r/aws • u/robbochinni • 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**
19
Upvotes
16
u/The-Wizard-of-AWS Aug 01 '26
Personally, I like CDK. It has more abstractions than SAM has, which is useful when you go needing the basics. SAM is really good if you’re just going to stick with the basics.
Also worth considering how comfortable you are with YAML vs TypeScript or other CDK language.
11
u/clintkev251 Aug 01 '26
SAM is really good at what it’s really good at, but outside of that you’re just writing CloudFormation, so overall CDK is going to be much more flexible
60
u/N0tWithThatAttitude Aug 01 '26
For thr love of God, don't use SAM. I had to convert a SAM app to cdk and it sucked.
79
u/moltar Aug 01 '26
CDK hands down
28
u/oneplane Aug 01 '26
Terraform. If you can't use that, CDK. Considering it's your first time with AWS: it takes a lot more to get to production and to make proper use of IaC; that part usually requires upfront knowledge of what to implement and why, the 'how' part (i.e. which IaC) can only be successful if built on top of that.
33
u/tomomcat Aug 01 '26
Of the two, use cdk, but honestly use terraform.
4
u/RocketOneMan Aug 01 '26 edited Aug 01 '26
I haven't used SAM for a while but if memory serves me right you're writing the cloudformation templates themself with addition of some special types that make certain serverless resources "easier" (or harder depending on if the abstraction works for you or not). And it has its own CLI for deploying these.
CDK lets you define your AWS resources, all* types of resources, in a turing complete language like typescript (not writing the YAML/JSON directly). It's still very declarative where you say what you want not how you want it but you can use the usual functions, variables, loops etc to make certain things easier.
I don't think SAM has seen much growth since the CDK was released (I could be wrong). You'll probably find more examples online or if someone else were to join you they'd more likely be familiar with CDK. And since you can define all* resources that way, I would recommend it.
I would also give terraform a look. CDK is built on top of Cloud Formation which has odd quirks that you have to learn. If you don't know how cloud formation works already then debugging some problems you think are CDK related will just be that much harder. Terraform does its own thing to call the AWS APIs directly.
But if this is your first time with AWS in general, do some workshops, click around a bit. If you're worried about running up the bill because you're unfamiliar with things the only thing that IaC does to help with that is deleting everything is easier. But you can also just delete your account after a week of learning things if you want.
You call this a startup but it's your first time with AWS and maybe are implying it's just you wanting to deploy something in the cloud. That's fine and all but it can be more trouble than it's worth when you're just starting out. AWS also has Lightsail with some basic VPS/Container services with more predictable pricing than DIYing it in the rest of the services AWS has to offer.
2
u/MavZA Aug 01 '26
From some comments that I see you’ve replied to it seems like you don’t understand the difference between the two. I recommend you research a bit more. If you’re a programmer as your day job, I recommend CDK because the ergonomics are going to be a lot better. However from an AWS standpoint CDK pulls ahead because it offers a wider variety of services to integrate to overall and has some better abstractions of the API over SAM. Additionally the way it handles outputs and integration of the outputs with other definitions in your stacks is (from my experience) better too. SAM is good if you: want to learn more about AWS, have very shallow needs or are in need of an architecture that isn’t bound to change much and you just need to stack some LEGO’s and bump dependencies and versions occasionally. But please do the research because you haven’t told us much more about what your needs are. I personally have been using SST because CDK’s building down to CF stacks became a real headache.
2
u/hashkent Aug 01 '26
Cdk is really nice for dry configs ensuring you deploy the same resources to multiple environments with the different between environments being resource types/counts/dns names etc.
Also avoids the where to store state and you can enforce tests in your code. Cdk nag to ensure best practices etc it can be really nice.
Downside is it requires full lifecycle software management so stick a dependabot workflow in and get spammed weekly with pr’s for version bumps.
2
u/kublaiprawn Aug 04 '26
SAM and CF. Nothing to update or maintain outside of the infra itself. With CDK you will always be on the hook for deps and version updates. AI has removed the barrier for a lot of the fiddly syntax when it comes to CF/SAM.
8
u/silentyeti82 Aug 01 '26
Neither, use Terraform.
3
u/ex-marco-inaros Aug 01 '26
>>** this is my first time with AWS**
For god sake get some training....
1
u/Floss_Patrol_76 Aug 01 '26
cdk, and it's not close for your case. the one thing sam is genuinely better at is the local lambda loop (sam local invoke / start-api) for iterating on a function offline, but the moment you have anything beyond plain lambda you're just hand-writing cloudformation, whereas cdk gives you real constructs and lets you refactor in an actual language. as a first-timer the thing that'll actually save you is being able to cdk diff before every deploy so you see exactly what's about to change.
1
u/skpratik Aug 02 '26
I use terraform (have two production apps, and for most of my consulting clients), but CDK is fine too.
And if it's your first time with AWS, then focus on getting the architecture right, get it reviewed. Terraform etc is how you right it, what you write is a bit more important though. Happy to help if you need.
The thing with using AWS is that, every click costs money and every decision is a purchase decision, so better to spend time on architecture to start with.
1
u/[deleted] Aug 02 '26
CDK, and look at Leigh Gilmore's (AWS Hero) for patterns - https://github.com/leegilmorecode
1
u/SisyphusAndMyBoulder Aug 02 '26
I just SAM for my APIGW & Lambdas. Took a bit to get configured, but smooth sailing ever since. Terraform for everything else.
1
u/MyFistsAreMyMoney Aug 02 '26
Plain terraform and forget the rest. You don't want developers opinionated mess in code and infra code. It will be a mess
1
u/kiwifellows Aug 03 '26
It depends on your approach. I would have said about 6 months to 1 year ago use CDK or Terraform for simplicity. In 15 years across AWS deployments and security I used everything from Ansible to Puppet to Saltstack to CFN/CDK/SAM/TF.
As most of the comments say use what you're comfortable with, there is no wrong and right here.
But now because of the advancement of LLM models and MCP development becomes a lot simpler. I would personally (now) to learn the basic fundamentals use CloudFormation first. That is as low level as you are going to get. But do it AI assisted initially if you want a tutor. Hook up to AWS MCP via Cursor or Claude and then just start hitting it with questions e.g. "I want to build an EC2 stack with an ALB. Provide me with necessary resources in CFN.
Also I have some open source templates you can try :)
https://github.com/teemops/templates/tree/master/cloudformation
1
u/mlhpdx Aug 07 '26
If you use CDK it will feel familiar, even in the corner with paint around you. With SAM you learn how AWS works and may not like the reality. I would choose the latter, and have in fact.
1
u/crypt0_bill Aug 02 '26
both shit use terraform thank yourself later
1
u/TwoWrongsAreSoRight Aug 02 '26
Terraform :)
1
u/return_of_valensky Aug 02 '26
if you're starting fresh and need to learn one, Pulumi is objectively the best, especially now since AI can write the syntax, it has the most features hands down. People used to say "but you need to know how to code" not anymore.
0
u/Witty-Comfortable851 Aug 01 '26
Terraform.
-3
u/oalfonso Aug 01 '26
Terraform
-1
u/Leather-Replacement7 Aug 01 '26
Cdk, but really neither, use terraform. Cloud formation is garbage
0
u/MateusKingston Aug 01 '26
Terraform -> CDK -> Abyss -> SAM
-5
u/pint Aug 01 '26
i don't like cdk at all. i use hand written cloudformation. not very sophisticated, but does the job.
-1
u/grumpper Aug 01 '26
For the love of god don't use anything based on cloud formation!!!
Go with terraform and use whatever ci/cd you want.
Choose anything else. It will still be faster, easier and less buggier than these...
0
u/LemonFishSauce Aug 06 '26
CDK all time. For its type checking and ease of bundling
-1
u/ConstructionSoft7584 Aug 01 '26
Sam is too abstracted and good for only a few use cases where it really shines.
I recommend cdk.
Additionally, go to freecodingcamp and see the videos by Andrew Brown on Aws, from cloud architect to developer accociate
-2
u/Status-Afternoon-425 Aug 01 '26
CDK
-3
u/CoastRedwood Aug 01 '26
Use the CDK, easiest to get up and running and easiest to maintain. Terraform adds complexity where it’s not needed and Sam is just trying to be like it’s older brothers.
-3
u/damnhandy Aug 01 '26
Why not both? You can use AWS SAM to test serverless code authored with AWS CDK:
https://docs.aws.amazon.com/cdk/v2/guide/testing-locally-with-sam-cli.html
The two are complimentary and not competing with one another. CDK exposes everything that CloudFormation offers, which is most everything AWS offers. AWS SAM is limited to Lambda-based applications.