Softwr

Developer Tools · head to head

AWS CDK vs AWS Serverless Application Model (AWS SAM)

AWS CDK logo

AWS CDK

Developer Tools

Open source framework for defining AWS infrastructure in programming languages

From
Free
Free plan
Yes
AWS Serverless Application Model (AWS SAM) logo

AWS Serverless Application Model (AWS SAM)

Developer Tools

Open-source framework and CLI for building serverless apps on AWS

From
Free
Free plan
Yes

The short version

  • AWS CDK is an Apache 2.
  • Both are free.
  • Only AWS CDK lists construct Library of reusable components; only AWS Serverless Application Model (AWS SAM) lists SAM connectors for IAM permissions.
  • Where AWS CDK falls short: targets AWS only, so it does not provision resources on other clouds.
  • Where AWS Serverless Application Model (AWS SAM) falls short: targets AWS only, so templates are not portable to other cloud providers.

How do AWS CDK and AWS Serverless Application Model (AWS SAM) differ?

Only the attributes on which AWS CDK and AWS Serverless Application Model (AWS SAM) actually diverge.

On every field we record, AWS CDK and AWS Serverless Application Model (AWS SAM) match. The differences are in what each one covers, below.

Identical on both: starting price (Free), pricing model (Open-source), free tier (Yes), platforms (Windows, macOS, Linux), category (Developer Tools).

Which features does each one have?

They share no listed features; 8 appear only for AWS CDK and 7 only for AWS Serverless Application Model (AWS SAM). Drawn from each product's published feature list. An absence here means we hold no record of it - not that the product lacks it.

Only in AWS CDK

  • Construct Library of reusable components
  • CDK CLI for synthesis and deployment
  • Programmatic CDK Toolkit Library
  • Support for TypeScript, JavaScript, Python, Java, C# and Go
  • Deployment through AWS CloudFormation
  • Custom and shareable constructs
  • Construct Hub registry
  • Open source under Apache 2.0

Only in AWS Serverless Application Model (AWS SAM)

  • SAM template shorthand for CloudFormation
  • SAM CLI project scaffolding with sam init
  • Local testing of Lambda functions and API endpoints
  • sam sync for syncing local changes to the cloud
  • SAM connectors for IAM permissions
  • Terraform project debugging support
  • CI/CD pipeline support

What is each one used for?

AWS CDK is most often brought in for defining AWS infrastructure in TypeScript or Python; AWS Serverless Application Model (AWS SAM) for defining Lambda and API Gateway applications as code. The jobs each tool is most often brought in to do.

AWS CDK

  • Defining AWS infrastructure in TypeScript or Pythonnot AWS Serverless Application Model (AWS SAM)
  • Reusable internal infrastructure modulesnot AWS Serverless Application Model (AWS SAM)
  • Serverless application stacksnot AWS Serverless Application Model (AWS SAM)
  • Testing infrastructure with unit testsnot AWS Serverless Application Model (AWS SAM)
  • Standardising environments across accountsnot AWS Serverless Application Model (AWS SAM)

AWS Serverless Application Model (AWS SAM)

  • Defining Lambda and API Gateway applications as codenot AWS CDK
  • Testing Lambda functions locally before deploymentnot AWS CDK
  • Building CI/CD pipelines for serverless appsnot AWS CDK
  • Converting console-created resources into templatesnot AWS CDK

Where do AWS CDK and AWS Serverless Application Model (AWS SAM) fall short?

AWS CDK's most cited limit: targets AWS only, so it does not provision resources on other clouds. AWS Serverless Application Model (AWS SAM)'s: targets AWS only, so templates are not portable to other cloud providers. Documented limitations, not opinions. Every one is a constraint you would hit in normal use.

AWS CDK

  • Targets AWS only, so it does not provision resources on other clouds
  • Deploys through CloudFormation, so its resource coverage and limits apply
  • Infrastructure written in code can be harder to review than declarative templates
  • The AWS resources it creates are billed separately at standard AWS rates

AWS Serverless Application Model (AWS SAM)

  • Targets AWS only, so templates are not portable to other cloud providers
  • Local testing of functions depends on Docker being installed and running
  • Requires an AWS account, the AWS CLI and configured credentials before first use
  • Declarative templates, so complex logic needs CloudFormation or the AWS CDK instead
  • Does not cover non-serverless infrastructure on its own, which falls back to CloudFormation

