python - AWS Lambda Python 获取最新的 S3 存储桶
问题描述
我正在编写一个将策略附加到最新存储桶的 Lambda 函数。该脚本将策略附加到命名存储桶,但我不太确定如何获取最新创建的存储桶的名称。任何想法表示赞赏:)。当前代码如下。
import boto3
import json
client = boto3.client('s3')
bucket_name = '*'
bucket_policy = {
"Version": "2012-10-17",
"Statement": [{
"Sid": "DenyS3PublicObjectACL",
"Effect": "Deny",
"Principal": "*",
"Action": ["s3:PutObjectAcl"],
"Resource": "arn:aws:s3:::%s/*" #% bucket_name,
"Condition": {
"StringEqualsIgnoreCaseIfExists": {
"s3:x-amz-acl": [
"public-read",
"public-read-write",
"authenticated-read"
]
}
}
}]
}
bucket_policy = json.dumps(bucket_policy) # Converting the policy into a JSON string.
def lambda_handler(event, context):
response = client.put_bucket_policy(Bucket=bucket_name, ConfirmRemoveSelfBucketAccess=True, Policy=bucket_policy)
解决方案
推荐阅读
- javascript - 如何从本地 XLSX 文件中读取数据并将其保存到对象/数组中
- unity3d - 检测全息透镜上的媒体捕获
- wpf - 风格错误?无法在 Windows10 中的样式中设置背景颜色
- android - 如何在 Android Studio 中修复 'Context.getResources()' 上的空对象引用'
- ios - NSInMemoryStoreType 类型的核心数据忽略实体的约束
- django - Conditional in model
- scala - 检查定义了多少对象属性
- python-2.7 - re.split() 在一个复杂的字符串上
- selenium - send_keys (Keys.ENTER) 上的 selenium webdriver 错误
- r - 如何计算同一区域不同分类的层堆栈中最丰富的像素值(多数票)?