Code Style guide for AWS Cloudformation and CDK

1

I am looking to standardize the work of my team, is there an official code style guide for cloudformation made by AWS?

In the case of using CDK with python, what code style guide do you recommend and why?

Do you know any libraries that can help me to order my templates automatically?

profile picture
エキスパート
質問済み 2年前1727ビュー
4回答
2
承認された回答

I'm not aware of any official style guides for CDK or CloudFormation.
For CDK, start with PEP8 and it's style checker (many IDEs will also apply PEP8 formatting). From there it is really up to your team to devise (or borrow) a coding standard as you would for any other Python project.

For CloudFormation a great policy enforcement tool is CloudFormation Guard. It has basic canned rules and you can also add your own. As for "ordering" (keys?), CFn templates are simply data structures so you could read them into Python as dictionaries, sort by key, then re-export.

AWS
SamKeen
回答済み 2年前
1

Beyond CloudFormation Guard, which was mentioned on the previous answer, here are a couple of tools that I use on a daily basis with CloudFormation templates:

  • cfn-lint CloudFormation linter
  • cfn-nag CloudFormation security linter
  • cfn-include CloudFormation pre-processor. This is a great simple way to break up a template into more manageable, smaller files.
AWS
Juan_P
回答済み 2年前
0

There is an open source CFN formatter by AWS that you could use to pre-process templates into a standard format before committing. cfn-format.

That can be used in conjunction with a tool like pre-commit to automatically format templates into a standard format.

An example of that is here: https://github.com/aws-cloudformation/rain/blob/main/.pre-commit-hooks.yaml

- id: cfn-format
  name: Format CloudFormation templates
  entry: cfn-format -w
  language: golang
  files: \.template$
  description: Format CloudFormation templates
回答済み 2年前
0

We're in the same boat... and an official CDK style guide is sorely lacking.

Naming conventions are not merely opinionated as some styles will hang up @ synth.

This unofficial guide is heading in the right direction --> https://github.com/kevinslin/open-cdk

Ironically it's from a former AWS'er that they probibly should have kept around.

Good luck on your own project!

profile picture
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