Docker build environment for Rust Runtime for AWS Lambda
$ mkdir workspace && cd workspace
$ docker run -it --rm \
-v "$(pwd):/build" \
-w "/build" \
-h "$(basename "$(pwd)")" \
anyakichi/lambda-rust-builder
[builder@workspace build]$ extract
[builder@workspace build]$ setup
[builder@workspace lambda-rust-sample]$ build
[builder@workspace lambda-rust-sample]$ package
You can use the din wrapper script for simplicity.
$ mkdir workspace && cd workspace
$ din anyakichi/lambda-rust-builder
[builder@workspace build]$ extract
[builder@workspace build]$ setup
[builder@workspace lambda-rust-sample]$ build
[builder@workspace lambda-rust-sample]$ package
If you want to share cargo caches with host environment, add extra options.
$ din -e CARGO_HOME=/cargo -v $HOME/.cargo:/cargo anyakichi/lambda-rust-builder
[builder@workspace build]$ build
By default, sample lambda program (https://github.com/anyakichi/lambda-rust-sample.git) is downloaded and compiled, but you can override it:
$ din -e GIT_REPO=<your-repo> anyakichi/lambda-rust-builder
Or you can build your own Docker build environment with Dockerfile.
FROM anyakichi/lambda-rust-builder
ENV GIT_REPO=<your-repo>
Download project repository using git clone.
Move to project repository.
Build the binary.
Create a zip file to upload to Lambda.
Run the lambda function in Docker container.
If you use the run sub command, publish port 9001 to host environment.
$ din -p 9001:9001 anyakichi/lambda-rust-builder
[builder@workspace build]$ run
And access to this from host environment.
$ curl -d '{}' http://localhost:9001/2015-03-31/functions/myfunction/invocations
And you can execute anything in the container.
Build debug binary:
[builder@workspace lambda-rust-sample]$ cargo build
Run lambda handler passing data from stdin:
[builder@workspace lambda-rust-sample]$ echo '{}' \
| DOCKER_LAMBDA_USE_STDIN=1 /var/runtime/init -bootstrap "target/release/lambda-rust-sample"
You can execute sub commands directly from din command.
$ din -p 9001:9001 anyakichi/lambda-rust-builder run
Content type
Image
Digest
sha256:a65b4c073…
Size
524 MB
Last updated
about 1 year ago
docker pull anyakichi/lambda-rust-builder:al2-rustup