Skip to content

Instantly share code, notes, and snippets.

@rajesh38
Created August 3, 2018 07:47
Show Gist options
  • Save rajesh38/e0d7d1c272108a6539fc6397ee131ee2 to your computer and use it in GitHub Desktop.
Save rajesh38/e0d7d1c272108a6539fc6397ee131ee2 to your computer and use it in GitHub Desktop.
Delete objects from S3
# using Aws::S3 rubygem
Aws.config.update({
credentials: Aws::Credentials.new(Rails.application.secrets.s3_access_key, Rails.application.secrets.s3_secret_key)
})
s3 = Aws::S3::Resource.new(region: '<region>')
s3.bucket('<bucket_name>').objects.each{|object| object.delete if (object.key !~ /<pattern_not_to_match>/)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment