{"id":15031579,"url":"https://github.com/softprops/lambda-rust","last_synced_at":"2025-08-20T08:32:27.829Z","repository":{"id":34086371,"uuid":"160704679","full_name":"softprops/lambda-rust","owner":"softprops","description":" 🐳 🦀 a dockerized lambda build env for rust applications","archived":false,"fork":false,"pushed_at":"2022-03-22T12:10:30.000Z","size":128,"stargazers_count":162,"open_issues_count":25,"forks_count":75,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-07T11:33:48.382Z","etag":null,"topics":["aws-lambda","aws-lambda-rust","rust","rustlang"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softprops.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-06T16:52:26.000Z","updated_at":"2024-08-20T16:50:13.000Z","dependencies_parsed_at":"2022-09-01T16:04:54.443Z","dependency_job_id":null,"html_url":"https://github.com/softprops/lambda-rust","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Flambda-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Flambda-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Flambda-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Flambda-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softprops","download_url":"https://codeload.github.com/softprops/lambda-rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230408170,"owners_count":18220974,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","aws-lambda-rust","rust","rustlang"],"created_at":"2024-09-24T20:16:05.722Z","updated_at":"2024-12-19T09:07:19.669Z","avatar_url":"https://github.com/softprops.png","language":"Shell","readme":"# AWS Lambda [Rust](https://www.rust-lang.org/) docker builder 🐑 🦀 🐳 [![Build Status](https://github.com/softprops/lambda-rust/workflows/Main/badge.svg)](https://github.com/softprops/lambda-rust/actions)\n\n\n## 🤔 about\n\nThis docker image extends [lambda ci `provided.al2`](https://github.com/lambci/docker-lambda#documentation) builder docker image, a faithful reproduction of the actual AWS \"**provided.al2**\" Lambda runtime environment,\nand installs [rustup](https://rustup.rs/) and the *stable* rust toolchain.\n\nThis provides a build environment, consistent with your target execution environment for predictable results.\n\n## 📦 install\n\nTags for this docker image follow the naming convention `softprops/lambda-rust:{version}-rust-{rust-stable-version}`\nwhere `{rust-stable-version}` is a stable version of rust.\n\nYou can find a list of available docker tags [here](https://hub.docker.com/r/softprops/lambda-rust/tags)\n\n\u003e 💡 If you don't find the version you're looking for, please [open a new github issue](https://github.com/softprops/lambda-rust/issues/new?title=I%27m%20looking%20for%20version%20xxx) to publish one\n\nYou can also depend directly on `softprops/lambda-rust:latest` for the most recently published version.\n\n## 🤸 usage\n\nThe default docker entrypoint will build a packaged release optimized version of your Rust artifact under `target/lambda/release` to\nisolate the lambda specific build artifacts from your host-local build artifacts.\n\n\u003e **⚠️ Note:** you can switch from the `release` profile to a custom profile like `dev` by providing a `PROFILE` environment variable set to the name of the desired profile. i.e. `-e PROFILE=dev` in your docker run\n\n\u003e **⚠️ Note:** you can include debug symbols in optimized release build binaries by setting `DEBUGINFO`. By default, debug symbols will be stripped from the release binary and set aside in a separate .debug file.\n\nYou will want to volume mount `/code` to the directory containing your cargo project.\n\nYou can pass additional flags to `cargo`, the Rust build tool, by setting the `CARGO_FLAGS` docker env variable.\n\nUnzipped `boostrap` and `boostrap.debug` files are always available\nunder `target/lambda/${PROFILE}/output/${BIN}` dir. If you want only them and don't\nneed a `.zip` archive (e.g. for when running lambdas locally) pass `-e PACKAGE=false`\nflag. More on that in [local testing](#-local-testing).\n\nA typical docker run might look like the following.\n\n```sh\n$ docker run --rm \\\n    -u $(id -u):$(id -g) \\\n    -v ${PWD}:/code \\\n    -v ${HOME}/.cargo/registry:/cargo/registry \\\n    -v ${HOME}/.cargo/git:/cargo/git \\\n    softprops/lambda-rust\n```\n\u003e 💡 The -v (volume mount) flags for `/cargo/{registry,git}` are optional but when supplied, provides a much faster turn around when doing iterative development\n\nNote that `-u $(id -u):$(id -g)` argument is crucial for the container to produce artifacts\nowned by the current host user, otherwise you won't be able to `rm -rf target/lambda`\nor run `cargo update`, because the container will write artifacts owned by `root` docker user\nto `target/lambda` and `./cargo/{registry,git}` dirs which will break your dev and/or ci environment.\n\nYou should also ensure that you do have `${HOME}/.cargo/{registry,git}` dirs created\non your host machine, otherwise docker will create them automatically and assign `root` user\nas an owner for these dirs which is unfortunate...\n\nIf you are using Windows, the command above may need to be modified to include\na `BIN` environment variable set to the name of the binary to be build and packaged\n\n```diff\n$ docker run --rm \\\n    -u $(id -u):$(id -g) \\\n+   -e BIN={your-binary-name} \\\n    -v ${PWD}:/code \\\n    -v ${HOME}/.cargo/registry:/cargo/registry \\\n    -v ${HOME}/.cargo/git:/cargo/git \\\n    softprops/lambda-rust\n```\n\nFor more custom codebases, the '-w' argument can be used to override the working directory.\nThis can be especially useful when using path dependencies for local crates.\n\n```sh\n$ docker run --rm \\\n    -u $(id -u):$(id -g) \\\n    -v ${PWD}/lambdas/mylambda:/code/lambdas/mylambda \\\n    -v ${PWD}/libs/mylib:/code/libs/mylib \\\n    -v ${HOME}/.cargo/registry:/cargo/registry \\\n    -v ${HOME}/.cargo/git:/cargo/git \\\n    -w /code/lambdas/mylambda \\\n    softprops/lambda-rust\n```\n\n## ⚓ using hooks\n\nIf you want to customize certain parts of the build process, you can leverage hooks that this image provides.\nHooks are just shell scripts that are invoked in a specific order, so you can customize the process as you wish. The following hooks exist:\n* `install`: run before `cargo build` - useful for installing native dependencies on the lambda environment\n* `build`: run after `cargo build`, but before packaging the executable into a zip - useful when modifying the executable after compilation\n* `package`: run after packaging the executable into a zip - useful for adding extra files into the zip file\n\nThe hooks' names are predefined and must be placed in a directory `.lambda-rust` in the project root.\n\nYou can take a look at an example [here](./tests/test-func-with-hooks).\n\n## 🔬 local testing\n\nOnce you've built a Rust lambda function artifact, the `provided.al2` runtime expects\ndeployments of that artifact to be named \"**bootstrap**\". The `lambda-rust` docker image\nbuilds a zip file, named after the binary, containing your binary file renamed to \"bootstrap\" for you, but zip file creation is unnecessary for local development.\n\nIn order to prevent the creation of an intermediate `.zip` artifact when testing your lambdas locally, pass `-e PACKAGE=false` during the build. After that the necessary\noutput (not zipped) is available under `target/lambda/{profile}/output/{your-lambda-binary-name}` dir.\nYou will see both `bootstrap` and `bootstrap.debug` files there.\n\u003e **⚠️ Note:** `PACKAGE=false` prevents `package` hook from running.\n\nYou can then invoke this bootstap executable with the lambda-ci docker image for the `provided.al2` AWS lambda runtime with a one off container.\n\n```sh\n# Build your function skipping the zip creation step\n# You may pass `-e PROFILE=dev` to build using dev profile, but here we use `release`\ndocker run \\\n    -u $(id -u):$(id -g) \\\n    -e PACKAGE=false \\\n    -e BIN={your-binary-name} \\\n    -v ${PWD}:/code \\\n    -v ${HOME}/.cargo/registry:/cargo/registry \\\n    -v ${HOME}/.cargo/git:/cargo/git \\\n    softprops/lambda-rust\n\n# start a one-off docker container replicating the \"provided.al2\" lambda runtime\n# awaiting an event to be provided via stdin\n$ docker run \\\n    -i -e DOCKER_LAMBDA_USE_STDIN=1 \\\n    --rm \\\n    -v ${PWD}/target/lambda/release/output/{your-binary-name}:/var/task:ro,delegated \\\n    lambci/lambda:provided.al2\n\n# provide an event payload via stdin (typically a json blob)\n\n# Ctrl-D to yield control back to your function\n```\n\nYou may find the one-off container less than ideal if you wish to trigger your lambda multiple times. For these cases try using the \"stay open\" mode of execution.\n\n```sh\n# start a long running docker container replicating the \"provided\" lambda runtime\n# listening on port 9001\n$ unzip -o \\\n    target/lambda/release/{your-binary-name}.zip \\\n    -d /tmp/lambda \u0026\u0026 \\\n  docker run \\\n    --rm \\\n    -v /tmp/lambda:/var/task:ro,delegated \\\n    -e DOCKER_LAMBDA_STAY_OPEN=1 \\\n    -p 9001:9001 \\\n    lambci/lambda:provided.al2\n```\n\nIn a separate terminal, you can invoke your function with `curl`\n\nThe `-d` flag is a means of providing your function's input.\n\n```sh\n$ curl -d '{}' \\\n    http://localhost:9001/2015-03-31/functions/myfunction/invocations\n```\n\nYou can also use the `aws` cli to invoke your function locally.  The `--payload` is a means of providing your function's input.\n\n```sh\n$ aws lambda invoke \\\n    --endpoint http://localhost:9001 \\\n    --cli-binary-format raw-in-base64-out \\\n    --no-sign-request \\\n    --function-name myfunction \\\n    --payload '{}' out.json \\\n    \u0026\u0026 cat out.json \\\n    \u0026\u0026 rm -f out.json\n```\n\n## 🤸🤸 usage via cargo aws-lambda subcommand\n\nA third party cargo subcommand exists to compile your code into a zip file and deploy it. This comes with only\nrust and docker as dependencies.\n\nSetup\n\n```sh\n$ cargo install cargo-aws-lambda\n```\n\nTo compile and deploy in your project directory\n```sh\n$ cargo aws-lambda {your aws function's full ARN} {your-binary-name}\n```\n\nTo list all options\n```sh\n$ cargo aws-lambda --help\n```\n\nMore instructions can be found [here](https://github.com/vvilhonen/cargo-aws-lambda).\n\n\nDoug Tangren (softprops) 2020\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftprops%2Flambda-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftprops%2Flambda-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftprops%2Flambda-rust/lists"}