Skip to content

This project provides a minimal example of an AWS Lambda function written in Rust, designed to run locally using Localstack on macOS.

Notifications You must be signed in to change notification settings

gekh/localstack-rust-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

This project provides a minimal example of an AWS Lambda function written in Rust, designed to run locally using Localstack on macOS.

INSTALL

  • Install docker

  • Install localstack (needs docker)

    brew install localstack/tap/localstack-cli
    localstack start -d
    localstack status services
  • Install awslocal https://github.com/localstack/awscli-local

    brew install awscli-local
    
  • Install compiler for aarch64-unknown-linux-gnu https://rustup.rs/

    brew tap messense/macos-cross-toolchains
    brew install aarch64-elf-gcc
    // or
    brew install aarch64-unknown-linux-gnu

USAGE

Tip: If you don't have awslocal installed, simply replace awslocal at the start of each command with:

aws --endpoint-url=http://localhost:4566

CREATE

rustup target add aarch64-unknown-linux-gnu
cargo build --release --target aarch64-unknown-linux-gnu
cp target/aarch64-unknown-linux-gnu/release/localstack-rust-example bootstrap
chmod +x bootstrap
zip -9 lambda.zip bootstrap
awslocal lambda create-function \
  --function-name localstack-rust-example \
  --runtime provided.al2023 \
  --architectures arm64 \
  --role arn:aws:iam::000000000000:role/lambda-role \
  --handler bootstrap \
  --zip-file fileb://lambda.zip
rm lambda.zip bootstrap response.json

(press "q" to exit status message when lambda is created)

CHECK

awslocal lambda get-function \
  --function-name localstack-rust-example

You should see this when lambda is created/updated successfully:

{
  // ...
  "State": "Active",
  "LastUpdateStatus": "Successful"
  // ...
}

UPDATE

rm lambda.zip bootstrap response.json
cargo build --release --target aarch64-unknown-linux-gnu
cp target/aarch64-unknown-linux-gnu/release/localstack-rust-example bootstrap
chmod +x bootstrap
zip -9 lambda.zip bootstrap
awslocal lambda update-function-code \
  --function-name localstack-rust-example \
  --zip-file fileb://lambda.zip
rm lambda.zip bootstrap

(press "q" to exit status message after lambda is updated)

INVOKE

awslocal lambda invoke \
  --function-name localstack-rust-example \
  --payload '{}' \
  --cli-binary-format raw-in-base64-out \
  response.json

Print result:

cat response.json | jq

(install jq or remove "| jq" in the end to see raw response)

(Optional) Remove response.json

rm response.json

DESTROY

awslocal lambda delete-function \
  --function-name localstack-rust-example

NOTES

To install jq on macOS:

brew install jq

About

This project provides a minimal example of an AWS Lambda function written in Rust, designed to run locally using Localstack on macOS.

Topics

Resources

Stars

Watchers

Forks

Languages