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.0.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.0-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.0-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (265.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-3.1.0-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.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (265.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

awslambdaric-3.1.0-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.0-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.0-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.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (343.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

awslambdaric-3.1.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: awslambdaric-3.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 25dd9180c23f1a636a0c23f029944c9b3bf4a0f3b3d9177326dcc4136ed52173
MD5 f60a48319e243158923ef28fcb602dd6
BLAKE2b-256 a2d6e8f8b28d2ccb183a2f94117a563045aa5f83a1fa36b0c2ccd1ea0f96e84f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5ce2786b5cbdad45f3d59e591531b2accc3091de0a4c6200f735af36c52638c
MD5 415a61d2a284516ab64b6c8876567c21
BLAKE2b-256 d754f04d05b863350f609ad0b16d959fced929a1249d8092fa216bea475b075e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 739129dbac26697490cf47577ae291aee9255e13d6f69f25684f17b5505ec385
MD5 c868eb401fdc03f4751aeedac39267c5
BLAKE2b-256 52ace5b9c0ee666cec9de2dd2d81a1c442dc99a02d51c5603535bce92c123e21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 46c84e3f3983f0685665c6f20f09f140f335b27912691ebdd02912b202c0cb49
MD5 dc9b264a95addefae40a38d721be17f5
BLAKE2b-256 3861eabf84933c6d5d518263ae16e9eba95227a091082c2e377971566d47feb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4596220aaa30ec69defca98dfb1129395d797d835d2343757c9cc8a56acf04c2
MD5 4cdda07262f1826a1b0e4492af838a27
BLAKE2b-256 3da88cec5f80a88799809df95f83eb6ef19cdb385b2e41e64511d2b545901cff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 90077df943d45b834e51c9cdbd1f6ae485336b88f911d8c1ae4c1a6fe8b0c2ea
MD5 1f55f6612ad7015db2efff885604738c
BLAKE2b-256 9d332c1052a50d6613178d62febc5ea6838d15dcf9a33a41491765d9cb9ed5f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f80d5857607cb474d7a120b00e43ff81a07bb4ccfac9c7c65fcf008e4ef26828
MD5 4eea731409405dc9e7843ca43ac0602b
BLAKE2b-256 f3e9ff11801953d3dcc6d87c8345e8361bacd14ce3e6d173dcb7f8ba0c4c8191

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 40e451534f719d56c02d742e08b730f5929f490a55993795b53ca1ee7d0333e0
MD5 3fc89b98b99292aaa0792600781c4b25
BLAKE2b-256 79522980a3126a93cb1aaddd16ab1e724de16d611e07adfcf938f15467b1e67a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c8df019af36162fd94d70dd1c93eb3461b93cec959469392c66ffd75c680dd2e
MD5 68a6d2625b2cd8eea6161a1fe4613e22
BLAKE2b-256 9e77177b2287bf0ab25f79f75f3eb3491f951ed4d936a1d609e9024f09768d99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 81118444045ba2f29ba721e40514a402081fec40d64d5490821258ad3efd1276
MD5 816ee37d8d0fb6a69c59c2b2fed4a890
BLAKE2b-256 fd4a8fa26721559ae5a88ca3d073e7e2c1d876227254f64e0cedf1c1618c7701

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 695dde7f9dca96a3501733d4abacc9660fde0607ff62afc43496e15311278363
MD5 0b2710a5e81183c1376d938589c449b9
BLAKE2b-256 bb072543d04960d7c7e333fc89e986dcbc396b071849e46dcb43e1bd5efb8aa9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 181994987e1c6001f94702cf9a428d4258ccdff10b32be5fb76ed74516582c5c
MD5 1183b2e9bcc01ee0214f6a0168e5611d
BLAKE2b-256 02b1837798ecf0a0e9b30d4e252ff97f7968c85a4e3885a388a45852fa7412fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7a844d52923864f913712e4958c4b22abde12b83d1917d981ee5e1b6604f5299
MD5 43788af9dcedcb178d4061f6c836d72a
BLAKE2b-256 7601f0ee0ebc40f59bab679a4268d5a3fa10fbe3ac518b279fb82fabad24cb08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3d03750486fca0e50cda96b8c9328fbf45e35200fffbbe0899e31f5a5f3527d0
MD5 32721ae0bd430a6928ec15867586039c
BLAKE2b-256 3691a20bcbeed7840e980cf351b90667e6fbe577c01a61d53c494596e9811bfd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2369468baf25ef1dd8be790e08236ca38be56b4f0e21233541119bc91b990848
MD5 c4bd5091e25da83ec6030137de0f2568
BLAKE2b-256 3655097e696f2250707147077730460950705c63038aad442f7416e3cd8ea57b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 35753663758dd59fed121d243452ab186c96e5aed9b0dc405a741e420943be3b
MD5 ec0800ace2c0cb553f997e15379c802f
BLAKE2b-256 9fe11b2907bd895d51eea9f1c31ff28ed9dadcb90d3b0c08e2e974a31a3db974

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 21ded61c006f0f401deb500957eb8979f50ec01571f1d7666278a695a55a68fe
MD5 cb3acc625659c683ea3115fa8088ce04
BLAKE2b-256 86f363364349a7ad7fd13e837d4a46b3856c2b135d8a9a96220a2aa943a452ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cdbad3d5581df07c75daeeb4d3186150eafaccaba4b8426a09947793343089d2
MD5 fe4af8da048a8bbed434425b50a21cc4
BLAKE2b-256 73778cccc127e7e67f8c20932beea4365f81733928836d556c2422a9bcab1767

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1b50e74fa49ee21ddd42b8e25135de938c7a13e50dbed09d83abc10fb0f9b73b
MD5 b9dd33ec045efb3299474e3f306cddb3
BLAKE2b-256 739344a2f945d825d7920e4734d6309a0c6f82d5a690d1f6fe3fb1ef47969e28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 354ec7c02ee7df6ce1cd2c95e2a0ed1276ad947ee03b63057935a336a4565340
MD5 4489604d8f7d105d7f28997d2c242c74
BLAKE2b-256 eadb0fb9029adf0ab2cabada30aee4fdc1ecdb56c2c4ab1243e68580e3b222e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for awslambdaric-3.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7270c40ce93b31f093d420e3ed47c72aedb76ab71ba6a4c42be16b18a9472435
MD5 b7f92c0fa1113e7eac87009b30e8f0be
BLAKE2b-256 0794b0f578f4692bcd396959ed4f02058dafebc1dc4e15d29e089681b126773c

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