amazon-web-services - 无法将策略添加到 serverless.yaml 中的 s3 存储桶

标签 amazon-web-services amazon-s3 aws-cloudformation serverless-framework

我想将以下政策添加到我的 S3 存储桶

s3Permissions:
  Type: AWS::S3::BucketPolicy
  Properties:
    Bucket: ${self:provider.environment.S3_BUCKET}
    PolicyDocument:
        Id: Policy1590589947784
        Version: '2012-10-17'
        Statement:
        - Sid: getObjectFromS3
          Action:
          - s3:GetObject
          Effect: Allow
          Resource: arn:aws:s3:::${self:provider.environment.S3_BUCKET}
          Principal: "*"

我将此设置作为我的环境变量之一

S3_BUCKET: com.backbar.lookups.${self:provider.stage}

尝试部署时出现以下错误

An error occurred: s3Permissions - Action does not apply to any resource(s) in statement (Service: Amazon S3; Status Code: 400; Error Code: MalformedPolicy; Request ID: 3760256F6D1080A1; S3 Extended Request ID: ...

如何正确设置存储桶策略?

最佳答案

我相信而不是:

Resource: arn:aws:s3:::${self:provider.environment.S3_BUCKET}

应该是:

Resource: arn:aws:s3:::${self:provider.environment.S3_BUCKET}/*

s3:GetObject 适用于对象。您的原始资源是一个存储桶。

关于amazon-web-services - 无法将策略添加到 serverless.yaml 中的 s3 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62425616/

相关文章:

amazon-web-services - AWS 云形成 : Reference to subnet causing error

amazon-web-services - EC2 实例 : Access RDS via Alias Name

amazon-web-services - 是否可以使用 CFT 将NotificationConfiguration 添加到现有的S3 存储桶?

amazon-web-services - S3错误: Access Denied when deploying CFN template with Nested Stacks

amazon-web-services - AWS Cloudformation 快速创建链接不提供其他选项

amazon-web-services - 在 Cloudformation 模板中传递安全组 ID 和子网 ID

amazon-web-services - 使用 Cloudformation 的 EC2 错误 : Service: AmazonEC2; Status Code: 400; Error Code: IncorrectInstanceState

node.js - AWS 在端口 3000 上对 Node.js 应用程序进行负载平衡

amazon-web-services - AWS S3 重定向不起作用

amazon-web-services - 无法使用 boto3 执行 s3 复制