Dmytro Hrimov
  • Blog
  • About

© 2026 Dmytro Hrimov

  • Privacy Policy
  • Terms & Conditions
← All posts
by Dmytro Hrimov·Posted Nov 28, 2026·11 min read

Package Several Python AWS Lambdas from One uv Workspace

AWSLambdaPythonGitHub ActionsuvCI/CD

One repo, many Lambdas. My last post turned my packaging script into a GitHub Action that builds a Python AWS Lambda zip in one step. Every example there had one Lambda per uv project, though, and real projects rarely stay that way. Sooner or later, two Lambdas need the same model or the same logger setup, and the question is where that shared code lives. In this post, I put several Lambdas and one shared library into a uv workspace and package each Lambda into its own zip.

There are two demo repos for this post:

  • demo-aws-lambda-uv-workspace-terraform - two Lambdas as members of a virtual workspace root, plus a shared library

  • demo-aws-lambda-uv-workspace-root-terraform - one Lambda as the workspace root, plus a shared library

Both repos include Terraform as one working way to deploy the zips, but nothing in this post depends on it. The output is a plain Lambda zip, so you can deploy it with whatever tool you already use.

Four ways to lay out Python Lambdas with uv

Before getting into workspaces, it's worth looking at where they sit next to the layouts I used before.

A single Lambda

Demo repo: demo-aws-lambda-terraform-uv. One uv project at the repo root, one pyproject.toml, one uv.lock, one zip. Nothing to share, so nothing to think about. This is where most projects start. I set it up in Deploy a Python Lambda on AWS with uv and Terraform.

A monorepo of separate Lambdas

Demo repo: demo-aws-lambda-packaging-with-uv. Several uv projects under lambdas/, each with its own pyproject.toml and its own uv.lock. Each Lambda is fully on its own, which is great until two of them need the same code. In that repo, both Lambdas have the same environment.py, byte for byte. Copying works, but every fix has to be made twice, and nothing tells you when the copies drift apart. Each lock file also resolves on its own, so two Lambdas can end up on two different versions of Pydantic without anyone deciding that.

A workspace with the Lambdas as members

Demo repo: demo-aws-lambda-uv-workspace-terraform. One uv.lock at the root, the Lambdas and the shared library as members. The shared code lives in one place, and every Lambda gets the same version of every package. This post is mostly about this layout.

A workspace with the Lambda as the root

Demo repo: demo-aws-lambda-uv-workspace-root-terraform. The root pyproject.toml is the Lambda itself, and the shared library is a member. It fits a different shape of project, and I'll come back to it later.

Setting up a uv workspace for several Lambdas

The first demo repo has three members: a shared library, common, and two Lambdas, lambda_insights and log_insights. Here is the layout:

.
├── pyproject.toml        virtual workspace root
├── uv.lock               one lock file for all members
├── libs/
│   └── common/           shared library
└── lambdas/
    ├── lambda_insights/  Lambda, the only member that uses humanize
    └── log_insights/     Lambda

Each member is a normal uv project with its own pyproject.toml and its own tests/.

A virtual root

The root pyproject.toml has a [tool.uv.workspace] table and no [project] table:

[tool.uv.workspace]
members = ["libs/*", "lambdas/*"]

[dependency-groups]
dev = [
    "pytest",
]

[tool.pytest.ini_options]
addopts = "--import-mode=importlib"
testpaths = ["libs", "lambdas"]

Without [project], the root is not a package. Nothing at the root is ever built or deployed. It only holds the list of members, the dev tools, and the test settings. That's exactly what I want when there are several equal Lambdas: no Lambda is special, and none of them has to carry the workspace settings in its own pyproject.toml.

You may notice that uv's workspace docs don't describe this setup. They say "Every workspace needs a root, which is also a workspace member", and every example there has a [project] at the root. The word "virtual" only shows up on the settings page, under package: "Whether the project should be considered a Python package, or a non-package ('virtual') project." It works all the same.

The --import-mode=importlib line is there because both Lambdas have a tests/test_main.py. With the default import mode, pytest raises an error when two test files share a name and their tests/ folders are not packages. With importlib, one command runs the tests of every member from the root:

