【发布时间】:2020-09-14 15:35:13
【问题描述】:
我正在尝试创建一个集中式日志记录存储桶,然后使用 lambda 和 aws-cdk 记录所有其他 s3 存储桶。已创建集中式日志存储桶,但在其上使用 lambda 写入时出错。这是我的代码: 导入boto3
s3 = boto3.resource('s3')
def handler(event, context):
setBucketPolicy(target_bucket='s3baselinestack-targetloggingbucketbab31bd5-b6y2hkvqz0of')
def setBucketPolicy(target_bucket):
for bucket in s3.buckets.all():
bucket_logging = s3.BucketLogging(bucket.name)
if not bucket_logging.logging_enabled:
reponse = bucket_logging.put(
BucketLoggingStatus={
'LoggingEnabled': {
'TargetBucket': target_bucket,
'TargetPrefix': f'{bucket.name}/'
}
},
)
print(reponse)
Here is my error:
START RequestId: 320e83c0-ba5e-4d54-a78c-a462d6e0cb87 Version: $LATEST
An error occurred (InvalidTargetBucketForLogging) when calling the PutBucketLogging operation: You must give the log-delivery group WRITE and READ_ACP permissions to the target bucket: ClientError
Traceback (most recent call last):
注意:一切正常,但是当我通过 aws 控制台启用它时,这个日志传递权限可以正常工作,但是,我需要以编程方式进行!提前谢谢你。
【问题讨论】:
标签: amazon-s3 aws-lambda boto3