Skip to content

Commit f542d32

Browse files
committed
Add ARM64 architecture support
1 parent 386c124 commit f542d32

16 files changed

+454
-134
lines changed

README.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,135 @@
11
## AWS Lambda Python Runtime Interface Client
22

3+
<<<<<<< HEAD
4+
The Lambda Runtime Interface Client helps with packaging functions using your own or community provided images.
5+
It allows your runtime to receive requests from and send requests to the Lambda service.
6+
The Runtime client starts the runtime and communicates with the Lambda [Runtime API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html) i.e., it calls the API for invocation events, starts the function code, calls the API to return the response.
7+
The Lambda Python Runtime Interface Client is vended through [pip](https://pypi.org/project/awslambdaric).
8+
You can include this package in your preferred base image to make that base image Lambda compatible.
9+
10+
## Requirements
11+
The Python Runtime Interface Client package currently works on Python versions:
12+
- Python 3.6.x
13+
- Python 3.7.x
14+
- Python 3.8.x
15+
- Python 3.9.x
16+
17+
## Usage
18+
19+
### Creating a Docker Image for Lambda with the Runtime Interface Client
20+
First step is to choose the base image to be used. The supported Linux OS distributions are:
21+
22+
- Amazon Linux 2
23+
- Alpine
24+
- CentOS
25+
- Debian
26+
- Ubuntu
27+
28+
29+
Then, the Runtime Interface Client needs to be installed. We provide both wheel and source distribution. If the OS/pip version used does not support manylinux2014 wheels, you will also need to install the required build dependencies. Also, the Lambda function code needs to be copied into the image.
30+
31+
```Docker
32+
# Include global arg in this stage of the build
33+
ARG FUNCTION_DIR
34+
35+
# Install aws-lambda-cpp build dependencies
36+
RUN apt-get update && \
37+
apt-get install -y \
38+
g++ \
39+
make \
40+
cmake \
41+
unzip \
42+
libcurl4-openssl-dev
43+
44+
45+
# Create function directory
46+
RUN mkdir -p ${FUNCTION_DIR}
47+
48+
# Copy handler function
49+
COPY app/* ${FUNCTION_DIR}
50+
51+
# Install the function's dependencies
52+
RUN pip install \
53+
--target ${FUNCTION_DIR} \
54+
awslambdaruntimeclient
55+
```
56+
57+
The next step would be to set the `ENTRYPOINT` property of the Docker image to invoke the Runtime Interface Client and then set the `CMD` argument to specify the desired handler.
58+
59+
Example Dockerfile (to keep the image light we use a multi-stage build):
60+
```Docker
61+
# Define custom function directory
62+
ARG FUNCTION_DIR="/function"
63+
64+
FROM python:buster as build-image
65+
66+
# Include global arg in this stage of the build
67+
ARG FUNCTION_DIR
68+
69+
# Install aws-lambda-cpp build dependencies
70+
RUN apt-get update && \
71+
apt-get install -y \
72+
g++ \
73+
make \
74+
cmake \
75+
unzip \
76+
libcurl4-openssl-dev
77+
78+
79+
# Create function directory
80+
RUN mkdir -p ${FUNCTION_DIR}
81+
82+
# Copy handler function
83+
COPY app/* ${FUNCTION_DIR}
84+
85+
# Install the function's dependencies
86+
RUN pip install \
87+
--target ${FUNCTION_DIR} \
88+
awslambdaric
89+
90+
91+
FROM python:buster
92+
93+
# Include global arg in this stage of the build
94+
ARG FUNCTION_DIR
95+
96+
# Set working directory to function root directory
97+
WORKDIR ${FUNCTION_DIR}
98+
99+
# Copy in the built dependencies
100+
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
101+
102+
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
103+
CMD [ "app.handler" ]
104+
105+
```
106+
107+
### Local Testing
108+
109+
For testing locally you will need to set up a local Runtime Interface Emulator against which the Runtime Interface Client will make API calls. You will need to post data to the endpoint it creates in order to invoke your function. For more information check out the [Runtime Interface Emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator).
110+
111+
112+
## Development
113+
114+
### Building the package
115+
Clone this repository and run:
116+
117+
```bash
118+
make init
119+
make build
120+
```
121+
122+
### Running tests
123+
124+
Make sure the project is built:
125+
```bash
126+
make init build
127+
```
128+
Then,
129+
* to run unit tests: `make test`
130+
* to run integration tests: `make test-integ`
131+
* to run examples: `make test-example`
132+
=======
3133
We have open-sourced a set of software packages, Runtime Interface Clients (RIC), that implement the Lambda
4134
[Runtime API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html), allowing you to seamlessly extend your preferred
5135
base images to be Lambda compatible.
@@ -11,6 +141,7 @@ You can include this package in your preferred base image to make that base imag
11141
## Requirements
12142
The Python Runtime Interface Client package currently supports Python versions:
13143
- 3.6.x up to and including 3.9.x
144+
>>>>>>> origin/main
14145
15146
## Usage
16147

awslambdaric/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
"""
44

5-
__version__ = "1.2.2"
5+
__version__ = "2.0.0"

scripts/preinstall.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ else
3434
--prefix "$ARTIFACTS_DIR" \
3535
--disable-shared \
3636
--without-ssl \
37+
--with-pic \
3738
--without-zlib && \
3839
make && \
3940
make install

tests/integration/codebuild/buildspec.os.alpine.1.yml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ batch:
1010
static:
1111
ignore-failure: false
1212
env:
13-
type: LINUX_CONTAINER
1413
privileged-mode: true
1514
dynamic:
1615
env:
@@ -27,15 +26,25 @@ phases:
2726
- echo "Extracting and including the Runtime Interface Emulator"
2827
- SCRATCH_DIR=".scratch"
2928
- mkdir "${SCRATCH_DIR}"
30-
- tar -xvf tests/integration/resources/aws-lambda-rie.tar.gz --directory "${SCRATCH_DIR}"
29+
- ARCHITECTURE=$(arch)
30+
- >
31+
if [[ "$ARCHITECTURE" == "x86_64" ]]; then
32+
RIE="aws-lambda-rie"
33+
elif [[ "$ARCHITECTURE" == "aarch64" ]]; then
34+
RIE="aws-lambda-rie-arm64"
35+
else
36+
echo "Architecture $ARCHITECTURE is not currently supported."
37+
exit 1
38+
fi
39+
- tar -xvf tests/integration/resources/${RIE}.tar.gz --directory "${SCRATCH_DIR}"
3140
- >
3241
cp "tests/integration/docker/Dockerfile.echo.${OS_DISTRIBUTION}" \
3342
"${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp"
3443
- >
3544
echo "RUN apk add curl" >> \
3645
"${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp"
3746
- >
38-
echo "COPY ${SCRATCH_DIR}/aws-lambda-rie /usr/bin/aws-lambda-rie" >> \
47+
echo "COPY ${SCRATCH_DIR}/${RIE} /usr/bin/${RIE}" >> \
3948
"${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp"
4049
- >
4150
if [[ -z "${DOCKERHUB_USERNAME}" && -z "${DOCKERHUB_PASSWORD}" ]];
@@ -60,12 +69,11 @@ phases:
6069
- >
6170
docker run \
6271
--detach \
63-
-e "PYTHON_LOCATION=${PYTHON_LOCATION}" \
6472
--name "${TEST_NAME}-app" \
6573
--network "${TEST_NAME}-network" \
6674
--entrypoint="" \
6775
"${IMAGE_TAG}" \
68-
sh -c '/usr/bin/aws-lambda-rie ${PYTHON_LOCATION} -m awslambdaric app.handler'
76+
sh -c "/usr/bin/${RIE} ${PYTHON_LOCATION} -m awslambdaric app.handler"
6977
- sleep 2
7078
- >
7179
docker run \
@@ -81,19 +89,20 @@ phases:
8189
echo "Response: ${actual}"
8290
if [[ "$actual" != "$expected" ]]; then
8391
echo "fail! runtime: $RUNTIME - expected output $expected - got $actual"
84-
echo "---------Container Logs: ${TEST_NAME}-app----------"
85-
echo
86-
docker logs "${TEST_NAME}-app"
87-
echo
88-
echo "---------------------------------------------------"
89-
echo "--------Container Logs: ${TEST_NAME}-tester--------"
90-
echo
91-
docker logs "${TEST_NAME}-tester"
92-
echo
93-
echo "---------------------------------------------------"
9492
exit -1
9593
fi
9694
finally:
95+
- |
96+
echo "---------Container Logs: ${TEST_NAME}-app----------"
97+
echo
98+
docker logs "${TEST_NAME}-app" || true
99+
echo
100+
echo "---------------------------------------------------"
101+
echo "--------Container Logs: ${TEST_NAME}-tester--------"
102+
echo
103+
docker logs "${TEST_NAME}-tester" || true
104+
echo
105+
echo "---------------------------------------------------"
97106
- echo "Cleaning up..."
98107
- docker stop "${TEST_NAME}-app" || true
99108
- docker rm --force "${TEST_NAME}-app" || true

tests/integration/codebuild/buildspec.os.alpine.2.yml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ batch:
1010
static:
1111
ignore-failure: false
1212
env:
13-
type: LINUX_CONTAINER
1413
privileged-mode: true
1514
dynamic:
1615
env:
@@ -29,15 +28,25 @@ phases:
2928
- echo "Extracting and including the Runtime Interface Emulator"
3029
- SCRATCH_DIR=".scratch"
3130
- mkdir "${SCRATCH_DIR}"
32-
- tar -xvf tests/integration/resources/aws-lambda-rie.tar.gz --directory "${SCRATCH_DIR}"
31+
- ARCHITECTURE=$(arch)
32+
- >
33+
if [[ "$ARCHITECTURE" == "x86_64" ]]; then
34+
RIE="aws-lambda-rie"
35+
elif [[ "$ARCHITECTURE" == "aarch64" ]]; then
36+
RIE="aws-lambda-rie-arm64"
37+
else
38+
echo "Architecture $ARCHITECTURE is not currently supported."
39+
exit 1
40+
fi
41+
- tar -xvf tests/integration/resources/${RIE}.tar.gz --directory "${SCRATCH_DIR}"
3342
- >
3443
cp "tests/integration/docker/Dockerfile.echo.${OS_DISTRIBUTION}" \
3544
"${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp"
3645
- >
3746
echo "RUN apk add curl" >> \
3847
"${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp"
3948
- >
40-
echo "COPY ${SCRATCH_DIR}/aws-lambda-rie /usr/bin/aws-lambda-rie" >> \
49+
echo "COPY ${SCRATCH_DIR}/${RIE} /usr/bin/${RIE}" >> \
4150
"${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp"
4251
- >
4352
if [[ -z "${DOCKERHUB_USERNAME}" && -z "${DOCKERHUB_PASSWORD}" ]];
@@ -62,12 +71,11 @@ phases:
6271
- >
6372
docker run \
6473
--detach \
65-
-e "PYTHON_LOCATION=${PYTHON_LOCATION}" \
6674
--name "${TEST_NAME}-app" \
6775
--network "${TEST_NAME}-network" \
6876
--entrypoint="" \
6977
"${IMAGE_TAG}" \
70-
sh -c '/usr/bin/aws-lambda-rie ${PYTHON_LOCATION} -m awslambdaric app.handler'
78+
sh -c "/usr/bin/${RIE} ${PYTHON_LOCATION} -m awslambdaric app.handler"
7179
- sleep 2
7280
- >
7381
docker run \
@@ -83,19 +91,20 @@ phases:
8391
echo "Response: ${actual}"
8492
if [[ "$actual" != "$expected" ]]; then
8593
echo "fail! runtime: $RUNTIME - expected output $expected - got $actual"
86-
echo "---------Container Logs: ${TEST_NAME}-app----------"
87-
echo
88-
docker logs "${TEST_NAME}-app"
89-
echo
90-
echo "---------------------------------------------------"
91-
echo "--------Container Logs: ${TEST_NAME}-tester--------"
92-
echo
93-
docker logs "${TEST_NAME}-tester"
94-
echo
95-
echo "---------------------------------------------------"
9694
exit -1
9795
fi
9896
finally:
97+
- |
98+
echo "---------Container Logs: ${TEST_NAME}-app----------"
99+
echo
100+
docker logs "${TEST_NAME}-app" || true
101+
echo
102+
echo "---------------------------------------------------"
103+
echo "--------Container Logs: ${TEST_NAME}-tester--------"
104+
echo
105+
docker logs "${TEST_NAME}-tester" || true
106+
echo
107+
echo "---------------------------------------------------"
99108
- echo "Cleaning up..."
100109
- docker stop "${TEST_NAME}-app" || true
101110
- docker rm --force "${TEST_NAME}-app" || true

0 commit comments

Comments
 (0)