Get Started

Deploy to AWS Lambda with LaunchFlow


Deploy a serverless API on AWS Lambda with LaunchFlow.

View the source code for this guide in our examples repo.


0. Create your Lambda function

If you already have an existing Lambda function, you can skip to step #1.

Create a new directory for your project.

1
mkdir launchflow-lambda
2
cd launchflow-lambda

Create a file named app.py with the following content:

1
def handler(event, context):
2
return {
3
"statusCode": 200,
4
"body": "Hello from LaunchFlow!"
5
}

1. Initialize Launch Flow

Install the LaunchFlow Python SDK and CLI using pip.

1
pip install launchflow[aws]

Initialize LaunchFlow in your project

1
lf init --backend=local
  • Name your project
  • Select Yes for creating an example infra.py
  • Select AWS for your cloud provider
  • Select Lambda for your service

Once finished you will get an infra.py that looks like:

1
import launchflow as lf
2
3
# LambdaService Docs: https://docs.launchflow.com/reference/aws-services/lambda-service
4
api = lf.aws.LambdaService("my-lambda-api", handler="TODO")

LambdaService will zip your local directory + Python environment and deploy it to AWS Lambda. You can provide additional fields to LambdaService to configure things like memory, timeout, or even a custom domain.


Update the LambdaService in your infra.py file to point to your Lambda handler in app.py

1
import launchflow as lf
2
3
# LambdaService Docs: https://docs.launchflow.com/reference/aws-services/lambda-service
4
api = lf.aws.LambdaService("my-lambda-api", handler="app.handler")

2. Deploy your Service

Make sure you have local AWS credentials set up before deploying.

1
lf deploy
  • Name your environment (dev is a good first name)
  • Select your cloud provider AWS
  • Confirm the resources to be created
  • Select the service to deploy

Once complete you will see a link to your deployed service on Lambda.

Deploy Lambda

3. Cleanup your Resources

Optionally you can delete all your resources, service, and environments with:

1
lf destroy
2
lf environments delete

4. Visualize, Share, and Automate

LaunchFlow Cloud Console

LaunchFlow Cloud usage is optional and free for individuals.

Using the local backend like we did above works fine for starting a project, but doesn't offer a way to share state between multiple users. LaunchFlow Cloud is a web-based service for managing, sharing, and automating your infrastructure. It's free small teams and provides a simple, secure way to collaborate with your team and automate your release pipelines.

Sign up for LaunchFlow Cloud and connect your local environment by running:

1
lf init --backend=lf

This will create a project in your LaunchFlow Cloud account and migrate your local state to the LaunchFlow Cloud backend.


What's next?

Previous
Docker Image