How can I quickly and effectively debug CloudFormation templates?

前端 未结 12 1314
野的像风
野的像风 2020-11-30 20:53

CloudFormation is a powerful AWS offering that allows the programmatic creation of AWS resource stacks, such as the web tier of an application, a high performance computing

相关标签:
12条回答
  • 2020-11-30 21:30

    A recent new feature added to Cloudformation this past December was the addition of additional Parameter Types. These new Types allow your templates to perform stronger data checking, and also can "fail-fast" when creating resources and nested Cloudformation stacks. You also have the ability to provide nicer human-readable custom error messages when invalid values are passed in using the new ConstraintDescription attribute.

    The new types are especially helpful when dealing with various VPC resources. You can ensure that Parameters for your templates are the correct type, and are explicit about expecting a single value vs. a List.

    For example:

    "Parameters" : {
      "SingleGroup": { "Type": "AWS::EC2::SecurityGroup::Id", ...},
      "GroupList": {"Type": "List<AWS::EC2::SecurityGroup::Id>", ...}
    }
    
    0 讨论(0)
  • 2020-11-30 21:32

    Use the aws cloudformation validate-template command in the AWS CLI tool. It only validates whether your template is valid JSON or YAML, not whether your keys and values are correct (for example doesn't check for typos in keys)

    0 讨论(0)
  • 2020-11-30 21:32

    For JetBrains IDEs (IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion Gogland DataGrip Rider Android Studio ), there is at AWS CloudFormation plugin that supports deep checking of JSON and YAML CFN templates

    0 讨论(0)
  • 2020-11-30 21:33

    Late to the party but I might also add that it is worthwhile spending a bit of time configuring and learning your editor. I know that sounds laughably basic as an answer but try it.

    In my case, with vim, I performed much better once I took some time installing json syntax plugins, and also (finally) understood folding techniques to navigate large CF files easily. Mine now suggests typos (commas where they shouldn't be etc) and the color highlighting saves a lot of time giving clear visual clues.

    This might help mitigate syntax errors, but in-template logical errors are better fixed by other tools. Hopefully one day there will be a "preview" mode on CF.

    0 讨论(0)
  • 2020-11-30 21:38

    The AWS CloudFormation linter provides additional static analysis beyond aws cloudformation validate-template

    It will inform you which resource types and instance types are unavailable in certain regions, validate property values against allowed values, catch circular resource dependencies, syntax errors, template limits, and much more

    In addition to the CLI, one of the most popular mechanisms to remember to run the linter is installing an editor plugin like the Visual Studio Code extension which runs on every file save

    Other mechanisms like pre-commit Git hooks are described here

    0 讨论(0)
  • 2020-11-30 21:40

    Have you looked at the AWS CloudFormation Template Editor that is included in the AWS Toolkit for Eclipse? It has syntax highlighting, statement completion, and deployment to AWS CloudFormation.

    0 讨论(0)
提交回复
热议问题