asaaki / rust-wasm-on-lambda-edge

Rust/WASM on AWS Lambda@Edge (CloudFront)
https://markentier.tech/posts/2021/01/rust-wasm-on-aws-lambda-edge/
Apache License 2.0
29 stars 1 forks source link
aws aws-cloudfront aws-lambda aws-lambda-edge cloudfront nodejs rust rust-lang wasm wasm-bindgen wasm-pack

Rust/Wasm on AWS Lambda@Edge (CloudFront)

Read the accompanying blog post to this project.

Since we still cannot have native Rust (or WebAssembly for that matter) on AWS Lambda@Edge, we have to come up with our own solution. Here I present mine: using the AWS Lambda Node.js enviroment to execute our Wasm blob generated from Rust code.

tl;dr

make build
make call
make zip
# upload to your AWS Lambda and attach it to a CloudFront distribution (as viewer request trigger)
# check the Cloudwatch logs in the regions you made requests
# be happy - Have a nice day!

This demo doesn't do anything fancy. In fact, it does not alter the request at all and only passes it through as-is.

The function will make a few log statements, check the Cloudwatch logs in the regions you received requests for your CloudFront distribution.

This setup is good to test for the baseline performance.

After the cold-start some requests later the function duration should be around 1 to 2 ms.

Depending on the region and where you are, this translates to 40 to 50 ms in request latency for a small static asset, while without any trigger attached the same request would take around 25 ms.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.