From 9ebb9f0c9b9cf5896ba8b3e54769658cda205fdd Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 4 Oct 2015 18:50:31 -0400 Subject: [PATCH] Make the AWS code a smidge more robust --- mini_s3put.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/mini_s3put.rb b/mini_s3put.rb index 6919fe9..3c7a189 100644 --- a/mini_s3put.rb +++ b/mini_s3put.rb @@ -4,14 +4,21 @@ def main bucket = ENV.fetch('CPI_FEED_AWS_BUCKET') key = ARGV.first || ENV.fetch('CPI_FEED_AWS_KEY') - puts Aws::S3::Resource.new.bucket(bucket).object(key).put( + Aws::S3::Resource.new.bucket(bucket).object(key).put( body: $stdin.read - ) + ).on_success do |response| + puts response.data - puts Aws::S3::Client.new.put_object_acl( - bucket: bucket, key: key, acl: 'public-read' - ) - 0 + Aws::S3::Client.new.put_object_acl( + bucket: bucket, key: key, acl: 'public-read' + ).on_success do |acl_response| + puts acl_response.data + end + + return 0 + end + + 1 end exit(main) if $PROGRAM_NAME == __FILE__