You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This docker image extends AWS Lambda `provided.al2 runtime environment, and installs [rustup](https://rustup.rs/) and the *stable* rust toolchain.
5
+
This docker image extends AWS Lambda `provided.al2` runtime environment, and installs [rustup](https://rustup.rs/) and the *stable* rust toolchain.
7
6
8
7
This provides a build environment, consistent with your target execution environment for predictable results.
9
8
@@ -24,7 +23,7 @@ The default docker entrypoint will build a packaged release optimized version of
24
23
isolate the lambda specific build artifacts from your host-local build artifacts.
25
24
26
25
> **⚠️ 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
27
-
26
+
>
28
27
> **⚠️ 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.
29
28
30
29
You will want to volume mount `/code` to the directory containing your cargo project.
@@ -40,15 +39,16 @@ A typical docker run might look like the following.
40
39
41
40
```sh
42
41
$ docker run --rm \
43
-
-u $(id -u):$(id -g) \
42
+
-u "$(id -u)":"$(id -g)" \
44
43
-v ${PWD}:/code \
45
44
-v ${HOME}/.cargo/registry:/cargo/registry \
46
45
-v ${HOME}/.cargo/git:/cargo/git \
47
46
rustserverless/lambda-rust
48
47
```
48
+
49
49
> 💡 The -v (volume mount) flags for `/cargo/{registry,git}` are optional but when supplied, provides a much faster turn around when doing iterative development
50
50
51
-
Note that `-u $(id -u):$(id -g)` argument is crucial for the container to produce artifacts
51
+
Note that `-u "$(id -u)":$(id -g)` argument is crucial for the container to produce artifacts
52
52
owned by the current host user, otherwise you won't be able to `rm -rf target/lambda`
53
53
or run `cargo update`, because the container will write artifacts owned by `root` docker user
54
54
to `target/lambda` and `./cargo/{registry,git}` dirs which will break your dev and/or ci environment.
@@ -86,8 +86,9 @@ $ docker run --rm \
86
86
87
87
## ⚓ using hooks
88
88
89
-
If you want to customize certain parts of the build process, you can leverage hooks that this image provides.
90
-
Hooks are just shell scripts that are invoked in a specific order, so you can customize the process as you wish. The following hooks exist:
89
+
You can leverage hooks provided in the image to customize certain parts of the build process.
90
+
Hooks are shell scripts that are invoked if they exist, so you can customize the process. The following hooks exist:
91
+
91
92
*`install`: run before `cargo build` - useful for installing native dependencies on the lambda environment
92
93
*`build`: run after `cargo build`, but before packaging the executable into a zip - useful when modifying the executable after compilation
93
94
*`package`: run after packaging the executable into a zip - useful for adding extra files into the zip file
@@ -121,56 +122,33 @@ docker run \
121
122
-v ${HOME}/.cargo/git:/cargo/git \
122
123
rustserverless/lambda-rust
123
124
124
-
# start a one-off docker container replicating the "provided.al2" lambda runtime
# provide an event payload via stdin (typically a json blob)
125
+
# Build a container with your binary as the runtime
133
126
134
-
# Ctrl-D to yield control back to your function
135
-
```
127
+
$ docker build -t mylambda -f- .<<EOF
128
+
FROM public.ecr.aws/lambda/provided:al2
129
+
COPY bootstrap /var/runtime
130
+
CMD [ "function.handler" ]
131
+
EOF
136
132
137
-
You 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.
138
-
139
-
```sh
140
-
# start a long running docker container replicating the "provided" lambda runtime
141
-
# listening on port 9001
142
-
$ unzip -o \
143
-
target/lambda/release/{your-binary-name}.zip \
144
-
-d /tmp/lambda && \
145
-
docker run \
146
-
--rm \
147
-
-v /tmp/lambda:/var/task:ro,delegated \
148
-
-e DOCKER_LAMBDA_STAY_OPEN=1 \
149
-
-p 9001:9001 \
150
-
public.ecr.aws/lambda/provided:al2
151
-
```
133
+
# start a container based on your image
134
+
$ docker run \
135
+
--name lambda \
136
+
--rm \
137
+
-p 9000:8080 \
138
+
-d mylambda
152
139
153
-
In a separate terminal, you can invoke your function with `curl`
140
+
# provide an event payload (in event.json" by http POST to the container
154
141
155
-
The `-d` flag is a means of providing your function's input.
0 commit comments