Skip to main content

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

  1. 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
  1. 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.

  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

awslambdaric-3.0.1.tar.gz (4.5 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

awslambdaric-3.0.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (268.8 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-3.0.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (264.9 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-3.0.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (344.6 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

awslambdaric-3.0.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (341.9 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ARM64

awslambdaric-3.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (343.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (340.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

awslambdaric-3.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (343.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (340.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

awslambdaric-3.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (343.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (340.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

awslambdaric-3.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (342.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (340.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

awslambdaric-3.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (342.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (340.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

File details

Details for the file awslambdaric-3.0.1.tar.gz.

File metadata

  • Download URL: awslambdaric-3.0.1.tar.gz
  • Upload date:
  • Size: 4.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.17

File hashes

Hashes for awslambdaric-3.0.1.tar.gz
Algorithm Hash digest
SHA256 4e6f410910ee0192597ed8e51418b08d9664101bbec8b2e353c90d8d7cb6f187
MD5 2acd32d02cb36085a8fb7b9c87379239
BLAKE2b-256 5af51e889495c448dabe1d5a3f86d489d98a1df0e67148e90cda7c815089b99a

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5528adb31ac945b134862be1b43ca069e9a6c1a4217ebc4679d470d25a963d6e
MD5 be6f8160a9b6f54fba7ba0c1ed0b7671
BLAKE2b-256 e36f83fc3f86b2789adba206f1e9b5fe69f70ac627c3feaf16509615a3173920

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2afb4a844079d95e7f599f6cc9405c81e9336b577185120423d81c90140d5b6e
MD5 870cdc69411b1e464d96d626e9134128
BLAKE2b-256 0fcd7b740838bee85bb045db7486fefb218b838babac7c4acdf16c99cbbec165

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a272034cfb31d8319f9134bc0346455c9e55fe5b4feedc5c9b13adcd60f0801b
MD5 ee46df892a2f6bb7a3a79e936180fd63
BLAKE2b-256 faec11254eb0cb899cdc891e970ca4f9aa02355bd57d866fa12fac4b11705e8e

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5fd827088523cde08f1b0e6162c35719dc7a636943de688ae21ff180ed2ce9da
MD5 8a8d6fab65c51b896db6ae249ec6bdb8
BLAKE2b-256 b5e8051bd14c5c18d264c8f0b9286974ef4ce0e1b85d68ea97b965f6003ce644

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f305a4007966d2631eb5f0dce90f64c1a3a99d5bf9c64759313aed1e08c8dbb1
MD5 3eb4c275ff25ea33dffa7a17060d1ab9
BLAKE2b-256 52445b49ae5f70d6a813085a85022c09a46355c2750a3794f112042c86367f77

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 58d35a0ec0eaa97727f277394d9b36552224a9a0b92950ef522039515e92024f
MD5 1939c7fd1c043c56100c7154f84f31d3
BLAKE2b-256 376efd637704fdc05275419e068fd767847a0868aec6f4d0b3349c2b59c0308a

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d77abe0a305c2ec5c8c4a4b3f68350b29ce3fd9afa27d7673e77fc9f09daabd6
MD5 93cbf2ac26aac9b70e9564e6056140de
BLAKE2b-256 6226477ffba7a781affce719b653954858d2b931f6ea80e0484c0fca714df661

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bed154fcdbe06e55a33fc6ece7966116c05bcf03352a8aa0d705455311300e6c
MD5 c2f9a38a39e5538a6b5a50cca1d8eda9
BLAKE2b-256 7c0a992dee764cbd46a64d034aa7963fc497d5dcd8448e6c78c566749886fc22

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 912df3c384d02653321fc53fa1d88e801c345c37c150cf32b44fb51b858fcf6e
MD5 40441a44ff59e0bca6889e2c87ce8544
BLAKE2b-256 85541d743e4e4452c6d9be42275e2c41b884ee93ec3ce5512a96efdef8f47b08

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6b5028aa92d7e11448dc2cf5b36b1342a141a8f639308e2a6fa0b5ca4e9a6ff5
MD5 5aea5bbe1b1bf42754def49e43e6fc13
BLAKE2b-256 349c88f3f2298b6afc32981d5bf71d343e884cc4819d2fbfbf4a78c033da4e5f

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aeeffd959061954549f352fd33b46c6f26001f09116a3ab10355be908c3a2216
MD5 a37ce0e880600e6f7c1456937daeead4
BLAKE2b-256 166eff72981418a134a0d41ccc67e969ebedeb4acc6c72798fec3ca4ffd460db

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8999c3a3bb2f742fbdf05984076099bc82d4c2258bf0c10ed2401809a38f4d9f
MD5 15fa061a536f5baf2d508ecba94cd52f
BLAKE2b-256 bc5d6be39a1fb72c4bf893ed70af25527651477f50992b19a4ac530c6f6aae9e

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18854caba9847ffe5c35231d7e91ed5733317123982efcaba73e6f6e0bcfb17d
MD5 fabfac2de21c19015a3fe069b602bb48
BLAKE2b-256 7b0fb296359c5137d235488f62c341375ea9d849f37d6c01c854d112e647bf1f

See more details on using hashes here.

File details

Details for the file awslambdaric-3.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e42343507354d282f83d6f55272456ee66ba961870f2901752a9aac4f8ef6ff7
MD5 68b75e01f5309819f620ef0774b1a411
BLAKE2b-256 7ffb6752d53836c7ea7d2a296971d1be1df2141175983628369307b33cd90a76

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page