uv run --all-packages pytest

The shared library as a member

A Lambda declares common like any other dependency, and a [tool.uv.sources] entry tells uv to take it from the workspace, not from PyPI:

[project]
name = "lambda-insights"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = [
    "common",
    "humanize>=4.17.0",
    "pydantic>=2.14.4",
]

[tool.uv.sources]
common = { workspace = true }

[build-system]
requires = ["uv_build>=0.13.9,<0.14"]
build-backend = "uv_build"

[tool.uv.build-backend]
module-root = ""

module-root = "" is there for the flat layout: the package directory sits next to pyproject.toml, and uv_build looks in src/ by default.

log_insights looks the same, minus humanize. common declares Pydantic and aws-lambda-powertools, and holds a response model that both Lambdas return and a logger helper.

All three members end up in one uv.lock. uv lock resolves the whole workspace at once, so there is one version of each package across all members. Both Lambdas run the same Pydantic, because there is only one Pydantic in the lock.

You may notice that both Lambdas declare Pydantic themselves, even though they already get it through common. They import it directly for their own request models, so they should say so. If common ever drops Pydantic, a Lambda that relied on it coming through common breaks.

Run uv lock at the root after every dependency change and commit uv.lock. The action runs uv lock --check first, so a stale lock fails the build.

What the root shares, and what it doesn't

My first guess was that I could declare Pydantic once at the root and have every member get it. That doesn't work, and not because the root is virtual. I tried it with a real root project that declared pydantic>=2 and a member that declared nothing. The member's export had no Pydantic in it. A root's [project.dependencies] belong to the root package only. Each member is its own distribution, and its wheel's metadata comes from its own pyproject.toml.

Here's what the root does share with every member:

  • [tool.uv.sources] - "Any tool.uv.sources definitions in the workspace root apply to all members, unless overridden" (docs)

  • requires-python - uv uses one value for the whole workspace, the intersection of all members' values

  • constraint-dependencies and override-dependencies under [tool.uv] - uv reads them only from the root (docs), so this is the place to limit a version for every member at once

A constraint only limits the versions of packages a member already requires. It doesn't add packages. So the rule stays simple: every member declares every package it imports.

No import isolation in the workspace venv

This is the one that's easy to miss. All members share one venv during development, and uv "can't ensure that packages don't import dependencies declared by another workspace member" (docs).

Say log_insights imports humanize, which only lambda_insights declares. Locally, humanize is in the venv, so the import works and the tests pass. In AWS, the log_insights zip has no humanize, and the Lambda fails on its first call.

⚠️

Tests in the workspace venv don't catch an import of a package that only another member declares. Only the per-Lambda zip shows the mistake. Declare every package a member imports in that member's own pyproject.toml.

One zip per Lambda with a GitHub Actions matrix

The workspace is for development. AWS Lambda still wants one zip per function, with only that function's code and dependencies. I package them in CI with my action, Package Python Lambda, one matrix job per Lambda:

  package:
    needs: test
    runs-on: ubuntu-latest
    permissions:
      contents: read
    strategy:
      fail-fast: false
      matrix:
        lambda: [lambda_insights, log_insights]
    steps:
      - uses: actions/checkout@v7

      - uses: dhrimov/package-python-lambda-gha@v1
        with:
          input-path: lambdas/${{ matrix.lambda }}
          output-path: dist
          python-version: "3.13"
          platform: aarch64-manylinux2014
          upload-artifact: "true"

Let's walk through the inputs:

  • input-path is the member to package

  • output-path is where the zip goes

  • python-version and platform are the Lambda runtime and architecture

  • upload-artifact uploads the zip for a later deploy job

The package job runs after a test job, which runs uv run --all-packages pytest from the root.

Each job packages one Lambda into its own zip, named after the member's distribution name (lambda_insights.zip, log_insights.zip), and uploads it as an artifact. To add a Lambda, add a member under lambdas/ and its directory name to the matrix list.

⚠️

input-path must point at a member, such as lambdas/log_insights, not at the virtual root. The root has no [project], so it isn't a package. The build fails late, with an error that doesn't say what's wrong: Multiple top-level packages discovered in a flat-layout.

