[英]Attaching public access policy to an S3 bucket via boto3 "MalformedPolicy error" keeps rearing its head
import boto3
import json
S3API = boto3.client("s3", region_name="regionname")
bucket_name = "bucketname"
policy_file = open("../public_policy.json", "r")
S3API.put_bucket_policy(
Bucket = 'bucket_name',
Policy = 'policy_file.read()'
)
botocore.exceptions.ClientError: An error occurred (MalformedPolicy) when calling the PutBucketPolicy operation: Policies must be valid JSON and the first byte must be '{'
Your policy is literal string "policy_file.read()"
.您的政策是文字字符串
"policy_file.read()"
。 It should be (assuming the policy file is correct):它应该是(假设策略文件是正确的):
S3API.put_bucket_policy(
Bucket = bucket_name,
Policy = policy_file.read()
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.