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

Uploaded Source

Built Distributions

awslambdaric-3.0.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (268.8 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.2-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (264.9 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

awslambdaric-3.0.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (268.8 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (264.9 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

awslambdaric-3.0.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (344.6 kB view details)

Uploaded CPython 3.13t manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.2-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (341.9 kB view details)

Uploaded CPython 3.13t manylinux: glibc 2.17+ ARM64

awslambdaric-3.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (343.4 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (340.6 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

awslambdaric-3.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (343.4 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (340.6 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

awslambdaric-3.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (343.6 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (340.9 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

awslambdaric-3.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (342.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (340.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

awslambdaric-3.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (342.6 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

awslambdaric-3.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (340.1 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

File details

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

File metadata

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

File hashes

Hashes for awslambdaric-3.0.2.tar.gz
Algorithm Hash digest
SHA256 d1d9f58f4b1f72179a3cde39cef1ce9bc2416978c63871472d2708e2101ffbef
MD5 f811ce64c5036446f3e0b6aff2d3408a
BLAKE2b-256 0236bb67a89c431b3229b4cd904a841fd498de6b3d2ab41b8356f41dd275d4b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18b595c696a206e13d4965e7d37750662619b04b93db60ba1787c2874710f448
MD5 622ddde4597840fbcc3922b33b4cb877
BLAKE2b-256 38dc075a90a6a911a704cef96bd0780fac98e91fe22224325d804791bf3ae99e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 20f64d9ad7e7250b63d955098fe7f75bd14a5ba9616f6695c6b8dbf7c0f57132
MD5 3a9013ec88c8a600abd7cff224aa515c
BLAKE2b-256 0cbeac41b26365dc334e99ec730f403ead76d86b7c1088087da00bbfb53af726

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6fedfceaf3b0ec094df3842d0b12b5546038d6d499c44d79f4491481d1270808
MD5 ea93df0a1d79f3fcf8fdefdd52ad41d6
BLAKE2b-256 4b9aa7ad3a44a8918e96c05c13421bc407a3088215a9bf7fd6ad3fcc020a7366

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c69d3457db145c624d8334b860522db7aadf2c2139cbc02e883feba73306c700
MD5 e21216d7d8be74004b4d5596a2a639bb
BLAKE2b-256 df9aecb9cab63654eaac9aa4df0194eb20514bb852f728c09a6790fadd3c7e96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c1279c761a0ac4f11fdde62d47132c72ee388207ceff948e383919cfe5279691
MD5 20685a7523ec6079d7ee5691bd5411b9
BLAKE2b-256 3074c3d398148d883efaa25685d0048de265c2207939b45fdeacfd1ffe59c773

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e6c819458ad73fa20f53bb850fbc57c292acbea31b9dbba7bd2fe101d1dc9fa2
MD5 58cda28a03385cdd04271d9d2981afd4
BLAKE2b-256 5de835e1c8bbc81bc10156646e9706672b1c1934f42d365cd395a54ac6c9e793

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9eac139f718e6506f65ff37f87d7b1bda14f6831c1c5406e78ed84eeb6f74b96
MD5 68e0e74b1e68c237044aa932f8279d3e
BLAKE2b-256 449bee90b04e3475a3a3b3b17c146d877877d0b1596623745ddf24536810f6a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 130dc7801da6356948d9bf269a27206345de90ed67d495c3f6812373f368af96
MD5 669ef11f36f6cc6f78cec2c6bb9ca75c
BLAKE2b-256 e0df0e3916fd82f4425079f1cff653b799495bd4fb02124426dbe2976ea755e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7a819855cbd6fdc0496df94c0338c1a77529b217c375d347fb87d6ae9dbf48db
MD5 67f88a42c46ef43d9195cc1ff5e8cc89
BLAKE2b-256 99ee183f0af47a6bd40542d0b0add92dbbd888f83ccda8b85f65d2fc869fd29d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 670e3156be9e7909fd972872105c1b74adc044827b4a481af896e1f70aba5888
MD5 e5f6a980458e643ccebe621485020049
BLAKE2b-256 80dd9d84f4e1e8a64d91bc86f18aa124b6bb4448073937ec2716fcdf48a97047

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99d020cb09864d4d071ed17bb197faca49791e2a755ea56b692792ce39d84365
MD5 fdb93cacfdd64928c46a5b89c925887f
BLAKE2b-256 a56b9f4e731acbc2fd4ea5be0cea9552ae26ede5be54fdf90fa368016166fb9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 56d67c6ded6d415c573ece9281e21f141348f16336a015824a6c4ee549303376
MD5 7b7319d8941efd34d7ca6f521cb74160
BLAKE2b-256 269e7cdac814ef0198cd31c77e1f27ede4298ea5df9be3f55cb329840a8c0c85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0261b0fd31b496a610b3400295e49e2843e1c52ef03503bce3348396dc71564
MD5 c6d039fb4325c6fb94a02e9b75aefbbf
BLAKE2b-256 326a58c94ef8aab9b6ae75429f78c1a4d68f431a7b0892d9882fae0fa2f00ade

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d502da11d3c7b094cf44824c7f44fbce724a537c8520ca593e955e6cb0551eaa
MD5 aaae6fc2e88f7bfc45571613e762190f
BLAKE2b-256 370d5c8311cbc773016057686e42f91baefdaa5a603cef8bfa8c145107016081

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bca03397c2fbb610cfa9e88384fac88a5f204bf0355921ac8c8bc4b5a92beedd
MD5 c034d3537108aefb450feee6f5e3c68c
BLAKE2b-256 fe5c02c4b2f272bfe68fe15e3ecb264f58732a3888363a46da9445a3937739b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3638d89653940e87022e594e7e4c0c89c2803585d97e60d53d305915356ae72e
MD5 6e1419973b2f3fd6f101f6a34406ba96
BLAKE2b-256 6f7b2b84cfde7d0e4afda131f27dac5d9611408c8ffec820a432e4c596677657

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page