Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use boto3 to download from public bucket

I'm trying to list files from a public bucket on AWS but the best I got was list my own bucket and my own files. I'm assuming that boto3 is using my credentials configured in the system to list my things.

How can I force it to list from a specific bucket, rather than my own bucket?

#http://sentinel-s2-l1c.s3-website.eu-central-1.amazonaws.com/
g_bucket = "sentinel-s2-l1c"
g_zone = "eu-central-1"

Thank you for helping me out.

like image 576
Xidh Avatar asked Feb 07 '17 13:02

Xidh


People also ask

How do I download from S3 bucket to local?

You can download an object from an S3 bucket in any of the following ways: Select the object and choose Download or choose Download as from the Actions menu if you want to download the object to a specific folder. If you want to download a specific version of the object, select the Show versions button.

How do I connect my S3 bucket to Boto3?

How to upload file to S3 Bucket using Boto3? The Boto3 library has two ways for uploading files and objects into an S3 Bucket: upload_file() method allows you to upload a file from the file system. upload_fileobj() method allows you to upload a file binary object data (see Working with Files in Python)


1 Answers

Pass the region_name when creating the client

s3client = boto3.client('s3', region_name='eu-central-1')

Then list objects from the bucket

objects = s3client.list_objects(Bucket='sentinel-s2-l1c')
like image 97
franklinsijo Avatar answered Oct 14 '22 19:10

franklinsijo