Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

localstack-samples/sample-rust-lambda

Repository files navigation

Rust Rest AWS Lambda

See the AWS docs here for more information on creating Rust Lambdas. AWS Rust Lambda Design

Prerequisites

  1. Docker Desktop is running
  2. LocalStack Pro auth token is set in the environment variable LOCALSTACK_AUTH_TOKEN

Setup

Create a file name .env-gdc-local and add the following to it:

export LOCALSTACK_AUTH_TOKEN=<your LocalStack auth token>

Either run a GDC or LocalStack

Run LocalStack without GDC

make start-localstack

OR

Run a GDC in the root of the repo.

Run a GDC (generic dev container) in the root of the repo.

  1. Clone this GDC
  2. Run the GDC
<path to GDC>/run-dev-container.sh
  1. Connect to the GDC
docker exec -it rls-dev-1 bash -l

Building for lambda requires more libs be installed into the GDC to cross-compile the Rust binary. Use the makefile target init-rust to install the necessary libs. If you're running on a Mac and not in a GDC, you will have to put sudo in front of this make command.

make init-rust

Build

make all

Deploy to AWS or LocalStack

Prerequisites

Set the AWS_ACCT variable in the makefile to the account number of the AWS account you want to deploy to. AWS Account Number is defaulted to the LocalStack default account number. Setup a profile in your ~/.aws/credentials file with the necessary permissions to create a lambda function. To use a LocalStack profile, create it and set AWS_PROFILE like this LocalStack AWS Profile

Set AWS_PROFILE

If you are using LocalStack, set the AWS_PROFILE environment variable to the LocalStack profile. Otherwise, set it to the profile in your ~/.aws/credentials file for your live AWS account.

export AWS_PROFILE=localstack

Create Lambda Role

make create-lambda-role

Deploy

Assume a role with the necessary permissions to create a lambda function.

make create-lambda-function

Run integration tests

In the Ubuntu dev container, you probably have to run this twice. There is some issue with Rust compilation on the Ubuntu dev container here. It doesn't happen on Mac and Windows.

make test

Clean up

make delete-lambda

About

Sample Rust Lambda

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published