Skip to content

Commit

Permalink
feat(sandbox): use Poetry to manage the dependencies of `sandbox-lamb…
Browse files Browse the repository at this point in the history
…da-python` (ARCH-355) (#2938)
  • Loading branch information
tschaffter authored Dec 5, 2024
1 parent abc94bd commit 7d131b9
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 16 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,7 @@ target/
# Ipython Notebook
.ipynb_checkpoints

vite.config.*.timestamp*
vite.config.*.timestamp*

# AWS SAM
.aws-sam
12 changes: 0 additions & 12 deletions apps/sandbox/lambda-python/.aws-sam/build.toml

This file was deleted.

2 changes: 1 addition & 1 deletion apps/sandbox/lambda-python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ target/
.ipynb_checkpoints

# pyenv
.python-version
# .python-version

# celery beat schedule file
celerybeat-schedule.*
Expand Down
1 change: 1 addition & 0 deletions apps/sandbox/lambda-python/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13.0
12 changes: 11 additions & 1 deletion apps/sandbox/lambda-python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
FROM python:3.13.0-slim-bullseye AS builder

# Install the same version of Poetry as inside the dev container
RUN pip install --no-cache-dir poetry==1.8.3

WORKDIR /app
COPY pyproject.toml poetry.lock ./
RUN poetry export --without-hashes --format=requirements.txt > requirements.txt

FROM public.ecr.aws/lambda/python:3.13

COPY hello_world/app.py requirements.txt ${LAMBDA_TASK_ROOT}/
COPY --from=builder /app/requirements.txt ${LAMBDA_TASK_ROOT}/
COPY sandbox_lambda_python/app.py ${LAMBDA_TASK_ROOT}/

RUN python3.13 -m pip install --no-cache-dir -r requirements.txt -t .

Expand Down
13 changes: 13 additions & 0 deletions apps/sandbox/lambda-python/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

PYTHON_VERSION=$(cat ".python-version")

pyenv install --skip-existing $PYTHON_VERSION

# Initializing pyenv again solves an issue encountered by GitHub action where the version of Python
# installed above is not detected.
eval "$(pyenv init -)"

pyenv local $PYTHON_VERSION
poetry env use $(pyenv which python)
poetry install
183 changes: 183 additions & 0 deletions apps/sandbox/lambda-python/poetry.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions apps/sandbox/lambda-python/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"targets": {
"prepare": {
"executor": "nx:run-commands",
"options": {
"command": "./install.sh",
"cwd": "{projectRoot}"
}
},
"build": {
"executor": "nx:run-commands",
"options": {
Expand Down
15 changes: 15 additions & 0 deletions apps/sandbox/lambda-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.poetry]
name = "sandbox-lambda-python"
version = "0.1.0"
description = "A containerized AWS Lambda example for Python"
authors = ["Thomas Schaffter <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "3.13.0"
requests = "2.32.3"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
1 change: 0 additions & 1 deletion apps/sandbox/lambda-python/requirements.txt

This file was deleted.

0 comments on commit 7d131b9

Please sign in to comment.