-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
I was wondering if there were any examples on how to use UV with the prebuilt AWS lambda python base images? Using the https://docs.astral.sh/uv/guides/integration/docker/ as reference but I seem to get into a state where the lambda does not have access to the imports.
I thought there wasn't a need to update PYTHONPATH as this would point to the default used by the lambda.
Dockerfile
FROM public.ecr.aws/lambda/python:3.13
ARG ACCESS_TOKEN
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1
ENV UV_LINK_MODE=copy
# Copy pyproject.toml and uv.lock to the working directory
COPY pyproject.toml uv.lock ${LAMBDA_TASK_ROOT}
# Install dependencies using uv
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-install-project --no-dev
# Copy the rest of the application code
COPY . ${LAMBDA_TASK_ROOT}
WORKDIR ${LAMBDA_TASK_ROOT}
# Install the project itself
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev
RUN python -c "import aws_lambda_typing; print('aws_lambda_typing is installed')"
CMD ["lambda.lambda_handler"]
lambda.py
from aws_lambda_typing import context as ctx
from aws_lambda_typing import events
import logging
def lambda_handler(event: events.APIGatewayProxyEventV1, context: ctx.Context):
# def lambda_handler(event, context):
logging.info("RUNNING")
return {"statusCode": 200, "body": "Ok"}
Command is correct as when I remove the types I get a 200.
pyproject.toml
[project]
name = "test"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11.9"
dependencies = [
"aws-lambda-typing==2.17.0",
]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation