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.6.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 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 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.2.tar.gz (8.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-2.0.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (579.5 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (573.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (579.5 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (573.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (580.4 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.2-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (573.9 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (335.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

awslambdaric-2.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (332.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

awslambdaric-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (335.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

awslambdaric-2.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (332.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

awslambdaric-2.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (335.1 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

awslambdaric-2.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (332.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

awslambdaric-2.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (335.8 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (333.2 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (334.9 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.2-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (332.3 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ ARM64

File details

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

File metadata

  • Download URL: awslambdaric-2.0.2.tar.gz
  • Upload date:
  • Size: 8.5 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.2.tar.gz
Algorithm Hash digest
SHA256 f3569a7189a86a4e46c76ba26d893cbe602715138a6321396ba02b48ef6caaec
MD5 7de88932600f2e779d8674d795116e14
BLAKE2b-256 7949e65c86a183efba9c003ffa1d457b32be9c2ef716e161c99315f6b3368b29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0280beaf14be870ebf0f076d49b0eaf59d50dbf6e9620fc45ff5323d4d6b4a63
MD5 fb9659d51c617410110d9ad668f366f1
BLAKE2b-256 a470deb92f7a32925513ef03b9232c8b13474983390568b3f5bcbf5db6c4e94d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bf738ad8a57c60c13fe58b1fa979b54a2ee6eb160d72cc2e72d795190c0b72ab
MD5 c3320295c406a40a8b79c1809cceb0db
BLAKE2b-256 f9f8307550eb9314dd7acdd1055d7deecb3ca5b045f617a0faf5724830c4c734

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bbb7d5cc5275c081585525d425180262f9b2e9a2d53b275992e2a31c4694ac39
MD5 fdbaee577021a328b503305d9400e34d
BLAKE2b-256 187fc61850fc4e7a4d1437ce1fceb5643dcec241cffe50d7825e8041fc131004

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6fe197ae9aae969ed05fd8b5c21e60b200a029774c697ec3764051a9aaef5124
MD5 f6c9ea89c57ec2da908c932eff7fe7b7
BLAKE2b-256 e4c412cb19939e296e43411bdd20cafbaf2d8d2ef64bd9528bab665410b0d7e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae4f2c6bac39e6ed85a1c0fae65e2a9645082a898e34c61dee768a6b54f6282c
MD5 24939d7ffa70c38687db96ceea0bc263
BLAKE2b-256 fce46709206d6e3b63fd6e48c1d8485725a38672507f253ca1c9653f161492c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2baf9f2801d8bac69b24adfac7a876eb5351eb64eaba2a1f6bb9d3e9d29b2d04
MD5 6b0e4a1ff19a6ae06dcf1411ffdd3a49
BLAKE2b-256 69ac06765c67c280c89c730c8e11907f00e554e310ae6bd9473ba05ba006ff00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d01a9fb72782eb5c13ec15e8c815965cba9ce4f5af5ce4ab9542845ddf11f1ec
MD5 ba347590413900e69ed75b4c870680cc
BLAKE2b-256 242d588303c648702bf3ad1e1fb19610df69e14f2489d0cdc6b41df6563c4bbe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 690751d58ef3bb09646831f26c971328cabcecb34448d0db22f2094d9d2ef64b
MD5 d53f98de00e671de857dc02affefcfb8
BLAKE2b-256 5db4b843f6d81694f1279565047d78dd76dded4d1c1885a4ba9c9a80928dc64c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 74adea60af926c205ce034ceabf2338acbd5ec9544753b64e8c1a6790838d630
MD5 2ac1735eb94d108bf50e6f1853e2bfd0
BLAKE2b-256 817a2fe3f780cbdf35c66c913c95016671fcb607f46d704c5c7c4d1584f9433b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b17a01399948a529438f5bc81603b81649e7f9f8bdd4017cbe7f6c123a77ec5a
MD5 6767d05121f0da7fa0a2877fd53e7f57
BLAKE2b-256 59ec1d914b466e4eb850cf28eb17256d1077ab32708946efd6120792583b7706

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d1614adf9ddaa92ace3999b1d9d0996a26744be4ac2ab77aae79cd473c73adc8
MD5 ea3cf0e2419f275812b1c92a42614fb7
BLAKE2b-256 f9af0cdf581dea7958310310466e094fcb242d4beeb02db4872359fcb30c8cf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e8261822ca59fc403dcd68b7f62df752d5ef3f6d787f908e5afc6ac24cfb9b6d
MD5 93c417541ae486a043196180afdd475e
BLAKE2b-256 7591cac4f96951e8c708feb2961f1eb12c19db708da8e61d6c9733725073c37c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9119e11e1ee420aaf0176dfbcb46ddfec4bee7b0a36f7fc4b87bb6ba7dfc7aca
MD5 a6b6d4117922bed03063e33da69bef98
BLAKE2b-256 6af2ca3b510b890ff52de8cc97f5f2e588e87a1035ff8ac49885c6cc35324851

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 40bd5d3941f427156f84112c2447c6eff5eede15f2bff41fd66edb7d49f33ae4
MD5 e9d8d8247a61b843e7822d87db91b3d8
BLAKE2b-256 5ba92e3811bf74468e0bf95c2c8a868ab952e750ed8069ae22493afa0db47f95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f2cb9fe7fcce00ffd0279252a9c00d7515f8234409f3cd79bccb4b6ce8c5e2e
MD5 5db933104b2332f3385095803d117c86
BLAKE2b-256 b4ee56fbd5a092063abc86004945e55f1c25d117a005efb251f499acc2121614

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.2-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bb2147070b75217658786ba0a024201b99414ea1f9dfb6be5c30725b5e31d386
MD5 fb941fadc5960f103b294e3eef7beed2
BLAKE2b-256 2e90ea1dffe66a99419d9b9253ea23b144b70e5404c7cc87e9b46ba3c5a498e9

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