调用PutBucketAcl操作时发生错误(InvalidArgument):未知

时间:2019-02-27 11:02:14

标签: amazon-s3 boto3 botocore

当调用boto3.client的方法put_bucket_acl(** kwargs)来设置bucket acl时,出现了此异常。 (PS:这是一桶ceph对象,而不是aws)


我的代码:

import boto3
import copy

s3_client = boto3.client('s3', 
        aws_access_key_id=s3_conf['ak'], 
        aws_secret_access_key=s3_conf['sk'], 
        endpoint_url=s3_conf["host"])
bucket_acl = s3.BucketAcl(test_bucket)
bucket_acl.grants.append(new_grants)
bucket_acl.put(ACL='private', AccessControlPolicy={'Grants': bucket_acl.grants, 'Owner': bucket_acl.owner})

我也尝试使用Session.client:

session = Session(s3_conf["ak"], s3_conf["sk"])
s3 = session.resource("s3", endpoint_url=s3_conf["host"])
s3_client = session.client("s3", endpoint_url=s3_conf["host"])

rsp = s3_client.get_bucket_acl(Bucket=test_bucket)
old_access_control_policy = { 'Grants': copy.deepcopy(rsp['Grants']), 'Owner': copy.deepcopy(rsp['Owner']) }
new_access_control_policy = copy.deepcopy(old_access_control_policy)
new_access_control_policy['Grants'].append(new_grants)
s3_client.put_bucket_acl(Bucket=test_bucket, ACL='private', AccessControlPolicy=old_access_control_policy)

如果我删除参数AccessControlPolicy,它将成功运行

s3_client.put_bucket_acl(Bucket=test_bucket, ACL='private')

我用错误的方式调用此方法吗? 但是指南也以相同的方式将此调用方法称为:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.put_bucket_acl 寻求任何帮助。

1 个答案:

答案 0 :(得分:0)

可以将bucket acl设置为:

s3_client.put_bucket_acl(Bucket=test_bucket, AccessControlPolicy={...})

ACL和AccessControlPolicy是AccessControlList,并且参数AccessControlList只能是以下之一:ACL,AccessControlPolicy,Bucket,ContentMD5,GrantFullControl,GrantRead,GrantReadACP,GrantWrite,GrantWriteACP。稍后,我需要阅读botocore的代码,并找到ceph s3和amazon s3之间的区别。考虑阅读。