Skip to content

Commit 166abc4

Browse files
eli-507 remove unused packages [test, example] from botocore dependency (#446)
* eli-507 remove botocore dependency * eli-507 flask extras * eli-507 add clean lambda script * eli-507 position clean lambda script * boto dependencies are placed in main again --------- Co-authored-by: karthikeyannhs <[email protected]>
1 parent faed1f6 commit 166abc4

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ check-licenses:
4343
build: dist/lambda.zip # Build lambda.zip in dist/
4444

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

4848
deploy: # Deploy the project artefact to the target environment @Pipeline
4949
# TODO: Implement the artefact deployment step

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ httpx = "^0.28.1"
2626
yarl = "^1.18.3"
2727
pydantic = "^2.12.3"
2828
asgiref = "^3.9.1"
29-
boto3 = "^1.40.57"
30-
botocore = "^1.40.57"
3129
eval-type-backport = "^0.2.2"
3230
mangum = "^0.19.0"
3331
wireup = "^2.1.0"
3432
python-json-logger = "^3.3.0"
3533
fhir-resources = "^8.0.0"
3634
python-dateutil = "^2.9.0"
3735
pyhamcrest = "^2.1.0"
36+
boto3 = "^1.40.57"
37+
botocore = "^1.40.57"
3838
aws-xray-sdk = "2.14.0"
3939

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

76+
[tool.poetry.scripts]
77+
clean-lambda = "scripts.lambda.clean_lambda:main"
78+
7679
[tool.ruff]
7780
line-length = 120
7881
exclude = ["docs/", "scripts/"]

scripts/lambda/__init__.py

Whitespace-only changes.

scripts/lambda/clean_lambda.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import zipfile
2+
import os
3+
import shutil
4+
import tempfile
5+
import logging
6+
7+
ZIP_PATH = "dist/lambda.zip"
8+
9+
# Configure logging
10+
logging.basicConfig(
11+
level=logging.INFO,
12+
format="%(asctime)s [%(levelname)s] %(message)s"
13+
)
14+
logger = logging.getLogger(__name__)
15+
16+
# Folders to prune (only safe unused folders)
17+
BOTOCORE_SAFE_PRUNE = [
18+
"botocore/data/s3/tests",
19+
"botocore/data/glacier/tests",
20+
]
21+
22+
BOTO3_SAFE_PRUNE = [
23+
"boto3/examples"
24+
]
25+
26+
def main():
27+
if not os.path.exists(ZIP_PATH):
28+
logger.warning("ZIP file %s does not exist. Skipping cleanup.", ZIP_PATH)
29+
return
30+
31+
tmp_dir = tempfile.mkdtemp(prefix="lambda_clean_")
32+
logger.info("Unzipping %s...", ZIP_PATH)
33+
with zipfile.ZipFile(ZIP_PATH, "r") as z:
34+
z.extractall(tmp_dir)
35+
36+
# Remove only safe folders
37+
for folder_list in [BOTOCORE_SAFE_PRUNE, BOTO3_SAFE_PRUNE]:
38+
for rel in folder_list:
39+
target = os.path.join(tmp_dir, rel)
40+
if os.path.exists(target):
41+
logger.info("Removing %s", target)
42+
shutil.rmtree(target)
43+
44+
# Re-create the cleaned zip
45+
logger.info("Re-zipping cleaned Lambda package...")
46+
with zipfile.ZipFile(ZIP_PATH, "w", zipfile.ZIP_DEFLATED) as z:
47+
for root, _, files in os.walk(tmp_dir):
48+
for f in files:
49+
abs_path = os.path.join(root, f)
50+
rel_path = os.path.relpath(abs_path, tmp_dir)
51+
z.write(abs_path, rel_path)
52+
53+
shutil.rmtree(tmp_dir)
54+
logger.info("Cleaned Lambda saved at %s", ZIP_PATH)
55+
56+
if __name__ == "__main__":
57+
logger.info("Running clean_lambda.py...")
58+
main()

0 commit comments

Comments
 (0)