Runtime Extensions for AWS Lambda in Rust
lambda-extension
is a library that makes it easy to write AWS Lambda Runtime Extensions in Rust. It also helps with using Lambda Logs API.
Example extensions
Simple extension
The code below creates a simple extension that's registered to every INVOKE
and SHUTDOWN
events, and logs them in CloudWatch.
use ;
async
async
Log processor extension
use ;
use info;
async
Ok
}
async
Deployment
Lambda extensions can be added to your functions either using Lambda layers, or adding them to containers images.
Regardless of how you deploy them, the extensions MUST be compiled against the same architecture that your lambda functions runs on.
Building extensions
-
Install cargo-lambda
-
Build the extension with:
cargo lambda build --release --extension
If you want to run the extension in ARM processors, add the --arm64
flag to the previous command:
cargo lambda build --release --extension --arm64
This previous command will generate a binary file in target/lambda/extensions
called basic
. When the extension is registered with the Runtime Extensions API, that's the name that the extension will be registered with. If you want to register the extension with a different name, you only have to rename this binary file and deploy it with the new name.
Deploying extensions
- Make sure you have the right credentials in your terminal by running the AWS CLI configure command:
aws configure
- Deploy the extension as a layer with:
cargo lambda deploy --extension