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.9.x up to and including 3.13.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
- 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
File details
Details for the file awslambdaric-3.0.0.tar.gz
.
File metadata
- Download URL: awslambdaric-3.0.0.tar.gz
- Upload date:
- Size: 4.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f42161dd92b559d08f2ebd9e442a905d9bfa7c6f66896b9fd1395aa6f061f6a6 |
|
MD5 | 07cfe5cefd11ebb4bd3cf168c9a1e5dc |
|
BLAKE2b-256 | d698d6391c3cb5b511addaca1ad980f34708b9913fab64e3cb6496548b1244b3 |
File details
Details for the file awslambdaric-3.0.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 268.8 kB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d1885aa91605bfe83d906855d6f3d7518279a6e5e5071f2c8bbe7486facb6ba |
|
MD5 | af0b254614d9641c7108f1cf0a0f3178 |
|
BLAKE2b-256 | 93615fa63163828a42606c3f7ca20b74fac98c14ef41a0463054643ce24437f7 |
File details
Details for the file awslambdaric-3.0.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 264.9 kB
- Tags: PyPy, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 558c25798c957d803416c0a1d2debf2042d2a59f35089bf255cce791406b9cd3 |
|
MD5 | 35a16113adffa25551c9cae6d990f2be |
|
BLAKE2b-256 | 0261b7994293b59cfcbc359e598e6c0c07f325196fbdf7049c11e4f7f63cda48 |
File details
Details for the file awslambdaric-3.0.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 344.6 kB
- Tags: CPython 3.13t, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7162bc6c0c2386b3ba41be8e537da75d4073763ce3d6f11e16cedd8f7ea95a0 |
|
MD5 | 0da3ec90de635c67b08d31c684c2935c |
|
BLAKE2b-256 | b0b484a273abefe911b4e9150a8233c2b0ec792615c4a9ca95e1d06a4bc53688 |
File details
Details for the file awslambdaric-3.0.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 341.9 kB
- Tags: CPython 3.13t, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36e079998bf44d2590616901d7cf9c89f33302ef6fe22270d76be89822d0d71f |
|
MD5 | 4ee81868dfd067fabbfa4bb6fedaa3b9 |
|
BLAKE2b-256 | c2623a9643906ad723342d89e5b7a813cf4b0ccdd588b69b8dab4c5607ff6f90 |
File details
Details for the file awslambdaric-3.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 343.4 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1b3e5932aead24171f64b460045966c46570db51ff18efc02337dcca196e9bf |
|
MD5 | 57c30e29a1f74f85ce8aac9e3403b9f6 |
|
BLAKE2b-256 | 45fccfe397c6ebb982bae56f77bcd1cc134fc7cf2e9864ab85a3c0fec108c182 |
File details
Details for the file awslambdaric-3.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 340.6 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2309ba2405fb8e3927f7fd97a6ef9087fb843e2ec0ecf56b6f9aa2626c26c8d |
|
MD5 | 56621eef498d8c7009c2ceef27e38f09 |
|
BLAKE2b-256 | 34f991839bc66654662011ff980e8aaeffc0ae54c587dec67fcb31756ceaf95b |
File details
Details for the file awslambdaric-3.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 343.4 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74d522da1afd513ebf0d068b3f14554d13fa3e2aadaa57dfedee9b7f849c2894 |
|
MD5 | 7f4ba4240f4183e9971fca38cfb03051 |
|
BLAKE2b-256 | d8ee6907715d123215ad7ff906956f0d1bf5c7edd12c170e56dcdeafacc2e88d |
File details
Details for the file awslambdaric-3.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 340.6 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a328c39d6d26180273e9b6e178999aab195623b39d4885b15f69b31107a62f6 |
|
MD5 | 0fc1c4cc0b4291877fb467dd4a7ee631 |
|
BLAKE2b-256 | f6d8d19837eb65ba730d2ec372ef74cc6dc835d1cbe90ccecbdca409694939ee |
File details
Details for the file awslambdaric-3.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 343.5 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 554049c4492658720230e3e60c9c691974397d21f81d77db398b1b00f32bcba3 |
|
MD5 | 346da6fb9e2864d2930d22c4f0eb11be |
|
BLAKE2b-256 | 21ff936f77d0f6c6b6c41893c1d884fa09f18b0cc6bd63d34f39c7b847f0a62e |
File details
Details for the file awslambdaric-3.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 340.9 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ab2703a20b9db1ae4e2557434158f007b1b12c43ebc628edb0111a9a4c47610 |
|
MD5 | 550c2dc99bcac00223a837e79588714b |
|
BLAKE2b-256 | d2364c16ea35f8d6809a180d78f5f0ebd5d60432d73bb6cef57573f76554af29 |
File details
Details for the file awslambdaric-3.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 342.8 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cfcfa951676538e1069d449ffb7dea31702caffe88a6b6c8c5dace82a92fbf6 |
|
MD5 | 1d96bcacbaf19515220487a53619fbae |
|
BLAKE2b-256 | a39ab44fc7761790dad3a956c5d1799576ce428cec45afc732d8524e1464fe20 |
File details
Details for the file awslambdaric-3.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 340.2 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa8a141c03fac6bc2a8f4b6381fb5ed5e788ccabac24b03c77cbd1cb5f5cfb8f |
|
MD5 | 78dc9f4a628e8cbb533d786594586d52 |
|
BLAKE2b-256 | 82108c25c89b02272bc455f7583cfbef95b613b2aec4ef3c2f360b7731d9977f |
File details
Details for the file awslambdaric-3.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 342.6 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a57f5f961b5d0c4cd1d71cc238a058bebfbac66c48e1c6ec152a508d2eb8f2d7 |
|
MD5 | 27ab7f55b6eabde1fb789da25966339f |
|
BLAKE2b-256 | e2e43cae1247d07d14092b38370b6c5207648495c7700c79d08c223cc0260e82 |
File details
Details for the file awslambdaric-3.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: awslambdaric-3.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 340.1 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3cafc8972d78b631687d546b300527e22877fb7817f2bf7a62d01ef9d0bcd11 |
|
MD5 | dfb4fe7c27f6da0999b01b867f8015d8 |
|
BLAKE2b-256 | 7ff297d41ca25a8d583d305cfc69893f64f84256b2352438671b40d9741be046 |