Skip to content

Consolidate lambda processing requirements [staging] - #547

Merged
duckduckgrayduck merged 9 commits into
stagingfrom
better_dependency_management
Nov 19, 2026
Merged

duckduckgrayduck merged 9 commits into
stagingfrom
better_dependency_management

Conversation

@duckduckgrayduck

Copy link
Copy Markdown
Contributor

How it works

Lambda requirements now live in config/aws/lambda/requirements/, as three tiers.

Each tier builds on the one above it:

File Adds Used by
processing.in Shared packages (boto3, aioboto3, redis, sentry-sdk, etc.) utils, document_conversion
pdf.in Pillow, pymupdf ocr
info_and_image.in pdfplumber, pikepdf, listcrunch info_and_image

Each lower tier has -r on the one above it, to include its packages, and -c on its compiled .txt, so shared packages stay on the same versions in every lambda. Each compiled .txt pins every package, including dependencies.

aioboto3 is in the shared tier, even though only info_and_image uses it, so that boto3, botocore and aiobotocore are always resolved together. If they’re compiled in separate tiers, botocore can end up newer than aiobotocore allows. As mentioned, it adds a little bit of bloat, but makes centralization much easier while allowing for some divergence between lambdas for space savings.

Each build_*.sh script copies its compiled file to $CODE_DIR/requirements.txt, which is what sam build installs from.

Updating dependencies

inv pip-compile-lambdas # compile without changing existing pins
inv pip-compile-lambdas --package pillow==13.0.0 # bump one package across all tiers
inv pip-compile-lambdas --upgrade # upgrade everything

To add a package for one lambda only, add it to that lambda’s tier. To give another lambda its own extras, add a new .in with -r/-c on the tier it builds on, add it to the task, and point that lambda’s build script at the new file.

Changes

Top-level pins all carried over unchanged, except:

  • Pillow 12.3.0 → 13.0.0 (ocr, info_and_image), to address dependabot alerts and to test.
  • cpuprofile removed, along with the CPU profiling code in ocr/main.py
  • setuptools<81 removed. It was a workaround from before the Python 3.12 upgrade, and the only remaining pkg_resources import (in sentry-sdk) is a fallback for Python < 3.8. ocr never had the cap.
  • aioboto3 is now installed on utils, ocr and document_conversion (about 14 MB added to these lambdas, but with the caveat that it makes this centralization much easier)

Additional changes:

  • Removed every per-lambda requirements.txt/cloud-requirements.txt, plus config/aws/lambda/cloud-requirements.txt and info-and-image-requirements.txt
  • Removed build_sidekick.sh and its call in build.sh, and the leftover VOCAB_SIZE/EMBEDDING_DIR template variables. Removed all other sidekick references.
  • Removed the unused GCP environment code (common/environment/gcp/), which already raised “not currently supported”, and the GCP Cloud Functions READMEs in ocr/ and info_and_image/
  • Added .aws-sam/ to .gitignore

Testing

[x] Deployed to staging successfully using inv deploy-lambdas --staging
[x] Each tier installed and imports in a clean Python
[x] PDF upload (image based & machine-generated)
[x] Tesseract OCR
[x] Forced Textract OCR
[x] redaction
[x] Libreoffice conversion (.png)
[x] Zipped package size for each individual lambda is under Lambda’s 250 MB unzipped limit: info_and_image dependencies are 193 MB, and the built document_conversion package is 182 MB.

Closes

#539 #27 #537

@duckduckgrayduck duckduckgrayduck changed the title Better dependency management [staging] Consolidate lambda processing requirements [staging] Nov 19, 2026
@duckduckgrayduck
duckduckgrayduck merged commit 10550f2 into staging Nov 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant