Skip to content

Instantly share code, notes, and snippets.

@miketheman
Created June 20, 2015 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketheman/3e9c7338d00818a70e3f to your computer and use it in GitHub Desktop.
Save miketheman/3e9c7338d00818a70e3f to your computer and use it in GitHub Desktop.
Use the AWS SDK Ruby gem to create new copies of objects without an invalid Content-Encoding metadata field
#!/usr/bin/env ruby
require 'aws-sdk'
INVALID_ENCODINGS = %w(ANSI_X3.4-1968 UTF-8)
bucket = Aws::S3::Bucket.new(
region: 'us-east-1',
name: 'www.mysite.com'
)
fail unless bucket.exists?
bucket.objects.each do |objectsummary|
obj = objectsummary.object
next unless INVALID_ENCODINGS.include?(obj.content_encoding)
obj_source = "#{obj.bucket_name}/#{obj.key}"
printf "%-60s %-8s %-24s %s\n",
obj.key, obj.content_encoding, obj.content_type, obj_source
objectsummary.copy_from(
copy_source: obj_source,
content_encoding: nil,
content_type: obj.content_type,
metadata: obj.metadata,
metadata_directive: 'REPLACE'
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment