Skip to content

Commit 6bc4a28

Browse files
authored
Support for arm64 architecture (#52)
1 parent 7aa1883 commit 6bc4a28

File tree

6 files changed

+277
-245
lines changed

6 files changed

+277
-245
lines changed

Makefile

+28-16
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,43 @@
22
RELEASE_BUILD_LINKER_FLAGS=-s -w
33

44
BINARY_NAME=aws-lambda-rie
5-
DESTINATION=bin/${BINARY_NAME}
5+
ARCH=x86_64
6+
GO_ARCH_old := amd64
7+
GO_ARCH_x86_64 := amd64
8+
GO_ARCH_arm64 := arm64
9+
DESTINATION_old:= bin/${BINARY_NAME}
10+
DESTINATION_x86_64 := bin/${BINARY_NAME}-x86_64
11+
DESTINATION_arm64 := bin/${BINARY_NAME}-arm64
12+
13+
compile-with-docker-all:
14+
make ARCH=x86_64 compile-with-docker
15+
make ARCH=arm64 compile-with-docker
16+
make ARCH=old compile-with-docker
17+
18+
compile-lambda-linux-all:
19+
make ARCH=x86_64 compile-lambda-linux
20+
make ARCH=arm64 compile-lambda-linux
21+
make ARCH=old compile-lambda-linux
622

723
compile-with-docker:
8-
docker run --env GOPROXY=direct -v $(shell pwd):/LambdaRuntimeLocal -w /LambdaRuntimeLocal golang:1.14 make compile-lambda-linux
24+
docker run --env GOPROXY=direct -v $(shell pwd):/LambdaRuntimeLocal -w /LambdaRuntimeLocal golang:1.14 make ARCH=${ARCH} compile-lambda-linux
925

1026
compile-lambda-linux:
11-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "${RELEASE_BUILD_LINKER_FLAGS}" -o ${DESTINATION} ./cmd/aws-lambda-rie
27+
CGO_ENABLED=0 GOOS=linux GOARCH=${GO_ARCH_${ARCH}} go build -ldflags "${RELEASE_BUILD_LINKER_FLAGS}" -o ${DESTINATION_${ARCH}} ./cmd/aws-lambda-rie
1228

1329
tests:
1430
go test ./...
1531

16-
integ-tests-and-compile: tests compile-lambda-linux
17-
python3 -m venv .venv
18-
.venv/bin/pip install --upgrade pip
19-
.venv/bin/pip install requests
20-
.venv/bin/python3 test/integration/local_lambda/end-to-end-test.py
21-
22-
integ-tests-with-docker: tests compile-with-docker
23-
python3 -m venv .venv
24-
.venv/bin/pip install --upgrade pip
25-
.venv/bin/pip install requests
26-
.venv/bin/python3 test/integration/local_lambda/end-to-end-test.py
32+
integ-tests-and-compile: tests
33+
make compile-lambda-linux-all
34+
make integ-tests
2735

36+
integ-tests-with-docker: tests
37+
make compile-with-docker-all
38+
make integ-tests
39+
2840
integ-tests:
2941
python3 -m venv .venv
3042
.venv/bin/pip install --upgrade pip
31-
.venv/bin/pip install requests
32-
.venv/bin/python3 test/integration/local_lambda/end-to-end-test.py
43+
.venv/bin/pip install requests parameterized
44+
.venv/bin/python3 test/integration/local_lambda/test_end_to_end.py

README.md

+39-23
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ Instructions for installing AWS Lambda Runtime Interface Emulator for your platf
1818

1919
| Platform | Command to install |
2020
|---------|---------
21-
| macOS | `mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && chmod +x ~/.aws-lambda-rie/aws-lambda-rie` |
22-
| Linux | `mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && chmod +x ~/.aws-lambda-rie/aws-lambda-rie` |
23-
| Windows | `Invoke-WebRequest -OutFile 'C:\Program Files\aws lambda\aws-lambda-rie' https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie` |
21+
| macOS/Linux x86\_64 | `mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && chmod +x ~/.aws-lambda-rie/aws-lambda-rie` |
22+
| macOS/Linux arm64 | `mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie-arm64 && chmod +x ~/.aws-lambda-rie/aws-lambda-rie` |
23+
| Windows x86\_64 | `Invoke-WebRequest -OutFile 'C:\Program Files\aws lambda\aws-lambda-rie' https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie` |
24+
| Windows arm64 | `Invoke-WebRequest -OutFile 'C:\Program Files\aws lambda\aws-lambda-rie' https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie-arm64` |
2425

2526

2627
## Getting started
@@ -53,10 +54,14 @@ The AWS base images for Lambda include the runtime interface emulator. You can a
5354
### Build RIE into your base image
5455

5556
You can build RIE into a base image. Download the RIE from GitHub to your local machine and update your Dockerfile to install RIE.
56-
57+
5758
#### To build the emulator into your image
5859

59-
1. Create a script and save it in your project directory. The following example shows a typical script for a Node.js function. The presence of the AWS_LAMBDA_RUNTIME_API environment variable indicates the presence of the runtime API. If the runtime API is present, the script runs the runtime interface client (https://docs.aws.amazon.com/lambda/latest/dg/runtimes-images.html#runtimes-api-client). Otherwise, the script runs the runtime interface emulator.
60+
1. Create a script and save it in your project directory. Set execution permissions for the script file.
61+
62+
The script checks for the presence of the `AWS_LAMBDA_RUNTIME_API` environment variable, which indicates the presence of the runtime API. If the runtime API is present, the script runs [the runtime interface client](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-images.html#runtimes-api-client). Otherwise, the script runs the runtime interface emulator.
63+
64+
The following example shows a typical script for a Node.js function.
6065
```
6166
#!/bin/sh
6267
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
@@ -65,45 +70,56 @@ You can build RIE into a base image. Download the RIE from GitHub to your local
6570
exec /usr/bin/npx aws-lambda-ric
6671
fi
6772
```
68-
69-
2. Download the runtime interface emulator (https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie) from GitHub into your project directory.
7073

71-
3. Install the emulator package and change ENTRYPOINT to run the new script by adding the following lines to your Dockerfile:
74+
2. Download the [runtime interface emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest) for your target architecture (`aws-lambda-rie` for x86\_64 or `aws-lambda-rie-arm64` for arm64) from GitHub into your project directory.
75+
76+
3. Install the emulator package and change `ENTRYPOINT` to run the new script by adding the following lines to your Dockerfile:
77+
78+
To use the default x86\_64 architecture
79+
```
80+
ADD aws-lambda-rie /usr/local/bin/aws-lambda-rie
81+
ENTRYPOINT [ "/entry_script.sh" ]
82+
```
83+
84+
To use the arm64 architecture:
7285
```
73-
ADD aws-lambda-rie /usr/local/bin/aws-lambda-rie
86+
ADD aws-lambda-rie-arm64 /usr/local/bin/aws-lambda-rie
7487
ENTRYPOINT [ "/entry_script.sh" ]
7588
```
7689

77-
4. Build your image locally using the docker build command.
90+
4. Build your image locally using the docker build command.
7891
```
7992
docker build -t myfunction:latest .
8093
```
8194
82-
5. Run your image locally using the docker run command.
95+
5. Run your image locally using the docker run command.
8396
```
8497
docker run -p 9000:8080 myfunction:latest
8598
```
8699
87100
### Test an image without adding RIE to the image
88101
89-
You install the runtime interface emulator to your local machine. When you run the image function, you set the entry point to be the emulator.
102+
You install the runtime interface emulator to your local machine. When you run the container image, you set the entry point to be the emulator.
90103
*To test an image without adding RIE to the image *
91104
92-
1. From your project directory, run the following command to download the RIE from GitHub and install it on your local machine.
105+
1. From your project directory, run the following command to download the RIE (x86-64 architecture) from GitHub and install it on your local machine.
93106
94107
```
95-
mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie \
96-
https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie \
97-
&& chmod +x ~/.aws-lambda-rie/aws-lambda-rie
98-
```
108+
mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie \
109+
https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie \
110+
&& chmod +x ~/.aws-lambda-rie/aws-lambda-rie
111+
```
99112
100-
2. Run your Lambda image function using the docker run command.
113+
To download the RIE for arm64 architecture, use the previous command with a different GitHub download url.
114+
```
115+
https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie-arm64 \
116+
```
101117
118+
2. Run your Lambda image function using the docker run command.
119+
```
120+
docker run -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 myfunction:latest
121+
--entrypoint /aws-lambda/aws-lambda-rie <image entrypoint> <(optional) image command>`
102122
```
103-
docker run -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 \
104-
--entrypoint /aws-lambda/aws-lambda-rie \
105-
myfunction:latest <image entrypoint> <(optional) image command>
106-
````
107123
108124
This runs the image as a container and starts up an endpoint locally at `localhost:9000/2015-03-31/functions/function/invocations`.
109125
@@ -142,7 +158,7 @@ configurations that will not be emulated by this component.
142158
* You can also use it to test extensions and agents built into the container image against the Lambda Extensions API.
143159
* This component does _not_ emulate Lambda’s orchestration, or security and authentication configurations.
144160
* The component does _not_ support X-ray and other Lambda integrations locally.
145-
* The component supports only Linux x86-64 architectures.
161+
* The component supports only Linux, for x86-64 and arm64 architectures.
146162
147163
## Security
148164

test/integration/local_lambda/end-to-end-test.py

-198
This file was deleted.

0 commit comments

Comments
 (0)