Using Lambda with infrastructure as code (IaC) - Amazon Lambda
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

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), you can automate your deployment processes to quickly and repeatably deploy and update whole serverless applications involving many separate Amazon resources. This approach speeds up your development cycle, makes configuration management easier, and ensures that your resources are deployed the same way every time.

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.

Diagram showing how Amazon SAM and Amazon CDK deploy Amazon resources and code using Amazon CloudFormation

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.