我正在尋找使用boto/boto3修改S3存儲桶策略。我在boto3中發現了兩種模式,我們可以通過它們對桶策略執行操作。Amazon S3使用boto/boto3修改存儲桶策略
# i can get bucket policy object as follows
import boto3
s3_conn = boto3.resource('s3')
bucket_policy = s3_conn.BucketPolicy('bucket_name')
# i can make put(), load(), policy on bucket_policy object.
#similar in other way i can use following code
policy = s3_conn.get_bucket_policy(Bucket='bucket_name')
# similar to this there are two other calls put_bucket_policy and delete_bucket_policy.
我在尋找可以添加更多屬性的更新存儲桶策略。
例如。我想在下面的策略的Statement key下添加一個條目。
{
"Version": "2012-10-17",
"Id": "Policy14564645656",
"Statement": [{
"Sid": "Stmt1445654645618",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::6164563645030:root"
},
"Action": "s3:Get*",
"Resource": "arn:aws:s3:::bucket_name/abc/*"
}]
}
是否有任何直接的方法來做到這一點。一種非常奇怪的方式是在JSON中添加條目,然後將其作爲新策略添加,但我正在尋找允許用戶在不知道退出策略的情況下更新策略的調用。
您需要Client()來調用get_bucket_policy。 – user615501