简体   繁体   English

通过 boto3“MalformedPolicy 错误”将公共访问策略附加到 S3 存储桶不断抬头

[英]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.

相关问题 AWS Cloudformation 模板 - S3 存储桶策略 - MalformedPolicy 错误 - AWS Cloudformation template - S3 bucket policy - MalformedPolicy error Boto3 S3 存储桶生命周期策略 - 这么多天后删除文件夹和文件 - Boto3 S3 Bucket Lifecycle Policy - Delete folders and files after so many days 使用带有 boto3 的访问点从/向 S3 存储桶读取和写入 - Read and write from/to S3 bucket using access points with boto3 如何通过 python boto3 列出 aws s3 存储桶中的所有文件夹 - How to list all folders inside aws s3 bucket via python boto3 使用 boto3 在 Amazon S3 上的文件夹之间移动文件(指定的存储桶不存在错误) - Move files between folder on Amazon S3 using boto3 ( The specified bucket does not exist error) boto3 使用自定义 url 为 S3 上的有效存储桶名称提供 InvalidBucketName 错误 - boto3 gives InvalidBucketName error for valid bucket names on S3 with custom url boto3 s3 复制对象错误 - boto3 s3 copyObject error 使用 boto3 创建 S3 生命周期策略时出现格式错误的 XML 错误 - Malformed XML error while creating the S3 life cycle policy using boto3 如何使用 Boto3 下载 S3 存储桶的最新文件? - How to download the latest file of an S3 bucket using Boto3? 如何使用boto3查找S3每个桶的大小 - How to find the size of each bucket of S3 using boto3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM