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.3.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.3-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.3-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (260.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.3-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.3-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (260.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.3-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.3-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (260.4 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (338.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

awslambdaric-2.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (335.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

awslambdaric-2.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (338.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

awslambdaric-2.0.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (335.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

awslambdaric-2.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (338.1 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

awslambdaric-2.0.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (335.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

awslambdaric-2.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (338.8 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (336.1 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ ARM64

awslambdaric-2.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (337.9 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

awslambdaric-2.0.3-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (335.3 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ ARM64

File details

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

File metadata

  • Download URL: awslambdaric-2.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 5e72d33f523798f15fe3d92f99fa617ba85305e39e858506a254d9107ed05f83
MD5 36dafe3ff23d2e818bfc40c35222dad5
BLAKE2b-256 ac78d6d33edc5b44279f8ad7b5f5c868f8b69bc5d1600c9287e41ef68064e1d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7d291c3efb7e96860f96187f54def77bc03ae3902333f34738807a56f75ff6a1
MD5 fe2564868d1d6ae8d8fb8dec17b57fc1
BLAKE2b-256 fa8675b7c0dd4d6d85fe8e97891a09e63bd53a062bf6a95d7174eb1092d3550f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1febf7f487dfee5eb485141855f00416e434ea4a774a2c522ddeb32e0e1b0e14
MD5 68eef53de9f034460cda1e31b33e402e
BLAKE2b-256 d54885349b707c1e894f22185c1c88c77ed75cb7f963f466731229a5c378a3cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29f46a7a3aacc8d4b3904899344f2c9d7a0c4ecf06b3cb998d8f4b210cd3e012
MD5 ba4a646c9b7278a8b68bdb49337bd49f
BLAKE2b-256 9562973d25bf015d7d58616a5e13083caa8359287dbb77389dca3e0bb58c35f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 019b291f240acfc36758beae0c2cbc7b88ce8e746b6fb1f180f346a28ec9a014
MD5 490b17789fde85495e0cae7ea0119726
BLAKE2b-256 428ac4d13d84343f0b7220c3841476a84661e7931151cee77c1843a747f452d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a56f514cdf13d5f6b59157904c86babd48f01e418dfd3e59039d47484630b2e1
MD5 44816d648633749c647dc3aaafa55fb0
BLAKE2b-256 3f6935471ddbb87621eff388f2bfc93ea1f816103a1b58fb699982b813bf67fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8b7989ac907436509686ccd3267d8d0a5557153ef646fd3fd9186564e3c75c4e
MD5 e8a5aa05dc1dc17942b1f6dc28686e47
BLAKE2b-256 7637fa6420940f6f15a449242e2b1d8e3426cc8ee1a597c636741bc916aa949d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f45198b67203f05f3bfa1265a1ab31c299513aa296195b21b8a74664af513d1
MD5 f06fcf5ac5439ef051edbd272bb4ec39
BLAKE2b-256 b223b127e7d36de855ec709029590bf4458273500ff5098bf56511ea517db831

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0ddb9aa89020a4a9e49b74515f0a951c82131333ee1fb949225a588fc2ddbd1f
MD5 cb0fc5af39da6c279b29aaf0fc61ebc0
BLAKE2b-256 63719d73c842180f1819fdbbdb673fc0f6f0f4c74869d193e0208ba58a5a873f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 80c559e7bf90d3b5edc47d09aa2051cc326b4e3e429d571ceda5c380a606ad04
MD5 018cefc941fd34b29f3443dfc79f435e
BLAKE2b-256 1ecefb4196801842934bebb7488f2f696ad3eddc6c04efbed770ae2d8a094e0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ea333117b18bbdd50860952494d405e3e2bb7fc12502730cb206e9403fd5d485
MD5 5c991b9d60514ac6a533ebfbf8cd7f7e
BLAKE2b-256 b9a444cadb0f0c7a6c2028655de18fad6fe5ec76a3e39d6a3a0930450c5d9fef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a76707533ef08be7caa7bf11311ba1e90a5fa6708768fbb327a4b2a6f8cef568
MD5 010f44c484cf2b941f5c05d459f0db47
BLAKE2b-256 85b9762f17710e8bb6a6c3c2afe65b8ac99b83c1cd01134ac1ba5ffdd87ec890

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e9c339128fde1f15a7b4ecef0e34e985419015d99f4568c430753f0cc6a28dab
MD5 f352fb8401865e1ec68495102d19ee23
BLAKE2b-256 63102f6f10364dd63a87d07e39942471b6f1ca43ba80eb5d01fd3414e81f8e76

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d7b9add8fdedbf8680a527af38703df75295f27103c93aeb01c5ce8544720c6c
MD5 8524323f802bcb715a00e4be1cb1350a
BLAKE2b-256 e3b0e3216ea5faa7513cd48831bc58cc55b4f29f579cf867602569332a63ee85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 49570c0c13492913fac1357d82fdae6063d08ce03e963ac210ff9b6cdcfed92e
MD5 5646ef19a36bedbee0ec4955cd0aedd8
BLAKE2b-256 6bc8be2a95692f9fe3c5a03bf88db5a088991b818647492ef5da0e7375227c7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6480c085b7a5be24675dbe6ef1123fc1928be3e8293c56ee4e2ebe9312e33bbd
MD5 f956c5a1667e678504a03ac7c89e27fa
BLAKE2b-256 3d399c55b5e5838df79b1291c2f8f20ecfdc54e0b2ec3724a182cf5384d3cc27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-2.0.3-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7607a2530a49615750e83f4eccc71e6e77000336fe1c367d526fbf5e04c8c6ff
MD5 f588bbc4234081411c0679fff0c6fbc1
BLAKE2b-256 3f5ab19f180a04d4dd9f2db8702602c5f23b8d39b78e89af5073b354240c82c1

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