【问题标题】:enabling s3 bucket logging via python code通过 python 代码启用 s3 存储桶日志记录
【发布时间】:2020-02-07 14:41:40
【问题描述】:

我正在尝试启用对我帐户中所有 s3 存储桶的登录,但在执行代码时出错

def s3_log():
    s3 = boto3.client('s3')
    response = s3.list_buckets()
    for i in response['Buckets']:
        #bucketacl = s3.put_bucket_acl(Bucket=i['Name'],AccessControlPolicy={'Grants': [{'Grantee': {'Type': 'Group','URI': 'http://acs.amazonaws.com/groups/s3/LogDelivery'},'Permission': 'FULL_CONTROL'}]})
        response = s3.put_bucket_logging(
        Bucket=i['Name'],
        BucketLoggingStatus={
            'LoggingEnabled': {
                'TargetBucket': i['Name'],
                'TargetGrants': [
                {
                    'Grantee': {
                        'Type': 'Group',
                        'URI': 'http://acs.amazonaws.com/groups/s3/LogDelivery'
                    },
                    'Permission': 'READ' },
                {
                    'Grantee': {
                        'Type': 'Group',
                        'URI': 'http://acs.amazonaws.com/groups/s3/LogDelivery'
                    },
                    'Permission': 'WRITE'

                },
                ],
                'TargetPrefix': i['Name'] + '/'

            }
        }

    )
Error :
"errorMessage": "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"

我添加了目标授权以添加对日志传递组的权限,但我的代码中似乎缺少某些内容。所以我继续尝试添加存储桶 acl,但它给了我一些格式错误的 xml 错误,所以 acl 代码是暂时评论了

【问题讨论】:

    标签: amazon-web-services amazon-s3 boto3


    【解决方案1】:

    您必须授予READ_ACP权限,您可以执行以下操作:

    s3c.put_bucket_acl(
        AccessControlPolicy = {
            "Owner": {
                "ID": "canonical_user_id_sdakfjldsakjf" # see https://docs.aws.amazon.com/general/latest/gr/acct-identifiers.html
            },
            'Grants': [
                {
                    'Grantee': {
                        'Type': 'Group',
                        'URI': 'http://acs.amazonaws.com/groups/s3/LogDelivery'
                    },
                    'Permission': 'WRITE'
                },
                {
                    'Grantee': {
                        'Type': 'Group',
                        'URI': 'http://acs.amazonaws.com/groups/s3/LogDelivery'
                    },
                    'Permission': 'READ_ACP'
                }
            ]
        },
        Bucket=bucket
    )
    

    更多关于here

    【讨论】:

      猜你喜欢
      • 2019-12-04
      • 2017-08-08
      • 2019-08-23
      • 2021-09-17
      • 2020-01-17
      • 2019-11-07
      • 2020-06-12
      • 1970-01-01
      • 2018-09-14
      相关资源
      最近更新 更多