来自存储桶加密的 boto3 打印规则
boto3 print rules from bucket encryption
我正在编写一个 python 脚本来检索 AWS 的信息,我试图只获取 SSEAlgorith 但我得到 TypeError: list indices must be integers or slice, not str
有什么办法吗?我猜是为了 [] inside Rules.
{
"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)
Rules
是一个列表。所以假设你只有一个列表,它应该是:
rules = enc['ServerSideEncryptionConfiguration']['Rules'][0]['ApplyServerSideEncryptionByDefault']['SSEAlgorithm']
我正在编写一个 python 脚本来检索 AWS 的信息,我试图只获取 SSEAlgorith 但我得到 TypeError: list indices must be integers or slice, not str 有什么办法吗?我猜是为了 [] inside Rules.
{
"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)
Rules
是一个列表。所以假设你只有一个列表,它应该是:
rules = enc['ServerSideEncryptionConfiguration']['Rules'][0]['ApplyServerSideEncryptionByDefault']['SSEAlgorithm']