warp_lambda
A super simple crate to let you use warp filters with aws lambda runtime
Note: Using fork of awslabs/aws-lambda-rust-runtime by Netlify devs lamedh-dev/aws-lambda-rust-runtime Due to issue #216 and an alternative from Netlify devs #274
Warning: This is experimental and not production ready! uses non stable version of aws_lambda_rust_runtime
Example
Add warp_lambda
, warp
and tokio
to your dependencies:
= { = "1.2.0", = [ "full" ]}
= "0.3"
= "0.1"
And then get started in your main.rs
:
use Filter;
async
Deployment
Relevant parts copied over from https://github.com/awslabs/aws-lambda-rust-runtime
AWS CLI
To deploy the basic sample as a Lambda function using the AWS CLI, we first need to manually build it with cargo
. Since Lambda uses Amazon Linux, you'll need to target your executable for an x86_64-unknown-linux-musl
platform.
Run this script once to add the new target:
Compile one of the examples as a release with a specific target for deployment to AWS:
For a custom runtime, AWS Lambda looks for an executable called bootstrap
in the deployment package zip. Rename the generated basic
executable to bootstrap
and add it to a zip archive.
&& &&
Now that we have a deployment package (lambda.zip
), we can use the AWS CLI to create a new Lambda function. Make sure to replace the execution role with an existing role in your account!
Note: --cli-binary-format raw-in-base64-out
is a required
argument when using the AWS CLI version 2. More Information
Docker
Alternatively, you can build a Rust-based Lambda function in a docker mirror of the AWS Lambda provided runtime with the Rust toolchain preinstalled.
Running the following command will start a ephemeral docker container which will build your Rust application and produce a zip file containing its binary auto-renamed to bootstrap
to meet the AWS Lambda's expectations for binaries under target/lambda/release/{your-binary-name}.zip
, typically this is just the name of your crate if you are using the cargo default binary (i.e. main.rs
)
# build and package deploy-ready artifact
Supported Lambda HTTP Trigger events
- API Gateway (REST API and HTTP API)
- Application Load Balancer
Recommended to use API Gateway with HTTP API with following parameters.
API Type: HTTP
Method: ANY
Resource Path: /{proxy+}
License
MIT