AWS Lambda Adapter is written in Rust and based on AWS Lambda Rust Runtime. AWS Lambda executes functions in x86_64 Amazon Linux Environment. We need to compile the adapter to that environment.
First, clone this repo to your local computer.
$ git clone https://github.com/aws-samples/aws-lambda-adapter.git
$ cd aws-lambda-adapterOn x86_64 Windows, Linux and macOS, you can run one command to compile Lambda Adapter with docker. The Dockerfile is here. AWS CLI v2 should have been installed and configured.
$ make buildOnce the build completes, it creates two docker images:
- "aws-lambda-adapter:latest-x86_64" for x86_64.
- "aws-lambda-adapter:latest-aarch64" for arm64.
AWS Lambda Adapter binary is packaged as '/opt/bootstrap' inside each docker image. "aws-lambda-adapter:latest" is tagged to the same image as "aws-lambda-adapter:latest-x86_64".
If you want to install rust toolchain in your Macbook and play with the source code, you can follow the steps below. First, install rustup if you haven't done it already. Then, add targets for x86_86 and arm64:
$ rustup target add x86_64-unknown-linux-musl
$ rustup target add aarch64-unknown-linux-muslAnd we have to install macOS cross-compiler toolchains. messense/homebrew-macos-cross-toolchains can be used on both Intel chip and Apple M1 chip.
$ brew tap messense/macos-cross-toolchains
$ brew install x86_64-unknown-linux-musl
$ brew install aarch64-unknown-linux-muslAnd we need to inform Cargo that our project uses the newly-installed linker when building for the x86_64-unknown-linux-musl and aarch64-unknown-linux-musl platforms.
Create a new directory called .cargo in your project folder and a new file called config inside the new folder.
$ mkdir .cargo
$ echo '[target.x86_64-unknown-linux-musl]
linker = "x86_64-unknown-linux-musl-gcc"
[target.aarch64-unknown-linux-musl]
linker = "aarch64-unknown-linux-musl-gcc"'> .cargo/configNow we can cross compile AWS Lambda Adapter.
$ CC=x86_64-unknown-linux-musl-gcc cargo build --release --target=x86_64-unknown-linux-musl --features vendored
$ CC=aarch64-unknown-linux-musl-gcc cargo build --release --target=aarch64-unknown-linux-musl --features vendoredLambda Adapter binary for x86_64 will be placed at target/x86_64-unknown-linux-musl/release/bootstrap.
Lambda Adapter binary for arm64 will be placed at target/aarch64-unknown-linux-musl/release/bootstrap.
Finally, run the following command to package lambda adapter into two container images for x86_64 and aarch64.
$ aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
$ docker build -f Dockerfile.mac --build-arg ARCH=x86_64 -t aws-lambda-adapter:latest-x86_64 .
$ docker build -f Dockerfile.mac --build-arg ARCH=aarch64 -t aws-lambda-adapter:latest-aarch64 .
$ docker tag aws-lambda-adapter:latest-x86_64 aws-lambda-adapter:latestWhen these commands complete successfully, you will have the following container images.
- "aws-lambda-adapter:latest-x86_64" for x86_64.
- "aws-lambda-adapter:latest-aarch64" for arm64.
- "aws-lambda-adapter:latest" is the same as "aws-lambda-adapter:latest-x86_64".