【发布时间】:2018-03-07 21:31:38
【问题描述】:
我想从我拥有的所有 s3 存储桶中提取 s3 存储桶策略,并将它们存储在各自的 .json 文件中。这应该是 json 格式。但是,在我尝试的解决方案中,它将策略与响应元数据一起存储在文件中,而不是 jSOn 格式。
"ResponseMetadata": {"HTTPStatusCode": 200, ...... "content-type": "application/json"}}}
这可以在 python/boto3 中完成吗?这是我的代码。
try:
s3client = get_s3Client('us-east-1')
response = s3client.list_buckets()
if response and response['Buckets']:
for bucket in response['Buckets']:
bucketName = bucket['Name']
print (bucketName)
policyname = policy_output + '\\' + bucketName + '.json'
print (policyname)
response = s3client.get_bucket_policy(
Bucket=bucketName
)
print (response)
with open(policyname, 'w') as f:
json.dump(response, f)
#f.write(response)
【问题讨论】:
标签: python amazon-web-services amazon-s3 boto3