ariva / rust-aws-lambda-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Super Simple Rust AWS Lambda

Super simplistic AWS rust lambda, which builds the target with the docker and allows you to test the execution locally with a simple cargo run ...

Can be used as a starting template...

Pre-requisites

Optional:

Build

  • Building platform: Intel x86-64 or Mac M1
  • Building OS: Linux Mint 20.x or MacOS 12.5.1
  • Rust version: 1.65.0

If you want musl build, set ENV var: MUSL_LINKER=true.

./build.sh autodetects if the host is an M1 mac and sets the target to the correct architecture. It defaults to x86-64 gnu build.

To build:

./build.sh
# OR
MUSL_LINKER=true ./build.sh

Deploy

Upload the zip file to AWS Lambda

Invoke AWS Lambda function from CLI:

aws lambda invoke \
    --function-name YOUR_AWS_FUNCTION_NAME \
    --payload '{ "name": "Testing007" }' \
    response.json \
&& echo "RESPONSE:" && cat response.json && echo

Expected Response:

{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
}
{"greeting":"Hello Rusty Lambda World! Received param name: Testing007!"}

Troubleshooting

If getting the Invalid base64:... error, then try the following:

add cli_binary_format=raw-in-base64-out to the ~/.aws/config file.

Test locally

cargo run -- '{ "name": "Test123"}'
# or
cargo run -- '{ "name": "Test1234", "test": true }'

About

License:Other


Languages

Language:Rust 48.0%Language:Shell 34.8%Language:Dockerfile 17.2%