Skip to content

Instantly share code, notes, and snippets.

@goalaleo
Last active March 22, 2018 11:55
Show Gist options
  • Save goalaleo/eb66ef93ed2a2ce10b38b931e8d17486 to your computer and use it in GitHub Desktop.
Save goalaleo/eb66ef93ed2a2ce10b38b931e8d17486 to your computer and use it in GitHub Desktop.

Change access to public for all files in AWS S3 bucket

Syncing a bucket doesn't seem to copy the access rights for files. This script changes the acl for all objects in the bucket to public-read

require 'aws-sdk'

region_code = 'REGION_CODE_HERE'
aws_access_key = 'ACCESS_KEY_ID_HERE'
aws_secret_access_key = 'SECRET_ACCESS_KEY_HERE'
bucket_name = 'BUCKET_NAME_HERE'

Aws.config.update({
  region: region_code,
  credentials: Aws::Credentials.new(
    aws_access_key,
    aws_secret_access_key
  )
})

s3 = Aws::S3::Resource.new
s3.bucket(bucket_name).objects.each do |object|
  puts object.key
  object.acl.put({ acl: 'public-read' })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment