AWS Lambda Runtime Interface Client for Python
Project description
AWS Lambda Python Runtime Interface Client
We have open-sourced a set of software packages, Runtime Interface Clients (RIC), that implement the Lambda Runtime API, allowing you to seamlessly extend your preferred base images to be Lambda compatible. The Lambda Runtime Interface Client is a lightweight interface that allows your runtime to receive requests from and send requests to the Lambda service.
The Lambda Python Runtime Interface Client is vended through pip. You can include this package in your preferred base image to make that base image Lambda compatible.
Requirements
The Python Runtime Interface Client package currently supports Python versions:
- 3.7.x up to and including 3.12.x
Usage
Creating a Docker Image for Lambda with the Runtime Interface Client
First step is to choose the base image to be used. The supported Linux OS distributions are:
- Amazon Linux 2
- Alpine
- CentOS
- Debian
- Ubuntu
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, your Lambda function code needs to be copied into the image.
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Install aws-lambda-cpp build dependencies
RUN apt-get update && \
apt-get install -y \
g++ \
make \
cmake \
unzip \
libcurl4-openssl-dev
# Copy function code
RUN mkdir -p ${FUNCTION_DIR}
COPY app/* ${FUNCTION_DIR}
# Install the function's dependencies
RUN pip install \
--target ${FUNCTION_DIR} \
awslambdaric
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.
Example Dockerfile (to keep the image light we use a multi-stage build):
# Define custom function directory
ARG FUNCTION_DIR="/function"
FROM public.ecr.aws/docker/library/python:buster as build-image
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Install aws-lambda-cpp build dependencies
RUN apt-get update && \
apt-get install -y \
g++ \
make \
cmake \
unzip \
libcurl4-openssl-dev
# Copy function code
RUN mkdir -p ${FUNCTION_DIR}
COPY app/* ${FUNCTION_DIR}
# Install the function's dependencies
RUN pip install \
--target ${FUNCTION_DIR} \
awslambdaric
FROM public.ecr.aws/docker/library/python:buster
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Set working directory to function root directory
WORKDIR ${FUNCTION_DIR}
# Copy in the built dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
CMD [ "app.handler" ]
Example Python handler app.py
:
def handler(event, context):
return "Hello World!"
Local Testing
To make it easy to locally test Lambda functions packaged as container images we open-sourced a lightweight web-server, Lambda Runtime Interface Emulator (RIE), which allows your function packaged as a container image to accept HTTP requests. You can install the AWS Lambda Runtime Interface Emulator on your local machine to test your function. Then when you run the image function, you set the entrypoint to be the emulator.
To install the emulator and test your Lambda function
- From your project directory, run the following command to download the RIE from GitHub and install it on your local machine.
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
- Run your Lambda image function using the docker run command.
docker run -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 \
--entrypoint /aws-lambda/aws-lambda-rie \
myfunction:latest \
/usr/local/bin/python -m awslambdaric app.handler
This runs the image as a container and starts up an endpoint locally at http://localhost:9000/2015-03-31/functions/function/invocations
.
- Post an event to the following endpoint using a curl command:
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
This command invokes the function running in the container image and returns a response.
Alternately, you can also include RIE as a part of your base image. See the AWS documentation on how to Build RIE into your base image.
Development
Building the package
Clone this repository and run:
make init
make build
Running tests
Make sure the project is built:
make init build
Then,
- to run unit tests:
make test
- to run integration tests:
make test-integ
- to run smoke tests:
make test-smoke
Troubleshooting
While running integration tests, you might encounter the Docker Hub rate limit error with the following body:
You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limits
To fix the above issue, consider authenticating to a Docker Hub account by setting the Docker Hub credentials as below CodeBuild environment variables.
DOCKERHUB_USERNAME=<dockerhub username>
DOCKERHUB_PASSWORD=<dockerhub password>
Recommended way is to set the Docker Hub credentials in CodeBuild job by retrieving them from AWS Secrets Manager.
Security
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our vulnerability reporting page. Please do not create a public github issue.
License
This project is licensed under the Apache-2.0 License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for awslambdaric-2.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af33ba6c4da9df2ec1a47243f27c6f858d70719c0a4cb451f4e99578d89d5171 |
|
MD5 | 5d6f5a04a4973eda5002ee8511cb4171 |
|
BLAKE2b-256 | a38cae34c310f2ff9fa914ea737be7586cfca9e1b33802d06111a94de5de70ea |
Hashes for awslambdaric-2.1.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a25f4947cab1a580fa6ac7414132d61cd838ef03decd7be9736f8709457a20c |
|
MD5 | 41694fa46697037755fab342e41ddd18 |
|
BLAKE2b-256 | 588efc9347ac4dfa967fed5518d3c98e7281860efdb4791928eb4d6afa0e167f |
Hashes for awslambdaric-2.1.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64f9835f8586c467d85a318a2a316d617ffd5bffc74ae5445bf42758f1766493 |
|
MD5 | 9e0b992bb89d17493d889e129e682ea8 |
|
BLAKE2b-256 | f8db19fa94366b8b94b6019f4cb77ea8ebb0f850e249d8102227a1be28a3ca37 |
Hashes for awslambdaric-2.1.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90a5aba2ad57aec5a49fb41e66959ff89fc3568d2209e756c6405b07f29578b1 |
|
MD5 | 2e96d03f4af121ed6e3503f228ee33f2 |
|
BLAKE2b-256 | af7483b7c85fdee20ca1ea4f7bca06c493284fe07f3ddda23b39d77399dd0361 |
Hashes for awslambdaric-2.1.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21584aea67948a0a4231a178b0ee13aea7db13e59376ab9f56e4fc5671bb805e |
|
MD5 | 25c3d5b7c9591c2305f860491a929c30 |
|
BLAKE2b-256 | 4caa5c39268485efd42f7841f6145f07f86f5b0e740c484938d7a40a2a311416 |
Hashes for awslambdaric-2.1.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2fdc49af4861af6261663528bd3ee06f2452bff2a877828cb151c9918587a53 |
|
MD5 | 20773a05d3f945f07c5329d84310dd42 |
|
BLAKE2b-256 | d89038cea700796e8eb150d4407c6b156288f609a580c4d2cae2dd5960c02670 |
Hashes for awslambdaric-2.1.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b56c8c3cb5e3c0ccc81c164f12c9cb618935b9cdea0c0bb1bd63d10fb755c134 |
|
MD5 | 6e72f4294ffa098e0cf6dd3ab76b4f93 |
|
BLAKE2b-256 | 823cbb8728ad4a10a224a8adeda4cf4bfd757386f4fc2e3a27b3d39ee96f8dca |
Hashes for awslambdaric-2.1.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2de4ed7393714a586c6c6146e500f95f9a5e17c6596698cb01d17a75e8fe9024 |
|
MD5 | bbe3b49584a9b64626f88ac1de2ba9ee |
|
BLAKE2b-256 | a5c6e52b9c4d863558bef4ec24ed3abce973e90f5f9a4b8d732859238c89b8b0 |
Hashes for awslambdaric-2.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 941306da5f927fa77b361ff002fb893715f97e37e2533c7670b7040c2a51d235 |
|
MD5 | 3a67925388d8b6706e31a1ca67345a6f |
|
BLAKE2b-256 | cd7019ecf549fe84d4f38131cfda4fc1f61cf26d5e7f8b4ad5c5edef8c8eaab7 |
Hashes for awslambdaric-2.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad50f351a056596f42409b36d10cb7fdcbc8eda87c469c751c4b5ed5bb2c3998 |
|
MD5 | f5febd3c352ec15458a4abbe20a222d1 |
|
BLAKE2b-256 | 172789051a670ca65d4523a72e9bd47982bdb9b6fce4fbfd11dd5abd99a95b00 |
Hashes for awslambdaric-2.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ea2a3a229ebfbe57b3a07a8a4bba435903f2e6e99a126e39fb9e1981d5fbcf2 |
|
MD5 | 6572a8e335a68020039ac0a18af5282f |
|
BLAKE2b-256 | 4d717af889d6a8a67f15544114be4295c24d2ce46a0cb3f730d5cb1c4ea90ace |
Hashes for awslambdaric-2.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43d502343bf58758cd42aece3fdd99b292c7f3262582880dab6c643f616a7d76 |
|
MD5 | 76fa858f4964b0aaf98713438fed4cef |
|
BLAKE2b-256 | 703204efd5b4bf3f5fb0d875b023fc76e5509f7dda14019d85d3f2f05692bf54 |
Hashes for awslambdaric-2.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca1e754bca40726bd58d0bfe18318a109adce0e74cd0c5d4402c294728a480d9 |
|
MD5 | 00397b5868945c5efe7b8a664b8538f4 |
|
BLAKE2b-256 | 5bd124e6a867f8174420f72f86e8aab233d0ce0dd103e63b713a9af18299ac48 |
Hashes for awslambdaric-2.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50646708b170b6e6d350d4cd8ace91bcad2574bf1c96e9b8a234ee2791bcd754 |
|
MD5 | 2efb4f3f5ec0dc1693d33397f6000dd9 |
|
BLAKE2b-256 | 3280fed863c84353c82f362d9681037aaef2055c3868d723449dc46fe8324e80 |
Hashes for awslambdaric-2.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0402b22d630d1c3fa474a7a0cc78712596569e437f67ce77b1bfc90e0783f74f |
|
MD5 | 23fe32e33e6b38cf20b84500a67b11f4 |
|
BLAKE2b-256 | a29939f19b8ead20c6cb83c3edfca4c3f7f0a43291b77b22b9c462ce6c50e9e5 |
Hashes for awslambdaric-2.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50a565fa87fa9bdee29926e382bb82db036a4594a9849d5ca3bd86227d8a8c7f |
|
MD5 | ff747a830cfdcc60f5cc5110f5ac51ec |
|
BLAKE2b-256 | 89c2310ecf7a060e2083bcbb04fdbfc9405aae034ffcfb079d6578e5496819e2 |
Hashes for awslambdaric-2.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 250e97dd72b44a8cbe5b9b8e3ea5ed05511722b1344bed7674c7b8430886e22e |
|
MD5 | 228eb9e00a85a4c3bf114138b58f3ebd |
|
BLAKE2b-256 | 41037b0509d38adf492f2303811c82e6a5dffe13880e23ab9a9957858b02cd0a |
Hashes for awslambdaric-2.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbff96851aad6ae5bc80e00da9fbcaa5d49e82f1dfaac70b2af8fb755976043f |
|
MD5 | 777746b151cdb0b2821df40f97246c0a |
|
BLAKE2b-256 | 6f9e3a3cb365ef086f0c84f223f5a5392b83077db7d1100451cbae29591dcdce |
Hashes for awslambdaric-2.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bd2f6164ac07fe54474dff5154671975ea30ef87f5a2b690e568514f0ce213c |
|
MD5 | 83f60be69cab386fff8872eeffd19392 |
|
BLAKE2b-256 | 8355a779a99f4de6d54f8253589283904b989bf6d440d7b2b665c90ad6fa85a7 |
Hashes for awslambdaric-2.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8548dbbb3c6aaf8f4a7297598b64dc22d4e5da9bc2c8ec93185c583191533b96 |
|
MD5 | 0a4334262506aba3756405753143038a |
|
BLAKE2b-256 | 81402031ba9804391594ffa6fa5a496759ffd618caab770650aac0565eb5abc8 |
Hashes for awslambdaric-2.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0612e79b99bdad05f8fc98e4b0d712c2ce0d38ddd79e479cdd3321d2eec9271 |
|
MD5 | 5055a21f90599bdbbd367b2cfaab05c5 |
|
BLAKE2b-256 | b4c766040166a799d9dcb4e4c6bd3ec8b450b9ac021a4381d7d65358db9b1165 |
Hashes for awslambdaric-2.1.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c1385a01c2a59c14c2b72163fb5aacc303e69eac46b3900c944d627ef7fa6c1 |
|
MD5 | 37e68919fbb55fec939e9d12bde290eb |
|
BLAKE2b-256 | 9ff7a610d1e2a9b421da97988beb9c20d1e9751f2e3ae0c2e61cc90d615d4782 |