Skip to content

Getting Started

This section will help you build a Rust function for AWS Lambda from scratch. If you already have an existent function, and would like to build it for AWS Lambda, start from Step 4.

Step 1: Install Cargo Lambda

See all the ways that you can use to install Cargo Lambda in your system.

Step 2: Create a new project

The new subcommand will help you create a new project with a default template. When that's done, change into the new directory:

cargo lambda new new-lambda-project \
    && cd new-lambda-project

TIP

Add the flag --http-feature apigw_rest if you want to automatically generate an HTTP function that integrates with Amazon API Gateway

Step 3: Serve the function locally for testing

Run the Lambda emulator built in with the watch subcommand:

cargo lambda watch

Step 4: Test your function

The invoke subcommand can send payloads to the function running locally:

cargo lambda invoke --data-ascii '{"command": "hi"}'

If you're testing an HTTP function, you can access it with your browser from the local endpoint: http://localhost:9000/lambda-url/new-lambda-project.

Step 5: Build the function to deploy it on AWS Lambda

Use the build subcommand to compile your function for Linux systems:

cargo lambda build --release

TIP

Add the flag --arm64 if you want to use Gravitron processors on AWS Lambda

Step 6: Deploy the function on AWS Lambda

Use the deploy subcommand to upload your function to AWS Lambda. This subcommand requires AWS credentials in your system.

cargo lambda deploy

INFO

A default execution role for this function will be created when you execute this command. Use the flag --iam-role if you want to use a predefined IAM role.

Debugging

Use the flag --verbose with any subcommand to enable tracing instrumentation. You can also enable instrumentation with the following environment variable RUST_LOG=cargo_lambda=trace.

Rust version

This project works with Rust 1.59 and above.

Released under the MIT License.