Created
November 1, 2016 17:47
-
-
Save hartfordfive/19097441d3803d9aa75ffe5ecf0696da to your computer and use it in GitHub Desktop.
Check if file exists in S3 bucket with Ruby aws-sdk gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Thanks, it's helpful for me!
Life saver! Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you don't ahve permission on the object that are you checking, the result it'll be false every time. So it's not an helpful script.