Skip to content

Instantly share code, notes, and snippets.

@bparanj
Forked from hartfordfive/verify_s3_file.rb
Created July 19, 2017 23:02
Show Gist options
  • Save bparanj/d39d0d535bce2e29a56a2b74ea95b209 to your computer and use it in GitHub Desktop.
Save bparanj/d39d0d535bce2e29a56a2b74ea95b209 to your computer and use it in GitHub Desktop.
Check if file exists in S3 bucket with Ruby aws-sdk gem
require 'aws-sdk'
s3 = Aws::S3::Resource.new(
region: 'us-east-1',
credentials: Aws::InstanceProfileCredentials.new()
)
bucket = s3.bucket('my-daily-backups')
file = (DateTime.now).strftime("%Y.%m.%d-backup")
if bucket.object(file).exists?
puts "File '/my-daily-backups/#{file}' is present in S3 bucket!"
else
puts "File '/my-daily-backups/#{file}' is not in S3 bucket!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment