amazon-web-services - Cloudformation 存储桶策略 - "Statement is missing required element"

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

我有这个 S3 存储桶和策略,正在部署到 CloudFormation。

Resources:
  ReportsBucket:
    Type: AWS::S3::Bucket

  BucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
      Bucket: !Ref ReportsBucket
      PolicyDocument:
        Id: ReportPolicy
        Version: "2012-10-17"
        Statement:
          - Sid: ReportBucketPolicyDoc
            Effect: Allow
            Action: "s3:*"
            Principal:
              AWS: !Join ['', ["arn:aws:iam::", !Ref "AWS::AccountId", ":root"]]
            Resource: !Join ['', ['arn:aws:s3:::', !Ref S3Bucket, '/*']]

它失败了,

UPDATE_ROLLBACK_IN_PROGRESS AWS::CloudFormation::Stack  {my stack name} The following resource(s) failed to create: [BucketPolicy].
CREATE_FAILED   AWS::S3::BucketPolicy   BucketPolicy    Statement is missing required element

我的政策有什么问题?

最佳答案

它有两个问题:

  • 第一行缺少 AWSTemplateFormatVersion(必需元素)
  • S3Bucket 的引用应为 ReportsBucket

更新版本:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  ReportsBucket:
    Type: AWS::S3::Bucket

  BucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
      Bucket: !Ref ReportsBucket
      PolicyDocument:
        Id: ReportPolicy
        Version: "2012-10-17"
        Statement:
          - Sid: ReportBucketPolicyDoc
            Effect: Allow
            Action: "s3:*"
            Principal:
              AWS: !Join ['', ["arn:aws:iam::", !Ref "AWS::AccountId", ":root"]]
            Resource: !Join ['', ['arn:aws:s3:::', !Ref ReportsBucket, '/*']]

关于amazon-web-services - Cloudformation 存储桶策略 - "Statement is missing required element",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46838980/

相关文章:

amazon-web-services - CloudFormation 可选映射属性 - DeadLetterQueue

amazon-web-services - Terraform AWS NLB TLS 直通

amazon-web-services - 如何添加 Cognito 用户名/密码来验证 ALB?

amazon-web-services - 如何测试 AWS ELB 粘性 session 是否按预期工作?

amazon-web-services - 每次将文件发布到存储桶时都将 s3 文件复制到 ec2 吗?

amazon-web-services - 使用子网时 AWS Cloudformation 出现错误

amazon-web-services - EMR 命令运行程序如何提交作业

amazon-web-services - 在我的 IaC 堆栈中收到自动存储桶策略的处理程序错误

powershell - 使用 Write-S3Object 时如何设置 Cache-Control?

amazon-web-services - 使用 CloudFormation 有条件地定义 Elastic Beanstalk 环境变量