How to access keys from buckets with periods (.) in their names using boto3?

前端 未结 2 1002
忘了有多久
忘了有多久 2021-01-18 21:35

Context

I am trying to get an encryption status for all of my buckets for a security report. However, since encryption is on a key level basis, I want to iterate t

相关标签:
2条回答
  • 2021-01-18 22:19

    Just generalizing the great answer provided from Ben.

    import boto3
    knownBucket = 'some.topLevel.BucketPath.withPeriods'
    s3 = boto3.resource('s3')
    
    #get region
    region = s3.meta.client.get_bucket_location(Bucket=knownBucket)['LocationConstraint']
    
    #set region in resource
    s3 = boto3.resource('s3',region_name=region)
    
    0 讨论(0)
  • 2021-01-18 22:31

    There are a couple of github issues on this. It's related to the region of the bucket. Make sure that your S3 resource is in the same region as the bucket you've created.

    FWIW you can determine the region programmatically like this:

    s3.meta.client.get_bucket_location(Bucket='boto3.region')
    
    0 讨论(0)
提交回复
热议问题