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-4.0.0.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-4.0.0-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (271.4 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-4.0.0-pp311-pypy311_pp73-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (267.6 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-4.0.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (349.6 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

awslambdaric-4.0.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (347.4 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

awslambdaric-4.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (348.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (345.7 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

awslambdaric-4.0.0-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (349.5 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

awslambdaric-4.0.0-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (347.3 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ARM64

awslambdaric-4.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (348.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (345.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

awslambdaric-4.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (348.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (345.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

awslambdaric-4.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (348.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (345.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

awslambdaric-4.0.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (347.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (345.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

awslambdaric-4.0.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (347.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.0-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (344.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

File details

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

File metadata

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

File hashes

Hashes for awslambdaric-4.0.0.tar.gz
Algorithm Hash digest
SHA256 779d0721e60239233aec572fe336d147d1c3c4e405f7e56be7548b4dfececb35
MD5 bdcc8684e2c2709817ea592bd7115381
BLAKE2b-256 98cf0493b0098ce2b1bcf30aaee72dcac43cd778e9cb45fe26626be5a75d8b91

See more details on using hashes here.

File details

Details for the file awslambdaric-4.0.0-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-4.0.0-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 3a5bd1b99dd982c9bcd12b9f1b6b2a6d2265de92e6cd24c61d752c7ddf64ba13
MD5 e93ac418514d62fd78796f3e6161b2bb
BLAKE2b-256 fbd0cebd4bb2c6097d9dc42d3054e82136337f5b7551e7cc1819363cb48b352e

See more details on using hashes here.

File details

Details for the file awslambdaric-4.0.0-pp311-pypy311_pp73-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-4.0.0-pp311-pypy311_pp73-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 2567e2120595cf6ebcc0b5b218066954df657b1fd85bff6aad3e7e0a542ce399
MD5 ec029af949680cb1a0bcb1f551be025f
BLAKE2b-256 a930d8a2bf0eac750cca046b8da597c0457f92374145abc4b1cc423080452bc7

See more details on using hashes here.

File details

Details for the file awslambdaric-4.0.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 0fcfd06b622f08316386ca23bfae7aa85189343a77548ca9124124a4e0625f20
MD5 885f4efe7fd8fbd23fa8704397bf4d54
BLAKE2b-256 916a0a99b7912e458f2bfcbc312053c2fe3c08600a77d6f1e12f25869663c62b

See more details on using hashes here.

File details

Details for the file awslambdaric-4.0.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 ae135112ae2b29b1beaee9289383ec15f3286cd0fee6047414362da3bece0faf
MD5 d24ddf4439d329d19beca5b1bfd0bd5a
BLAKE2b-256 670d882c91a2e13655b86fd3ae955887a0464c83e8d579fced1c6b1c36f39f93

See more details on using hashes here.

File details

Details for the file awslambdaric-4.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 64c161247f3c6957a271d8be46d85742eaab9804d76c235afc61de7942bc801e
MD5 d550785643c875b1761f1b30786fa79d
BLAKE2b-256 4c85706cbd24866149ed8fe2aab6b12201e2ec0c198b4a7584435e844a234a7b

See more details on using hashes here.

File details

Details for the file awslambdaric-4.0.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 55070856326c805b8d1aff6957cb8357f280bafac13c0bc6efdb4be65d251a58
MD5 b1b2d3708b1b31652d6de4ff16ec0f15
BLAKE2b-256 9fc848a1d0bf86d5ac5e2cfb577b549a8bb9156a87e83e1ba84f38f8b1c6021e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 7687637d074e5ad57e5d23305c6acfad2d63e55062f627e4d4888762effe43b0
MD5 b3ca6b4f7a92463a70b9085476188d7f
BLAKE2b-256 67bdf405316fae2651269ef639f1ae52df4128030932daca543904a8d04e28e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 8b9f6d5a33bfb2abf2bd755e9921dc4affad83b512da8653ada65e8defcb04c4
MD5 654e817c10521cae93e5faeddc7d7db9
BLAKE2b-256 fbcc578f27e11233fd35bf37dc60d6a7b952ad25984a72b4db8ec13ba1123c75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 1833a7af1c3494d266c21133aa4e9bb5e3c7408af6ac7675986f70ff2fad0d90
MD5 41774b1a508ee8222dc3fd644633c48e
BLAKE2b-256 5373543b45e29ea4fa2be0cbbc8e834a2a02480f9f952fc18068d138da7d36f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 e1660334f5f713e8880924bfce14c52767c0767f9462885ca469427a1df2f15d
MD5 60034bc19f9ecbae842ddfcc3cdbb975
BLAKE2b-256 8ac390a46ddc41a481f13a534f5fd30356fb7edc9273bca89386c75fb9662847

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 7272bdd5fb5b8c909b9bc8c7ddd78b2f605b869a789edf434ed211d10f2d47bb
MD5 f600802371e958db989ac3b73ca0d471
BLAKE2b-256 19195effc5dd44bb55a6fe9208ae91330576e6c3107f37bec48da190e316eaa3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 55d157823685708204f325dd8c561176d70718ad95d7a5ac85f18d6f3de20a77
MD5 d2e1312db21247fff13fe2d400378104
BLAKE2b-256 9ae7298f32de8b28ec8eda85509ab3477dfcf5668734b7033d9767ba1b370bcc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 52be7a5c8a03671cc77fea9cb41eca3c90acf6b1e2f4106f1f8871213fae0f4f
MD5 cb305d91a9cd58ec7f7ad00e98f5eee0
BLAKE2b-256 f108f780c2943fa42e5efde9d897bae6bf9037594075ee380182ab810eae68af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 8f3fbc37f75f1ea7d1f3dd0a3f4aff9b373a989ed98dd9c7d9be0347a0b20b99
MD5 ecc23c13541842cb60b94c26375c333d
BLAKE2b-256 5e6228d3ae6b1d79f3bee09a2b0421d16a0fcad4f8971b047000044dfb0120ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 5ac494ef80e9552abfeda0cdab8483bb306514821c6809e5c20a9e958b79deb3
MD5 822bf3d8b6f03de75654bc629423e70c
BLAKE2b-256 3d1b641234c781501599fea85d8026c4de10af99a76e81cde54ff7875a4829f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 fb7c5b44db06cc6303c1851c992b99969ead5fe57e4427dfa766d54fdce2dc19
MD5 3fcfd7884c8d07d11110ac0da231fe2d
BLAKE2b-256 9e3ebfd2ba4a2f45a7fe26aa1e82fee4011c1693c1e036090edbf511c4d859bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 cc72ac23ef76c89db0ab7919a97ab235c8b2735714b40d1932cc3ecb876a9fe9
MD5 c30516a346867878d608174611dc5bf2
BLAKE2b-256 beddfcc0f0e235f820a73b1ac9d71c1ed5edd2997da6ae8b7c6bc960ff329bc8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.0-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 531ee2931465e078eeea1b7b91749064f07ceaef9161e9ebc9feaf24fcabe01b
MD5 56ddcdc6d60f6d4c8378bdb62e591fd9
BLAKE2b-256 50a6ce4d37258bf85c8b984533656b0432b7ca23177a96a190558b40e5ffdefb

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