0

I have access key to Amazon S3 with rights limited to a certain subfolder or prefix "subfloder/". I cannot find in documentation how to access only those objects in the bucket that I have access to.

I have two access keys: the one that has read access to the whole bucket and the one with limited read/write access that I'm supposed to use. The only thing I have found is how to access collection of ObjectSummary for the whole Bucket. The following code gives me a result under bucket-access access key. However, under limited access key it gives botocore.exceptions.ClientError: Access Denied.

my_session = boto3.session.Session(aws_access_key_id=access_id, aws_secret_access_key=access_key)
s3 = my_session.resource('s3')
my_bucket = s3.Bucket(bucketname)

for obj in my_bucket.objects.filter(Prefix=prefix):
    print(obj.key)

The desired result is being able to list items under restricted-access key as well as being able to call desired Object objects to run their download_fileobj() method

  • Possible duplicate of [Listing contents of a bucket with boto3](https://stackoverflow.com/questions/30249069/listing-contents-of-a-bucket-with-boto3) – Nir Alfasi Jun 07 '19 at 16:18
  • Specifically see: https://stackoverflow.com/a/43221593/1057429 – Nir Alfasi Jun 07 '19 at 16:19
  • The problem was that two access keys gave access to two separate buckets. The method listed in the question as well as in questions linked by alfasin give valid results if the correct bucket is queried. – Василий Паршин Jun 25 '19 at 09:42

0 Answers0