cpi-feed/mini_s3put.rb

35 lines
738 B
Ruby

# frozen_string_literal: true
require 'aws-sdk'
class MiniS3put
def initialize(key: nil, instream: $stdin)
@bucket = ENV.fetch('CPI_FEED_AWS_BUCKET')
@key = key || ENV.fetch('CPI_FEED_AWS_KEY')
@instream = instream
end
def put
Aws::S3::Resource.new.bucket(bucket).object(key).put(
body: instream.read
).on_success(&method(:on_put_success))
0
end
def on_put_success(response)
puts response.data
Aws::S3::Client.new.put_object_acl(
bucket: bucket, key: key, acl: 'public-read'
).on_success do |acl_response|
puts acl_response.data
end
end
private
attr_reader :bucket, :key, :instream
end
exit(MiniS3put.new(key: ARGV.first).put) if $PROGRAM_NAME == __FILE__