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년 전1625회 조회
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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