AWS Lambda Runtime Interface Client for Python
The AWS Lambda Runtime Interface Client (RIC) for Python is a lightweight library that implements the Lambda Runtime API. It enables you to use alternative base images or build custom runtimes for your Python Lambda functions, making them compatible with the Lambda service. It manages the interaction between the Lambda execution environment and your function code, handling invocation events and responses. The library is actively maintained by AWS and is currently at version 4.0.0.
Warnings
- breaking Version 3.0.0 of `awslambdaric` dropped support for Python runtimes older than 3.9. Functions using Python versions 3.8 or earlier will no longer work with `awslambdaric` v3.0.0 and newer.
- deprecated AWS Lambda will deprecate Python 3.9 runtime. New functions using Python 3.9 will be blocked from creation after January 15, 2026, and existing functions cannot be updated with Python 3.9 after February 15, 2026.
- gotcha When upgrading Python runtime versions for Lambda functions (e.g., from 3.7 to 3.9), ensure that external dependencies are correctly packaged at the root level of your deployment, not within a 'packages' folder, as the underlying Python runtime search path changed.
- gotcha Incorrect configuration of `ENTRYPOINT` and `CMD` in Dockerfiles for custom runtimes is a common error. The `awslambdaric` module must be the `ENTRYPOINT`, and your function's handler path the `CMD`.
- gotcha Historical compatibility issues with the `simplejson` dependency (e.g., lack of Python 3.9 wheels for older `simplejson` versions) could lead to installation failures.
- gotcha Version 3.0.0 introduced support for SnapStart runtime hooks. If you are leveraging AWS Lambda SnapStart, be aware of the new hooks and how they might affect your function's initialization lifecycle.
Install
-
pip install awslambdaric
Imports
- LambdaRuntimeException
from awslambdaric.lambda_runtime_exception import LambdaRuntimeException
Quickstart
# app.py
def handler(event, context):
print(f"Received event: {event}")
print(f"Context: {context.aws_request_id}")
return {"statusCode": 200, "body": "Hello from Lambda!"}
# Dockerfile
FROM python:3.9-slim-buster
# Set working directory
WORKDIR /var/task
# Copy function code
COPY app.py .
# Install awslambdaric and any other dependencies
RUN pip install --no-cache-dir awslambdaric
# Set the ENTRYPOINT to the AWS Lambda Runtime Interface Client
ENTRYPOINT ["/usr/local/bin/python", "-m", "awslambdaric"]
# Set the CMD to your Lambda handler
CMD ["app.handler"]