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.7.x up to and including 3.9.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

  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-2.0.4.tar.gz (4.4 MB view details)

Uploaded Source

Built Distributions

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

awslambdaric-2.0.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264.5 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.4-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (260.6 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264.5 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.4-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (260.6 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.4-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264.6 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.4-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (260.7 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (339.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

awslambdaric-2.0.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (336.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

awslambdaric-2.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (338.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

awslambdaric-2.0.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (335.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

awslambdaric-2.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (338.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

awslambdaric-2.0.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (335.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

awslambdaric-2.0.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (338.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

awslambdaric-2.0.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (335.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

awslambdaric-2.0.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (339.1 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (336.4 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (338.2 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.4-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (335.6 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ ARM64

File details

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

File metadata

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

File hashes

Hashes for awslambdaric-2.0.4.tar.gz
Algorithm Hash digest
SHA256 dad646f566aa7ec9b7179f16ca6741a2bea148abec6ed5947f86d00607e0a9a2
MD5 79715ea1b6c7774caa13b4521c5ace09
BLAKE2b-256 c9c1c851767acd173512fe6089445b3a611283932961ace5dc8fdc337c440538

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2efff2292fc8f8484eb094ffd77808a67815353be898a7f0b33ce51b841af691
MD5 d5bc9939b3289ae81b3c391cc11976d5
BLAKE2b-256 e8975417b5532a6eb889116c00b4e3e38a447e9360cbf96083b8eb13898b1abe

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 19da28e8c892b1c52a9db4d2b986af303932e3a4c4632eb0c5d5eb6a673c6022
MD5 76c042d96acc45756828881210a45bdb
BLAKE2b-256 f99ba296b54126aad69e20ff2745b49b2ee71eb23c81fbc8c471e4328ade29cc

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fbbd24446ce2f876335b178f04aa4ec7ec480afc0f9621ebfdd5f55ad4b7c06e
MD5 9a6a828bb499a4e1d58d358479a63688
BLAKE2b-256 81d5ff829f7c2e1a5ab3c46654cc61f98e8ac46a9170c39e498510b674fbb6b9

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9b0781bd41c20a2f2a0b018464a1daa376f663bd5eb7b0b6ba78f483681b1519
MD5 c84e8d34883c02060efb4666de3a93f6
BLAKE2b-256 e858afd6308ca23b699f93f0f0cea66ac47b8ab6faf3e6e18658ce4320281ca8

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3fd0e1b3891987fa7ebb0c08d24c76af5fc17466f6efdfa9a59848dfb23930ec
MD5 3b66f46e6b4f15aa380a1de67a4e249b
BLAKE2b-256 5d00879b6e24f367c3e3c795b6ee5bf9858048aea0fabb6a4b8d867756f1d1d3

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 059c7a66d4470169e01620d93f07424b80d302e3736cd11e68373f293a41e396
MD5 526360cac3e3739ccd00d82fd98b7ea5
BLAKE2b-256 1ca8497e6232f464592da95fbd06878dce22539c405404fbf1f835f260f891bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fe76893a1b42bcee4c91c6456092d2a42455818756e8f62d50e8c5adb22fa9e7
MD5 0e71b58a4ca2c7250a3a4ef1f7696752
BLAKE2b-256 e92932d47904227738b30181bc352d95eb2add3a1fd9a85288b4ad44b0ac3b09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 11a365164efec105aa670259dfe473d9609da8f6f2e468790b2dfc24969bfff1
MD5 e33488d39c85b1ce6552c45f5d39d566
BLAKE2b-256 2815411096f1ab3c9960378621683bc34c1595d4eb90ff8b22716d900adcf2f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bad98f2f94cecc90b89ac4e1d4feed96eb664e13c29b7ce232444cc9358e0d36
MD5 c71590028393a89f902e3b40458fc98e
BLAKE2b-256 2ba430e4327d01b37b4e654a6dd92c0553060fc7393914967aa7a4f3c0e38cb0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0e90053614f0e5e5d6d6ae6d164412ce95b5d549c6fb0f6ff4290d77c5e9d3e5
MD5 2446c416dd933bb663be7204d7f5f0aa
BLAKE2b-256 509fec1dddff0b7921986fb7101dcab0f24824c4201a45eee09327d1ce89a2de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 63a82d21d66146b3fde7eb6086abd058b75bdcab4a02b02afe0e8e4a45edfb5b
MD5 f289c06f916e54107af70f253f19987b
BLAKE2b-256 0f88f85ef7eb0f160d868181d07e85e221a52d4e12555140c80faf2a0e2f57f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 387b94cb0358662ae2b203f0aa2af25e80c6a2019a6b569f733ecd993a4f53d2
MD5 276442ab11727b53b9646cba9d00e268
BLAKE2b-256 c8281bf3df80a80e131a9f73a7ed2d51651bc9d3ad1c5e33ae7e42096b5c3079

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 38f8ae67ecb5b4e9f7fc42746ee39765dd7ddab359cb7e8ebfda1de0f0c0b059
MD5 df8cbdc3e82c45bd3b28b88702b32fb1
BLAKE2b-256 22d23ba66ee62bb90de2cbb5a3dd5bdd0b2af62bcf561ab4be1447248bb5a514

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d8f280b25d8a7ae6b6ff92a9bbc6567b984264be8ef3e0fcb0402a1247f6c75d
MD5 99725ef882ce1c21a29d71ffe72b503e
BLAKE2b-256 58e93c88e48acf2775647053c879d42d41191c5a389c37d336a413b7e92605ad

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 676a741ad8f3aa27d651bcf3a2b83d5cee815f99c8b2b9abef3cb22ca7b29698
MD5 704d9b5840b1603521402488da27feac
BLAKE2b-256 b9840136e863769ea07e29cdd601e40fd8f48fa23f561d5f7ffbe16a9f0633b6

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dc7072f642fdd215387d4921bbd5ac91b96a4a705bce5e7853622d09fe59f57d
MD5 c41a0fa51c4a2174a2225e754edb59fc
BLAKE2b-256 590d4bb10d94ce10e82b0a15cf1fc4fee2e2b94fe270805ab4103aa789587328

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d64dcba8da9dbea62644133a48c75376a37bfe0f84096ad73bf7fc5b2eb31fc7
MD5 bbf91d9c84f9f6b9e9d4ba9b267d75cf
BLAKE2b-256 70cd7070201d98bdfbc3ab8d9863891fbc8a9d97586c53d51a4dc99acc97930a

See more details on using hashes here.

File details

Details for the file awslambdaric-2.0.4-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-2.0.4-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2eb2fdb1ae0f84669d37f193f247fa115a282a7777e051ced3a33620d6280646
MD5 84bbe572dcb5899b268c15ecad4efe1b
BLAKE2b-256 603ee4924f317280335bf36f778f13dfe63c4e1342b1f5f2b095188db6413c1a

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