AWS SAM and CDK for serverless and IaC

Automating Deployments on AWS

Dunieski Otano

Amazon Web Services Solutions Architect

A 2,000-line YAML file

yaml

  • One Lambda + API Gateway grew into 2,000 lines of YAML
  • Every IAM role, log group, and permission spelled out
  • A typo lands halfway down a permission policy
  • SAM and CDK collapse this into a few lines
Automating Deployments on AWS

AWS SAM at a glance

sam

  • SAM is a CloudFormation extension for serverless
  • Concise resource types: AWS::Serverless::Function, ::Api
  • The SAM CLI builds, packages, and deploys
  • Templates transform into plain CloudFormation
Automating Deployments on AWS

The SAM workflow

workflow

  • sam init: scaffold a project from a template
  • sam validate: check the template before building
  • sam build: compile and package the code
  • sam deploy: ship to a CloudFormation stack
Automating Deployments on AWS

AWS CDK at a glance

  • Write infrastructure in TypeScript, JavaScript, Python, Java, C#, Go
  • Compile to CloudFormation with cdk synth
  • Deploy with cdk deploy; rebuilds on every code change
  • Same stack and resource concepts as CloudFormation

cdk

Automating Deployments on AWS

CDK construct levels

  • L1: a 1-to-1 wrap of a CloudFormation resource
  • L2: curated constructs with sensible defaults
  • L3: patterns that bundle multiple resources
  • Higher levels = fewer lines, less control

construct

Automating Deployments on AWS

When to use each

  • Raw CloudFormation: full control, ops-friendly
  • SAM: pure serverless apps, fastest path
  • CDK: complex infra, programming-language teams
  • All three deploy the same way underneath

each

Automating Deployments on AWS

All three deploy as CloudFormation

funnel

  • SAM transforms to CloudFormation
  • CDK synths to CloudFormation
  • The resulting stack uses the same events, drift, change sets
  • Rollbacks work the same regardless of toolkit
Automating Deployments on AWS

Let's practice!

Automating Deployments on AWS

Preparing Video For Download...