【问题标题】:boto3 print rules from bucket encryption来自桶加密的 boto3 打印规则
【发布时间】:2021-11-20 19:39:39
【问题描述】:

我正在编写一个 python 脚本来检索 AWS 的信息并且我试图只获取 SSEAlgorith 但我得到 TypeError: list indices must be integers or slices, not str 有没有办法做到这一点?我猜是为了 [] 里面的规则。

{
    "ServerSideEncryptionConfiguration": {
        "Rules": [
            {
                "ApplyServerSideEncryptionByDefault": {
                    "SSEAlgorithm": "AES256"
                }
            }
        ]
    }
}

这是我用来检索信息的代码:

s3 = boto3.client('s3') 
buc = s3.list_buckets()

for i in response['Buckets']:
    enc = s3.get_bucket_encryption(Bucket=i['Name'])
    rules = enc['ServerSideEncryptionConfiguration']['Rules']['ApplyServerSideEncryptionByDefault']['SSEAlgorithm']
    print(rules)

【问题讨论】:

    标签: python-3.x amazon-s3 boto3 boto botocore


    【解决方案1】:

    Rules 是一个列表。所以假设你只有一个列表,它应该是:

    rules = enc['ServerSideEncryptionConfiguration']['Rules'][0]['ApplyServerSideEncryptionByDefault']['SSEAlgorithm']
    

    【讨论】:

      猜你喜欢
      • 2021-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-28
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      相关资源
      最近更新 更多