Skip to content

Commit

Permalink
upgrade to emulation of amazon provided.al2 runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
softprops committed Aug 23, 2020
1 parent 4e8e978 commit 0397305
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ $ docker run --rm \

* Upgrade to Rust [`1.45.2`](https://blog.rust-lang.org/2020/08/03/Rust-1.45.2.html)

* Upgrade to [amazon linux 2](https://aws.amazon.com/blogs/compute/migrating-aws-lambda-functions-to-al2/) base

# 0.3.0-rust-1.45.0

* Upgrade to Rust [`1.45.0`](https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html)
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# https://github.com/lambci/docker-lambda#documentation
FROM lambci/lambda:build-provided
FROM lambci/lambda:build-provided.al2

ARG RUST_VERSION=1.45.2
RUN yum install -y jq
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION ?= 0.3.0
VERSION ?= 0.4.0
RUST_VERSION ?= 1.45.2
REPO ?= softprops/lambda-rust
TAG ?= "$(REPO):$(VERSION)-rust-$(RUST_VERSION)"
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## 🤔 about

This docker image extends [lambda ci `provided`](https://github.com/lambci/docker-lambda#documentation) builder docker image, a faithful reproduction of the actual AWS "**provided**" Lambda runtime environment,
This 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,
and installs [rustup](https://rustup.rs/) and the *stable* rust toolchain.

This provides a build environment, consistent with your target execution environment for predictable results.
Expand Down Expand Up @@ -99,7 +99,7 @@ You can take a look at an example [here](./tests/test-func-with-hooks).

## 🔬 local testing

Once you've built a Rust lambda function artifact, the `provided` runtime expects
Once you've built a Rust lambda function artifact, the `provided.al2` runtime expects
deployments of that artifact to be named "**bootstrap**". The `lambda-rust` docker image
builds 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.

Expand All @@ -108,7 +108,7 @@ output (not zipped) is available under `target/lambda/{profile}/output/{your-lam
You will see both `bootstrap` and `bootstrap.debug` files there.
> **⚠️ Note:** `PACKAGE=false` prevents `package` hook from running.
You can then invoke this bootstap executable with the lambda-ci docker image for the `provided` AWS lambda runtime with a one off container.
You can then invoke this bootstap executable with the lambda-ci docker image for the `provided.al2` AWS lambda runtime with a one off container.

```sh
# Build your function skipping the zip creation step
Expand All @@ -122,13 +122,13 @@ docker run \
-v ${HOME}/.cargo/git:/cargo/git \
softprops/lambda-rust

# start a one-off docker container replicating the "provided" lambda runtime
# start a one-off docker container replicating the "provided.al2" lambda runtime
# awaiting an event to be provided via stdin
$ docker run \
-i -e DOCKER_LAMBDA_USE_STDIN=1 \
--rm \
-v ${PWD}/target/lambda/release/output/{your-binary-name}:/var/task:ro,delegated \
lambci/lambda:provided
lambci/lambda:provided.al2

# provide an event payload via stdin (typically a json blob)

Expand All @@ -148,7 +148,7 @@ $ unzip -o \
-v /tmp/lambda:/var/task:ro,delegated \
-e DOCKER_LAMBDA_STAY_OPEN=1 \
-p 9001:9001 \
lambci/lambda:provided
lambci/lambda:provided.al2
```

In a separate terminal, you can invoke your function with `curl`
Expand Down
4 changes: 2 additions & 2 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ for project in test-func test-multi-func test-func-with-hooks; do

assert "it packages all bins" package_all "${bin_name}"

# verify packaged artifact by invoking it using the lambdaci "provided" docker image
# verify packaged artifact by invoking it using the lambdaci "provided.al2" docker image
rm -f output.log > /dev/null 2>&1
rm -f test-out.log > /dev/null 2>&1
rm -rf /tmp/lambda > /dev/null 2>&1
Expand All @@ -97,7 +97,7 @@ for project in test-func test-multi-func test-func-with-hooks; do
-i -e DOCKER_LAMBDA_USE_STDIN=1 \
--rm \
-v /tmp/lambda:/var/task \
lambci/lambda:provided < test-event.json | grep -v RequestId | grep -v '^\W*$' > test-out.log
lambci/lambda:provided.al2 < test-event.json | grep -v RequestId | grep -v '^\W*$' > test-out.log

assert "when invoked, it produces expected output" diff expected-output.json test-out.log
done
Expand Down

0 comments on commit 0397305

Please sign in to comment.