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-3.1.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-3.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (269.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-3.1.1-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (265.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-3.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (269.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

awslambdaric-3.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (265.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-3.1.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (347.2 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

awslambdaric-3.1.1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (345.0 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

awslambdaric-3.1.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (345.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

awslambdaric-3.1.1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (343.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

awslambdaric-3.1.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (347.1 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

awslambdaric-3.1.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (344.9 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ARM64

awslambdaric-3.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (345.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

awslambdaric-3.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (343.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

awslambdaric-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (345.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

awslambdaric-3.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (343.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

awslambdaric-3.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (346.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

awslambdaric-3.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (343.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

awslambdaric-3.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (345.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

awslambdaric-3.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (342.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

awslambdaric-3.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (344.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

awslambdaric-3.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (342.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

File details

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

File metadata

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

File hashes

Hashes for awslambdaric-3.1.1.tar.gz
Algorithm Hash digest
SHA256 1c1fd30570b9a2c5cc4ccd2151c883312c5eef2dbf759c8e9d29c18cec6de2e8
MD5 ce66824c4e03537d9a053e0dc9afcdd7
BLAKE2b-256 a3259ae3c97af6dc4628cf8094dd2189a8b97388409870fba1c54f58c64d5766

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 37159c9f67d5cced4dcf72963d29dcac48b214f601931d15b78f58a1336c9dc5
MD5 c13c1eda6a1fc7f7508ab29f243899af
BLAKE2b-256 953458469329afe94c965ccd7b3c1967f64ef9b03a4cc478bcb9c093101b4132

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7b7e44922dc4f22cdc9462d5eb41b43f8edfd4ec091f26b91bcbd9eec9c0e368
MD5 862831d82705ec9cc534d14f23392167
BLAKE2b-256 bc734e7ac2788396f6f6f939385f48ce12c5d9c4f37d4eb85d8a4db8526d6172

See more details on using hashes here.

File details

Details for the file awslambdaric-3.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fbe854813e5a1bac7d68cc05827dbcf5eb7fd2158ec2e6972d5643d00c3f3f61
MD5 1e623c88727a2d83b5d93203bf689515
BLAKE2b-256 cc72ecab2b0e838d6a4da9e767fb39fae764781bd32790ab1ccdbcb379687e56

See more details on using hashes here.

File details

Details for the file awslambdaric-3.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for awslambdaric-3.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 84855b22f2dfb68f1180ea9acbd18e5b636aed02d45e88d7bdfbf10551ba5658
MD5 201d03cf8e061dd55bcc96f4f5e07b2a
BLAKE2b-256 6d750f09ac3740189361e5fe2649f26f38faa3722c9b1b9df59d65b90852d2a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6c8ecbcf05cf02f1bd263a0831b1acf3c29cd9296cb72e74067de71185f6c118
MD5 29b60b0a6bc19ad31fcd7d909099e043
BLAKE2b-256 0e6dad856d498a037b94a96866f22ce6f244fce73976f9c064cfbff5f5c94745

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ad2ff7352517b590ca5748f75b9b9df906b111139753f35bcb069f25c14d3c94
MD5 c18a1d6d254247bfed7e5467059d7b75
BLAKE2b-256 912177c0d0867f263e270888c9c2fb85fa35e90b95d9d0cce32b252b3423c9c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a5860d96e08cc4bab5bd4d7a2cd5eeb10ea17d0269fe4c1b7c57ac8d06abbf70
MD5 9c540feea1a752ba767f4b87738fa47a
BLAKE2b-256 358d7a39188d0e95fd9975deadeb56e4fba085b03a90c572a7cfa1f279b19e2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 537e4986f723cb981af01d031743c9ae09b9ddc497d2582a548da0d696c81809
MD5 365180725997b88cf8559f7926f81d80
BLAKE2b-256 06b04acb191304bb2364c88984b09fa17b435575f7a1b50d9ada79038c5e7db0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4972127ef34729c44c9567148e68a4eacc283d685400f9d08bf51138ac4ee3d5
MD5 5db637d26469a9da19d3ed36eaf64f5a
BLAKE2b-256 79102cc723ad18b3bd049af5175bf620262bedc0c788433c3e2e90e67ec3d16e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 889b4bb6e9d88aab26d67cce7f9212aafa1f53c64eca2dc83cdf42a79eb3e6ec
MD5 7f95920915f727639a7dfb3d35b806d4
BLAKE2b-256 a9350e97e4cc862f586211b22d3cbb070e9d9a8c1646aaa5a38b5a530192805c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 755db7118d1ed900a675a2608ea9c48c463949ede5cc91648c542a5ec89df4ed
MD5 699277ecc20273fb8f86028e2d3df430
BLAKE2b-256 c4ded8901e24e5a4852c3f88b7e3abaf897b1473ca00d1952100ff1cfa5ba500

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9bb003f14f3754a3d6912e3a478cf3a306b84febdc26b612fe23c1143a89f0fd
MD5 59da29d6c792cafbac78c992692f0f71
BLAKE2b-256 368c24cd782cb5406bea659a386b8edf48d35c7ded88a7f30df533da96664eac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 329bd2e09d6a8257b9a7ff386d9956783ec905bba4c00ea2f841fbc89246910e
MD5 af1a11f46e0f1ad1ab4e8943707c66e2
BLAKE2b-256 58bd596c2d92b1446cbb6905e59d3e688b660df5b6d57e85460588200ffc2ff4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 134b5132803094ce0488f2b3e071745f09779c583371e84bc5979c21a5bac46a
MD5 6ca19aea4f302a2396313ce7e5f2a4c6
BLAKE2b-256 9ab0a084730323fa1e592ff4c7bc9b9412fa25be5a077ce6be1a1d239ffbc289

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc30e9b674828b4d00f703f7774e1bc6e78f8cc1b7fd577e583d66e1c62734ea
MD5 edc2a68795d7d75610b2503aa0cc807c
BLAKE2b-256 0fe307725379412a777ffb73c4a731e846ff26963dd2a7d9ddb3fc2ecb317db5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2cd110915f17967bfc39079c37efd7f9ca65eedb049c79f5203f02dcb3a514fc
MD5 5f69715f60d5d6e64fa01d0285d9ad1d
BLAKE2b-256 b4b1a526a96797aa2403e98c51e7ea13dc34e23cf38f8f0d1b69b6e48ef2c73f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9d0d3de5a3fd9b2d8496b07e30b471b74d6a7839c878bef89419db0dae8795e
MD5 356486d66a3f68a5990a3cdc03db9db7
BLAKE2b-256 c4312240fc9fd5c8dd3908c88f27e9d4925fd170676273141d6e42fb1b3d15ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 09ba762169869c576f8842d2b08fa6e30254494eabe533eb77efef0e38af33fa
MD5 8c271ea536faad71aee3cfb19867ca9b
BLAKE2b-256 eeceebeeffb8454b1d3fbcd6097ebb2769af11e6ea0a685a275cd9b6dc09460a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b30fd0b2e62c46c268eaf316c3bc77ba6d3900caea3c81cdf211952062e118f
MD5 0df2a68accf9737afc15e35888009342
BLAKE2b-256 350842ccefb03d619a163c2c838a43258c22adbeabc061b4e00e4f3a360d98f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a7066867f704675c65da522ee28174d674b847f7df9479eb7f60cbba2ab85e09
MD5 fe0accb856f63158d97a2a2a4b88ad13
BLAKE2b-256 61b9f04d067f827afdb696ca8c4fdffdacd0bcb0d33f003a7e3d4c9a6fc2eada

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