我下面发布的代码可以获取aws上所有s3存储桶列表,我正在尝试编写python代码来检查这些存储桶是否已加密,但是我无法弄清楚如何实现。请问有人能告诉我如何修改我的代码吗?我尝试了在线示例并查看了文档。
我的代码如下:
尝试了以下代码,但它们无法工作:
并且。
我的代码如下:
from __future__ import print_function
import boto3
import os
os.environ['AWS_DEFAULT_REGION'] = "us-east-1"
# Create an S3 client
s3 = boto3.client('s3')
# Call S3 to list current buckets
response = s3.list_buckets()
# Get a list of all bucket names from the response
buckets = [bucket['Name'] for bucket in response['Buckets']]
# Print out the bucket list
print("Bucket List: %s" % buckets)
尝试了以下代码,但它们无法工作:
s3 = boto3.resource('s3')
bucket = s3.Bucket('my-bucket-name')
for obj in bucket.objects.all():
key = s3.Object(bucket.name, obj.key)
print key.server_side_encryption
并且。
#!/usr/bin/env python
import boto3
s3_client = boto3.client('s3')
head = s3_client.head_object(
Bucket="<S3 bucket name>",
Key="<S3 object key>"
)
if 'ServerSideEncryption' in head:
print head['ServerSideEncryption']