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

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-4.0.1-pp311-pypy311_pp73-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (268.0 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-4.0.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (351.3 kB view details)

Uploaded CPython 3.15tmanylinux: glibc 2.17+ x86-64

awslambdaric-4.0.1-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (348.2 kB view details)

Uploaded CPython 3.15tmanylinux: glibc 2.17+ ARM64

awslambdaric-4.0.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (350.0 kB view details)

Uploaded CPython 3.15manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.1-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (346.6 kB view details)

Uploaded CPython 3.15manylinux: glibc 2.17+ ARM64

awslambdaric-4.0.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (350.1 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

awslambdaric-4.0.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (347.8 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

awslambdaric-4.0.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (348.7 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (346.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

awslambdaric-4.0.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (348.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (345.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

awslambdaric-4.0.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (348.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (345.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

awslambdaric-4.0.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (348.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (346.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

awslambdaric-4.0.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (347.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (345.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

awslambdaric-4.0.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (347.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

awslambdaric-4.0.1-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (345.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

File details

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

File metadata

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

File hashes

Hashes for awslambdaric-4.0.1.tar.gz
Algorithm Hash digest
SHA256 6559779b59f39426026557f4bd8fa90fa4b3dcf5965d230362eb4a83ec4f81d2
MD5 f0f2857d0de7867d728dbe14d04e202d
BLAKE2b-256 8200cb7eb5d32b0fb04be9b09b512f8e2d4729dbf10cdea3e75f139fe405b7bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 07722eac2262e0da67af64776daa0070fdd1937008ed1f113ecce7e182759bb7
MD5 dab0a7d2863574d50341c7ee5e41422b
BLAKE2b-256 3400305e6f32bd9c018d81518ff23eefe36dd1d6ebdd1bbbfd82b2390ea22286

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-pp311-pypy311_pp73-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 ceec748feb53355cdd212a0014dd5ad637ecaf22eac92d994c36eea645cc5937
MD5 cebe53013c5234de0205131f2f2c9290
BLAKE2b-256 504ec3c74df992bde42b63d57e7de6a9f90b75a95323e8063ce8700659f8b419

See more details on using hashes here.

File details

Details for the file awslambdaric-4.0.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 908cc86c6395d20c7c85b93dfdb7bdc3db0dc84dd0c3a78ea4a209b7d6afebb7
MD5 1b095a57a98ec698a577ba8322822e7c
BLAKE2b-256 2d74e159dcd7ad1cf2548b5002172d08ada2e9d5b9ae35580014631cfc61e81b

See more details on using hashes here.

File details

Details for the file awslambdaric-4.0.1-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 d68546c0b09cfca12978af453be7e60bc713817b869139fb0b40f57462fd1790
MD5 ec20664b7b120c271c1d6a8aef4b8007
BLAKE2b-256 2d9d793358ccf85b68461e14dc2fb798bd61e6e9e03a34a75e4c5536b916c58f

See more details on using hashes here.

File details

Details for the file awslambdaric-4.0.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 60545730bace404c54933d3e990cbecc257b236bcb4ea742af38be3ba052c425
MD5 4d45847c7fcae279a30b3b34aaa05a4b
BLAKE2b-256 67d82aa3fa705677699510a3475dc4767f520119d0e50808feb7e4bdda260e80

See more details on using hashes here.

File details

Details for the file awslambdaric-4.0.1-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 b19e2472765f9db0c3c9ea6cdaa201fc3f361c15de98e41f7ef0908205aa8b5c
MD5 ffaeb5ff920a51aff66225fb4beb3310
BLAKE2b-256 624c79382868664511625db74dac424ce2939cfab50c12faa54b4d25092159ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 6bbacaa19a5e0ba097a524e14ba2b80023497ea839e0fdb3e8875e3b44817618
MD5 753f07151cb2cd12a49d4c2f579db8f5
BLAKE2b-256 ce4eb3214be854b71a877d3b88a75b37746ebd314cb70e099eb8bb9408ac1f65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 90aa1f1c1c58a67ca1b87d9f7dbedde73724b8546d18e1011c8fe74bb0ac1f43
MD5 ba356c025247e27b0d4279adfb2cc446
BLAKE2b-256 af65ccfc99586e3c1f9388dcb1b95951b8d6be016ee03cebb8a5c070d095b754

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 9e3e7418633a67a5648bed7e086e3733cdf03b8a16c2d5e52ee2a8f25bd9c943
MD5 b8cb5cd3ab1653f27afa5fe6d414fcd7
BLAKE2b-256 cc408475d594bd73acbed8effbc040cd1516234d17717d53adb41f57d0e502c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 0ba8f9827add7b2fa6821697ddd83a2170fb584226981f82641a2b62b302bdbc
MD5 f905da497c8f5a40e7cb314883c4e908
BLAKE2b-256 6bb7f3e77510de900d587134fa8757c5efec27ce79f3427dafb1766110c03617

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 fe88e8677dbef80d9f78287d58c726ea84659040b92fcbcf071efda8f97c9036
MD5 59c6bdf7640a8dde5a9ab7947dd7509d
BLAKE2b-256 3c2d0bb5330c1b8f5bd111d24edfa8f86003814cb5b3798a6cd7fec07a780587

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 333c108954480df0f0019d6b78b41624d2fbc8f806b223e619dda759f2e9da1b
MD5 c9fbb244c2ee6b50738b184876f0f33a
BLAKE2b-256 6f9e29a61c2b5cf797a1208dd8d0aaf398aaf7ac370bbe63a700ae236a479a7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 9ee8329fb5e08399fb89531eae729d750b687c67acad03489c8798a571d5869b
MD5 62c69ead6a7bbf1092ad95e80a33aa6d
BLAKE2b-256 f2c6b6644ed1cba744c4183d5e2fc0c376b20e9166fdcbf5f081dccff882a4af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 0445e74f5ca1356f92a861cee55d539d3d976569524c8a5bf1e6718c24a70ff6
MD5 957447c3bb9e2f57c563f685d8f9e5cf
BLAKE2b-256 7f2ba5e6c2ca4795e8fbc00ed1471910b1cdd441af1233c3a466299ce79be550

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 bb077859e4b2a1f2eb63a0585919e323ad96580d5068c4446c1dfa93c8b7584f
MD5 0b88826046216937f28d16a614838830
BLAKE2b-256 f6be690081741a64986caf89429e81917999dcadbfde759504c38538cfb036d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 a1a25d64e3a1a44ce7a18b4688428d49d07dce89db2ee49535172ce74f886188
MD5 866fe7e89e07f0049173a6402b4afaac
BLAKE2b-256 39516622d132be7b67676206d6d733ca2f4bc92ce1caa058dcdd020fcffaae3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 20df7dc9e178bc0d63a64c0658958cb7301a4a87f0d44bab83d25a1ad1e382df
MD5 92e843b8c386ac97b88d0d15a8c30b4f
BLAKE2b-256 66f87fd50ec4aa9b4059f7fb7ed5592c62996083f911218a1954708ded1e362c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 fad585cc1dea6d55f54c3609d2e2ee4a5e31b1926f7ec5a3fed39736d25e9193
MD5 196707e69d8c0cf52afee5760be87c50
BLAKE2b-256 31319dffef134089e3e85a9bae54c55fdf8284b5fca9657e7bed7c682f68b0a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 f0366dc86e08c6588ea1e8b568cd0dea65db044704616eb1483e3faf97064069
MD5 14b2bc21277f257f7dbef9659c53736a
BLAKE2b-256 ebafc35506476d43b48272cdbb3de6fbed2b6e5b8900d6f58faae54e00a6a532

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-4.0.1-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 466b1208fda8a7ac3d54d71517e3137d709b00dba2c0eee3a66d7cc357fef415
MD5 8e8d80cc6078e3b4d2500fafa6e88090
BLAKE2b-256 b3dc1efc589b560dedbc70ae431efad82d5abb0c2b585f1d09d1bad24ebd90a9

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