Skip to content

Instantly share code, notes, and snippets.

@wzul
Forked from dannguyen/aws-write-to-s3-acl.rb
Created June 10, 2019 03:04
Show Gist options
  • Save wzul/4e74183e951c679f191df94ff9d88da3 to your computer and use it in GitHub Desktop.
Save wzul/4e74183e951c679f191df94ff9d88da3 to your computer and use it in GitHub Desktop.
Using Ruby AWS-SDK to write an object to S3 and set its ACL
#!/usr/bin/ruby
require 'rubygems'
require 'aws-sdk'
#creates an interface object to AWS S3
AWS.config( :access_key_id => '' , :secret_access_key => '' )
#creates an interface to the S3
s3interface = AWS::S3.new
object_key = 'testobject.txt'
object_data = 'Hello, World!'
#print redirector_object.inspect
bucket = s3interface.buckets['mydomain.com']
object = bucket.objects[object_key]
object.write('Hello World!')
object.acl=(:public_read)
object.metadata['website-redirect-location'] = 'http://mydomain.com/file.txt'
# via: https://forums.aws.amazon.com/thread.jspa?messageID=399096
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment