Skip to content

Commit 8858f6b

Browse files
authored
Update readme to use cargo-lambda (#441)
This simplifies the process of building functions. Signed-off-by: David Calavera <david.calavera@gmail.com>
1 parent e43bc28 commit 8858f6b

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ rustup target add aarch64-unknown-linux-gnu
5454
rustup target add x86_64-unknown-linux-gnu
5555
```
5656

57-
Once this is done, install [Zig](https://ziglang.org/) using the instructions in their [installation guide](https://ziglang.org/learn/getting-started/#installing-zig), and install `cargo-zigbuild`:
57+
Once this is done, install `cargo-lambda`:
5858

5959
```bash
60-
cargo install cargo-zigbuild
60+
cargo install cargo-lambda
6161
```
6262

63+
This Cargo subcommand will give you the option to install [Zig](https://ziglang.org/) to use as the linker. You can also install [Zig](https://ziglang.org/) using the instructions in their [installation guide](https://ziglang.org/learn/getting-started/#installing-zig).
64+
6365
#### 1.2. Build your Lambda functions
6466

6567
__Amazon Linux 2__
@@ -68,7 +70,7 @@ We recommend you to use Amazon Linux 2 runtimes (such as `provided.al2`) as much
6870

6971
```bash
7072
# Note: replace "aarch64" with "x86_64" if you are building for x86_64
71-
cargo zigbuild --release --target aarch64-unknown-linux-gnu
73+
cargo lambda build --release --target aarch64-unknown-linux-gnu
7274
```
7375

7476
__Amazon Linux 1__
@@ -79,21 +81,21 @@ If you are building for Amazon Linux 1, or you want to support both Amazon Linux
7981

8082
```
8183
# Note: replace "aarch64" with "x86_64" if you are building for x86_64
82-
cargo zigbuild --release --target aarch64-unknown-linux-gnu.2.17
84+
cargo lambda build --release --target aarch64-unknown-linux-gnu.2.17
8385
```
8486

8587
### 2. Deploying the binary to AWS Lambda
8688

8789
For [a custom runtime](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html), AWS Lambda looks for an executable called `bootstrap` in the deployment package zip. Rename the generated executable to `bootstrap` and add it to a zip archive.
8890

89-
__Note__: Depending on the target you used above, you'll find the provided basic executable under the corresponding directory. For example, if you are building the aarch64-unknown-linux-gnu as your target, it will be under `./target/aarch64-unknown-linux-gnu/release/`.
91+
You can find the `bootstrap` binary for your function under the `target/lambda` directory.
9092

9193
#### 2.1. Deploying with the AWS CLI
9294

9395
First, you will need to create a ZIP archive of your Lambda function. For example, if you are using the `basic` example and aarch64-unknown-linux-gnu as your target, you can run:
9496

9597
```bash
96-
cp ./target/aarch64-unknown-linux-gnu/release/examples/basic ./bootstrap && zip lambda.zip bootstrap && rm bootstrap
98+
zip -j lambda.zip target/lambda/basic/bootstrap
9799
```
98100

99101
Now that we have a deployment package (`lambda.zip`), we can use the [AWS CLI](https://aws.amazon.com/cli/) to create a new Lambda function. Make sure to replace the execution role with an existing role in your account!
@@ -141,21 +143,14 @@ Resources:
141143
Handler: bootstrap
142144
Runtime: provided.al2
143145
Timeout: 5
144-
CodeUri: build/
146+
CodeUri: target/lambda/basic/
145147

146148
Outputs:
147149
FunctionName:
148150
Value: !Ref HelloWorldFunction
149151
Description: Name of the Lambda function
150152
```
151153
152-
After building your function, you will also need to store the binary as `bootstrap` in a dedicated directory for that function (e.g. `build/bootstrap`):
153-
154-
```bash
155-
mkdir build
156-
cp ./target/aarch64-unknown-linux-gnu/release/examples/basic ./build/bootstrap
157-
```
158-
159154
You can then deploy your Lambda function using the AWS SAM CLI:
160155
161156
```bash

0 commit comments

Comments
 (0)