Inititalize a new package with a binary crate and add
lamedh is netlify's fork of the official AWS Lambda runtime for Rust
The code to run a hello-world lambda uses a couple macros to make things easier:
tokio::mainfor an async runtime
lambda(http)to bootstrap the lambda function execution context
To build for the runtime Netlify expects, we can use
x86_64-unknown-linux-musl installed via rustup. When we
cargo build we'll specify the target as well as
release. We specify release here because we want a smaller end artifact to upload and debug releases can be quite large.
If you're on macos and you get this linker error message:
then you need to install some cross-compilation tooling.
and then tell cargo to use the linker by specifying the following in
Now after building, we can find the binary at
We'll deal with renaming the binary in a second, but first we can test the output on netlify by copying the binary into the
./functions folder and renaming it to something like
Deploying to netlify will send our function up to a deploy preview, which lets us test our function without deploying to our primary live site.
You should see something like this, which indicates one new function has been deployed.
Netlify doesn't hand us the location of our function URLs, so we'll have to construct them ourselves or view the function in the netlify dashboard. Using
curl or your favorite http request tool (like postman). The url will be the
Website Draft URL plus
.netlify/functions and finally the name of our function. We should get a response "boop".
We can not currently view function logs for deploy previews (we'll cover implementing our over observability soon), so for now we need to deploy to production.
and now after curling the production URL we'll see the