Infrastructure as Code (IaC)
With Infrastructure as Code (IaC), you can automate the deployment and management of your Amazon resources, including serverless applications. IaC allows you to define your infrastructure using code, making it easier to version, share, and replicate your deployments. This approach helps you:
-
Speed up your development cycle
-
Simplify configuration management
-
Improve reliability and consistency of your deployments
IaC tools for Amazon serverless applications
Amazon offers several IaC tools to help you build, deploy, and manage your cloud resources. This section explains how Amazon SAM fits within this ecosystem and works with other Amazon IaC tools.
- Amazon CloudFormation
-
Using Amazon CloudFormation
, you can model and provision your entire Amazon infrastructure with YAML or JSON templates. Amazon CloudFormation handles resource creation, updates, and deletion automatically. When you deploy Amazon SAM applications, Amazon CloudFormation processes the transformed templates to create and manage your resources. - Amazon Serverless Application Model (Amazon SAM)
-
Amazon SAM helps you build serverless applications with simplified syntax for defining serverless resources. You can use Amazon SAM templates to provision Lambda functions, APIs, databases, and event sources using concise YAML syntax. Amazon SAM transforms these templates into Amazon CloudFormation templates during deployment.
Note
While Amazon SAM specializes in serverless applications, you can use any Amazon CloudFormation resource types in your Amazon SAM templates. This gives you the flexibility to include non-serverless resources when needed.
- Amazon Cloud Development Kit (Amazon CDK)
-
With Amazon CDK
, you can define your serverless infrastructure using familiar programming languages like TypeScript, Python, Java, C#/.Net, or Go. You can use programming constructs such as loops and conditions to define your infrastructure, and Amazon CDK generates Amazon CloudFormation templates for deployment. You can use the Amazon SAM CLI to locally test and debug applications created with Amazon CDK. To learn more, see Testing CDK applications locally .
Comparing IaC tools for Serverless Applications
When choosing an IaC tool for your serverless applications, consider your team's preferences, project requirements, and existing workflows. The following table compares the key characteristics of Amazon IaC tools for serverless development:
Tool |
Primary use |
Best for |
Works with Amazon SAM |
When to choose |
---|---|---|---|---|
Amazon CloudFormation |
Managing complex Amazon infrastructure |
Applications requiring detailed control of Amazon resources |
Amazon SAM templates transform into Amazon CloudFormation templates during deployment |
For fine-grained control over non-serverless resources |
Amazon SAM |
Serverless application development |
Teams building serverless applications using Lambda |
Native functionality |
When focusing primarily on serverless architectures with Lambda functions, API Gateway APIs, and other serverless resources |
Amazon CDK |
Infrastructure definition using programming languages |
Teams preferring typed languages and code-first approach |
Generate Amazon SAM templates and use Amazon SAM CLI for testing |
When you need programmatic infrastructure definition or complex resource configuration logic |
Note
While this guide focuses on Amazon-native IaC tools, Terraform is another popular IaC solution that can be used to define serverless applications. The Amazon SAM CLI supports local testing of Lambda functions defined in Terraform. For more information, see Amazon SAM CLI Terraform support.
Learn more
-
To learn more about DevOps practices on Amazon, see Introduction to DevOps on Amazon
-
For information about using Lambda with different IaC tools, see Using Lambda with infrastructure as code (IaC)