CDK vs CloudFormation: is the latter somehow deprecated, in favour of the the newer? Or do they cover different use cases?

1

I've come across different tools explaining how to migrate from a CloudFormation template to CDK - I seem to understand CDK comes with more features, hence the question: when starting from scratch, is it always worth using CDK? Or are the 2 tools covering different use-cases? If someone needs to start now, is it still worth using CloudFormation, or could a newbie go straight to CDK?

Thanks

asked 2 years ago1690 views
2 Answers
2

If anything, CDK is making CloudFormation even more so required: CDK generates the templates that are then used to deploy your resources in AWS via CloudFormation, not instead of using CloudFormation.

Now, is it always worth using it ? I do not think so at all. CDK fits some needs, but why spend the time and effort into writing a script in CDK that should really just be a simpler template?

Plus, again that's just my opinion, using CDK also takes away some of the key functionalities that make CFN so great. You might end up feeling like you have to "hardcode" values into your templates, which could just have been a parameter, a mapping, or have in code conditions that will only work for a narrow case but a CFN Conditon would have done just fine.

Seen plenty of CDK generated stuff where the template becomes un-reusable in different accounts, regions, partitions and so on. And that's a damn shame considering that CFN is here to allow taking one template, and it will work, anywhere in AWS.

I much prefer Troposphere to CDK too. At least in Python. Troposphere in version 4+ generates his code from the AWS CloudFormation specifications, and the property names are a 1:1 match to the documentation, whereas in CDK so many resources have their properties renamed.

As for CDK doing lookup of existing resources, nothing you could not do with the APIs anyways, and again, often, that's a hardcode.

profile picture
answered 2 years ago
  • Good answer! In my opinion, Terraform and CloudFormation are most easy and beautiful!!!

1

It depends on your preference. If you are comfortable writing Infrastructure as Code in YAML (or JSON), then you should use Cloudformation.

If you are comfortable writing code in a programming language like Java, Python, Javascript, Go etc. then CDK is the tool you may want to use. You should take a look at the CDK FAQs to better understand all the capabilities that CDK offers - https://aws.amazon.com/cdk/faqs

If my answer resolves your question, please upvote and accept my answer. Thanks

profile pictureAWS
EXPERT
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions