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
- Amazon CloudFormation
-
CloudFormation is the foundational IaC service from Amazon. You can use YAML or JSON templates to model and provision your entire Amazon infrastructure, including Lambda functions. CloudFormation handles the complexities of creating, updating, and deleting your Amazon resources.
- Amazon Serverless Application Model (Amazon SAM)
-
Amazon SAM is an open-source framework built on top of CloudFormation. It provides a simplified syntax for defining serverless applications. Use Amazon SAM templates to quickly provision Lambda functions, APIs, databases, and event sources with just a few lines of YAML.
- Amazon Cloud Development Kit (Amazon 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 Amazon CDK.

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