Created
August 17, 2024 07:33
-
-
Save trash-anger/5316380ac7cf4dd724c10c10d5c52ffe to your computer and use it in GitHub Desktop.
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' | |
# Replace these values with your actual credentials and details | |
storage_uri = 'https://storage.googleapis.com' | |
bucket_name = 'lexop-stg-blob' | |
access_key = 'xxxx' | |
secret_key = 'xxxx' | |
# Initialize the S3 client with the custom endpoint | |
s3_client = Aws::S3::Client.new( | |
access_key_id: access_key, | |
secret_access_key: secret_key, | |
endpoint: storage_uri, | |
force_path_style: true # Use path-style addressing | |
) | |
# List objects in the bucket | |
begin | |
response = s3_client.list_objects_v2(bucket: bucket_name) | |
if response.contents.empty? | |
puts "No files found in bucket '#{bucket_name}'." | |
else | |
puts "Files in bucket '#{bucket_name}':" | |
response.contents.each do |object| | |
puts object.key | |
end | |
end | |
rescue Aws::S3::Errors::ServiceError => e | |
puts "Error listing files: #{e.message}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment