Skip to content

Commit e881b72

Browse files
softpropsdavidbarsky
authored andcommitted
how to build and test with docker (#61)
* how to build and test with docker * typo
1 parent 7436632 commit e881b72

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,40 @@ Invoke it using serverless framework or a configured AWS integrated trigger sour
128128
$ npx serverless invoke -f hello -d '{"foo":"bar"}'
129129
```
130130

131+
#### Docker
132+
133+
Alternatively, you can build a Rust-based Lambda function in a [docker mirror of the AWS Lambda provided runtime with the Rust toolchain preinstalled](https://github.com/softprops/lambda-rust).
134+
135+
Running the following command will start a emphemeral 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`)
136+
137+
```bash
138+
# build and package deploy-ready artifact
139+
$ docker run --rm \
140+
-v ${PWD}:/code \
141+
-v ${HOME}/.cargo/registry:/root/.cargo/registry \
142+
-v ${HOME}/.cargo/git:/root/.cargo/git \
143+
softprops/lambda-rust
144+
```
145+
146+
With your application build and packaged, it's ready to ship to production. You can also invoke it locally to verify is behavior using the [lambdaci :provided docker container](https://hub.docker.com/r/lambci/lambda/) which is also a mirror of the AWS Lambda provided runtime with build dependencies omitted.
147+
148+
```bash
149+
# start a docker container replicating the "provided" lambda runtime
150+
# awaiting an event to be provided via stdin
151+
$ unzip -o \
152+
target/lambda/release/{your-binary-name}.zip \
153+
-d /tmp/lambda && \
154+
docker run \
155+
-i -e DOCKER_LAMBDA_USE_STDIN=1 \
156+
--rm \
157+
-v /tmp/lambda:/var/task \
158+
lambci/lambda:provided
159+
160+
# provide an event payload via stdin (typically a json blob)
161+
162+
# Ctrl-D to yield control back to your function
163+
```
164+
131165

132166
## lambda-runtime-client
133167

0 commit comments

Comments
 (0)