How much do AWS CDK and AWS Serverless Application Model (AWS SAM) cost?

AWS CDK is free to use; AWS Serverless Application Model (AWS SAM) is free to use. Plan by plan below, from each vendor's own pricing page.

AWS CDK

Free

No published plan breakdown. See the AWS CDK review.

AWS Serverless Application Model (AWS SAM)

Free

No published plan breakdown. See the AWS Serverless Application Model (AWS SAM) review.

Which should you pick?

Choose AWS CDK if

  • You need construct library of reusable components.
  • You want to start without paying.
  • You work on Windows, macOS, Linux.
  • You also want cdk cli for synthesis and deployment.

Choose AWS Serverless Application Model (AWS SAM) if

  • You need sam template shorthand for cloudformation.
  • You want to start without paying.
  • You work on Windows, macOS, Linux.
  • You also want sam cli project scaffolding with sam init.

Questions people ask

Is AWS CDK or AWS Serverless Application Model (AWS SAM) better?
It depends on the job. AWS CDK fits defining AWS infrastructure in TypeScript or Python; AWS Serverless Application Model (AWS SAM) fits defining Lambda and API Gateway applications as code. AWS CDK starts at Free and AWS Serverless Application Model (AWS SAM) at Free.
Which is cheaper, AWS CDK or AWS Serverless Application Model (AWS SAM)?
AWS CDK starts at Free and AWS Serverless Application Model (AWS SAM) at Free.
Does AWS CDK or AWS Serverless Application Model (AWS SAM) run on more platforms?
Both run on Windows, macOS, Linux, so platform support will not decide this one for you.
Can I use AWS CDK for free?
Both have a free tier, so you can try either at no cost before committing.
What is AWS CDK best used for?
AWS CDK is most often used for defining aws infrastructure in typescript or python, reusable internal infrastructure modules, serverless application stacks, testing infrastructure with unit tests. Of those, defining aws infrastructure in typescript or python and reusable internal infrastructure modules are not what AWS Serverless Application Model (AWS SAM) is typically brought in for.
What can AWS CDK do that AWS Serverless Application Model (AWS SAM) cannot?
AWS CDK covers Construct Library of reusable components, CDK CLI for synthesis and deployment, Programmatic CDK Toolkit Library, Support for TypeScript, JavaScript, Python, Java, C# and Go. AWS Serverless Application Model (AWS SAM) covers SAM template shorthand for CloudFormation, SAM CLI project scaffolding with sam init, Local testing of Lambda functions and API endpoints, sam sync for syncing local changes to the cloud.

Answered from the vendors’ own pages

AWS CDK: Which languages does AWS CDK support?

The AWS documentation lists TypeScript, JavaScript, Python, Java, C# and .NET, and Go. Infrastructure is defined as constructs composed into stacks and apps.

Source
AWS Serverless Application Model (AWS SAM): What is AWS SAM?

AWS SAM is an open-source framework for building serverless applications with infrastructure as code. It consists of a template syntax that extends CloudFormation and a command-line tool.

Source
AWS CDK: How does AWS CDK deploy resources?

CDK apps are synthesised and deployed through AWS CloudFormation. The documentation states this gives predictable, repeatable deployments with rollback on error.

Source
AWS Serverless Application Model (AWS SAM): Which operating systems does the SAM CLI support?

AWS publishes installers for Linux on x86_64 and arm64, macOS on Intel and Apple silicon, and a 64-bit Windows MSI. macOS versions older than 13.x are not supported.

Source
AWS CDK: Is AWS CDK free?

It is open source under the Apache 2.0 licence according to its GitHub repository. The AWS resources you provision with it are charged at their normal rates.

Source
AWS Serverless Application Model (AWS SAM): What licence does AWS SAM use?

The serverless-application-model repository on GitHub is licensed under Apache-2.0.

Source
AWS CDK: When was AWS CDK first released?

Wikipedia reports a developer preview announced in 2018 and general availability on 11 July 2019. CDK v2 followed in 2021.

Source
AWS Serverless Application Model (AWS SAM): How does SAM differ from the AWS CDK?

The documentation says to use SAM instead of the CDK if you prefer a declarative approach to describing infrastructure rather than a programmatic one. The two can also be combined, using the SAM CLI's local testing with CDK applications.

Source
Share

Related pages

Other head to heads