Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ check-licenses:
build: dist/lambda.zip # Build lambda.zip in dist/

dist/lambda.zip: $(MAKE_DIR)/pyproject.toml $(MAKE_DIR)/poetry.lock $(shell find src -type f)
poetry build-lambda -vv
poetry build-lambda -vv && poetry run clean-lambda

deploy: # Deploy the project artefact to the target environment @Pipeline
# TODO: Implement the artefact deployment step
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ httpx = "^0.28.1"
yarl = "^1.18.3"
pydantic = "^2.12.3"
asgiref = "^3.9.1"
boto3 = "^1.40.57"
botocore = "^1.40.57"
eval-type-backport = "^0.2.2"
mangum = "^0.19.0"
wireup = "^2.1.0"
python-json-logger = "^3.3.0"
fhir-resources = "^8.0.0"
python-dateutil = "^2.9.0"
pyhamcrest = "^2.1.0"
boto3 = "^1.40.57"
botocore = "^1.40.57"
aws-xray-sdk = "2.14.0"

[tool.poetry.group.dev.dependencies]
Expand Down Expand Up @@ -73,6 +73,9 @@ docker-platform = "linux/x86_64"
package-artifact-path = "dist/lambda.zip"
without = "dev"

[tool.poetry.scripts]
clean-lambda = "scripts.lambda.clean_lambda:main"

[tool.ruff]
line-length = 120
exclude = ["docs/", "scripts/"]
Expand Down
Empty file added scripts/lambda/__init__.py
Empty file.
58 changes: 58 additions & 0 deletions scripts/lambda/clean_lambda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import zipfile
import os
import shutil
import tempfile
import logging

ZIP_PATH = "dist/lambda.zip"

# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s"
)
logger = logging.getLogger(__name__)

# Folders to prune (only safe unused folders)
BOTOCORE_SAFE_PRUNE = [
"botocore/data/s3/tests",
"botocore/data/glacier/tests",
]

BOTO3_SAFE_PRUNE = [
"boto3/examples"
]

def main():
if not os.path.exists(ZIP_PATH):
logger.warning("ZIP file %s does not exist. Skipping cleanup.", ZIP_PATH)
return

tmp_dir = tempfile.mkdtemp(prefix="lambda_clean_")
logger.info("Unzipping %s...", ZIP_PATH)
with zipfile.ZipFile(ZIP_PATH, "r") as z:
z.extractall(tmp_dir)

# Remove only safe folders
for folder_list in [BOTOCORE_SAFE_PRUNE, BOTO3_SAFE_PRUNE]:
for rel in folder_list:
target = os.path.join(tmp_dir, rel)
if os.path.exists(target):
logger.info("Removing %s", target)
shutil.rmtree(target)

# Re-create the cleaned zip
logger.info("Re-zipping cleaned Lambda package...")
with zipfile.ZipFile(ZIP_PATH, "w", zipfile.ZIP_DEFLATED) as z:
for root, _, files in os.walk(tmp_dir):
for f in files:
abs_path = os.path.join(root, f)
rel_path = os.path.relpath(abs_path, tmp_dir)
z.write(abs_path, rel_path)

shutil.rmtree(tmp_dir)
logger.info("Cleaned Lambda saved at %s", ZIP_PATH)

if __name__ == "__main__":
logger.info("Running clean_lambda.py...")
main()