【问题标题】:How to check if CloudFormation template is correct?如何检查 CloudFormation 模板是否正确?
【发布时间】:2021-09-12 20:56:56
【问题描述】:

我想从 CloudFormation 模板部署 SQS 队列。我的模板有问题吗?

configurationQueue:
    Type: 'AWS::SQS::Queue'
    Properties:
      QueueName: configuration-queue
      VisibilityTimeout: 60
      MessageRetentionPeriod: 86400

SQSQueuePolicy:
      Type: 'AWS::SQS::QueuePolicy'
      Properties:
        PolicyDocument:
          Version: 2012-10-17
          Statement:
            - Effect: Allow
              Principal:
                AWS: '*'
              Action:
                - 'sqs:CreateQueue'
                - 'sqs:DeleteMessage'
                - 'sqs:GetQueueAttributes'
                - 'sqs:GetQueueUrl'
                - 'sqs:ListQueueTags'
                - 'sqs:ListQueues'
                - 'sqs:ReceiveMessage'
                - 'sqs:SendMessage
              Resource: "arn:aws:sqs:us-west-2:****configuration-queue"
        Queues:
          - !Ref configurationQueue

这是我使用的命令

cfn-lint sqs-resources.yaml

这是错误

【问题讨论】:

  • 您可以很容易地使用 awscli validate the template syntax,但我们无法验证您模板的语义,因为您没有说明要求是什么。
  • 嗨,@jarmod 我只想创建一个简单的 sqs ctf,我的代码中有 c 错误吗?
  • 不,这几乎肯定是错误的,但我们不知道什么是“正确”,因为我们不知道您想要实现什么。也就是说,明显的错误是主要的——您几乎不应该使用 AWS:*,而是将其限制为最小的 AWS 账户集(例如,您的帐号)。操作通常应仅包括 sqs:SendMessage 和/或 sqs:ReceiveMessage - 您似乎将 SQS 资源策略与 IAM 策略混淆了。这里有一些examples
  • @WCY 您可以使用 cfn-lint、cfn-nag 进行 CFN 模板验证。 dev.to/namuny/…
  • @deechris27 我安装了cfn-lint并测试了,但是出现这样的错误,是因为它只能在vscode中使用吗?

标签: amazon-web-services amazon-cloudformation amazon-sqs


【解决方案1】:

sqs:SendMessage 缺少结尾引号

建议在编写模板以及自动完成和文档链接时尝试使用 VSCode 中的 CloudFormation Linter 来查看其中的一些内联错误

【讨论】:

  • 我安装了 cfn-lint 并测试了它,但是得到这样的错误,是因为它只能在 vscode 中使用
  • cfn-lint 也可以在 VSCode 之外使用
猜你喜欢
  • 2021-08-08
  • 2018-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-04
  • 2017-10-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多