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

前端 未结 2 1019
忘了有多久
忘了有多久 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)
    

提交回复
热议问题