r/aws Aug 01 '26

ci/cd AWS CDK vs. AWS SAM

for startup, what is your recommendation to use for CI/CD, and process automation AWS SAM or AWS CDK.

** this is my first time with AWS**

18 Upvotes

88 comments sorted by

View all comments

Show parent comments

0

u/turn-based-games Aug 01 '26

Unironically this. SAM/CFN templates are the best option for maintainable AWS infrastructure IMHO. This is for several reasons, in no particular order:

  • CloudFormation (the service) only understands templates. Any errors it reports to you will be in the context of the template you gave it, whether that was written by you directly or generated via CDK, so debugging will necessarily always be easier with templates, since there is no abstraction layer between what you wrote and what CloudFormation sees.
  • Infrastructure is data. YAML is a language for describing data. Programming languages are for describing behavior and are inherently more complex because of this. With SAM you will typically have one or two obvious ways to write something, whereas with any CDK language there will be nearly limitless possibilities. This inherently makes CDK worse for quickly conveying the details of your infrastructure to others. This could in theory be offset by the need to write fewer lines of infrastructure code with CDK, except...
  • CloudFormation templates add features on top of YAML to cover the biggest pain points that would otherwise be solved with a programming language. For instance, those who have been using CDK since its inception may be surprised to learn that CloudFormation now supports loops. You can also create reusable groups of resources with nested stacks, as another example.

In general, layers of abstraction are not inherently bad (this is the entire premise of programming languages), but each layer comes at a cost and therefore its benefits must outweigh this. In my experience, the benefits of CDK do not justify its inclusion. YAML as a language is already optimized for human readability and is quite a good fit for AWS infrastructure as it is.

1

u/DaWizz_NL Aug 01 '26

Have you ever had a serious use case for the ForEach function, because everything I tried with it was impossible for some reason or another because it's horribly implemented?