Using Lambda with infrastructure as code (IaC)
Lambda functions rarely run in isolation. Instead, they often form part of a serverless application with other resources such as
databases, queues, and storage. With infrastructure as code (IaC)
IaC tools for Lambda
- AWS CloudFormation
-
CloudFormation is the foundational IaC service from AWS. You can use YAML or JSON templates to model and provision your entire AWS infrastructure, including Lambda functions. CloudFormation handles the complexities of creating, updating, and deleting your AWS resources.
- AWS Serverless Application Model (AWS SAM)
-
AWS SAM is an open-source framework built on top of CloudFormation. It provides a simplified syntax for defining serverless applications. Use AWS SAM templates to quickly provision Lambda functions, APIs, databases, and event sources with just a few lines of YAML.
- AWS Cloud Development Kit (AWS CDK)
-
The CDK is a code-first approach to IaC. You can define your Lambda-based architecture using TypeScript, JavaScript, Python, Java, C#/.Net, or Go. Choose your preferred language and use programming elements like parameters, conditionals, loops, composition, and inheritance to define the desired outcome of your infrastructure. The CDK then generates the underlying CloudFormation templates for deployment. For an example of how to use Lambda with CDK, see Deploying Lambda functions with AWS CDK.

AWS also provides a service called AWS Infrastructure Composer to develop IaC templates using a simple graphical interface. With Infrastructure Composer, you design an application architecture by dragging, grouping, and connecting AWS services in a visual canvas. Infrastructure Composer then creates an AWS SAM template or an AWS CloudFormation template from your design that you can use to deploy your application.
In the Using Lambda functions in AWS SAM and Infrastructure Composer section below, you use Infrastructure Composer to develop a template for a serverless application based on an existing Lambda function.