The distribution name has to normalise to the package directory (lambda-insights → lambda_insights/). I explain why in the packaging post.

Each zip holds its own Lambda, common, and only its own third-party dependencies, built for arm64. humanize is only in lambda_insights.zip, and neither zip has the other Lambda's code or any tests/ directory. That's the point of packaging per Lambda, and it's also why the import mistake from the previous section only shows up here.

⚠️

platform has to match the architecture you set on the Lambda (arm64 here). The action can't check that for you, and a mismatch only fails when the Lambda runs. I covered it in the action post.

How the action packages a workspace member

The action has supported workspace members since v1.3.0. Before that, it couldn't build the shared library at all. Here's what it does now:

  1. It exports the member's dependencies with --no-emit-local, so requirements.txt has only third-party packages, pinned from the one uv.lock, with hashes.

  2. It builds each local package the member depends on, here common, as a wheel. It finds them from the member's export, so a Lambda only gets the local packages it actually needs.

  3. It builds the member itself as a wheel.

  4. It installs the wheels and requirements.txt for the target platform. --only-binary=:all: stays on for third-party packages, so nothing gets compiled on the runner for the wrong platform. Local packages are never installed from a path - they are always the wheels from step 2.

The uv cache is keyed on the root uv.lock, because a member has no lock file of its own. Every matrix job uses the same cache key.

The Lambda as the workspace root

The second demo repo uses the other workspace layout. The root pyproject.toml is the Lambda's own project, and it also holds [tool.uv.workspace]:

[project]
name = "alarm-insights"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = [
    "common",
    "pydantic>=2.14.4",
]

[tool.uv.sources]
common = { workspace = true }

[tool.uv.workspace]
members = ["libs/*"]

[dependency-groups]
dev = [
    "pytest",
]

[build-system]
requires = ["uv_build>=0.13.9,<0.14"]
build-backend = "uv_build"

[tool.uv.build-backend]
module-root = ""

And the layout:

.
├── pyproject.toml   the Lambda's project and the workspace root
├── uv.lock
├── alarm_insights/  the Lambda
├── tests/
└── libs/
    └── common/      shared library

This is the layout uv's own Lambda guide uses: one Lambda at the root, one library as a member. The guide covers only that one Lambda. It says that "If a project includes local dependencies (e.g., via Workspaces), those too must be included in the deployment package", and its zip commands do that. They don't use --only-binary, though, so the local library gets built from source during the install, along with anything else that has no wheel for the target.

With the action, the CI step is the same as before, with input-path: . and no matrix. The action builds common as a wheel and puts it into the zip next to alarm_insights. libs/ and tests/ don't end up in the zip, and the dev group doesn't either, because the export runs with --no-dev.

So which one should you pick? The Lambda as the root fits one main Lambda with some helper libraries. You can still add a second Lambda as a member later, but at that point the first Lambda is special for no good reason - its pyproject.toml carries the workspace settings next to its own metadata. For several equal Lambdas, a virtual root is cleaner.

When a uv workspace doesn't fit

A workspace means one lock file, and that cuts both ways. uv's docs are clear that workspaces "are not suited for cases in which members have conflicting requirements" (When (not) to use workspaces). Per-Lambda packaging decides which packages go into each zip. The versions still come from the one lock file. If one Lambda needs Pydantic 1 and another needs Pydantic 2, they don't fit in one workspace.

The same goes for Python versions. uv uses one requires-python for the whole workspace, the intersection of all members' values. If one Lambda starts to need Python 3.14 and declares >=3.14, every other member now requires 3.14 too.

In both cases, the monorepo of separate projects, each with its own uv.lock, is still a fine answer.

Final words

A uv workspace gives several Python Lambdas one place for shared code and one lock file, and per-Lambda packaging still gives each of them its own zip with only what it needs. For several equal Lambdas, I'd go with a virtual root and the Lambdas as members. For one main Lambda with helpers, the Lambda as the root works just as well. In both cases, be mindful that the workspace venv won't catch a missing dependency - only the zip will.

If you try this with your own Lambdas, tell me where it breaks. Issues and pull requests are always welcome on the repos.

Thank you so much for taking the time to read this. Happy coding!