Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.
Closed
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
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \
FROM python:3.12-slim
COPY --from=builder --chown=app:app /app/.venv /app/.venv

# install DuckDB extensions needed by DuckDB client at build time
RUN python -c "import stacrs; stacrs.DuckdbClient()"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is duplicated in the deploy dockerfile, can we refactor to something shared so we don't repeat ourselves? Not sure if that makes sense with how dockerfiles work, but just asking.


CMD [ "/app/.venv/bin/uvicorn", "stac_fastapi.geoparquet.main:app" ]
Empty file removed infrastructure/aws/__init__.py
Empty file.
14 changes: 8 additions & 6 deletions infrastructure/aws/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
)
from aws_cdk.aws_apigatewayv2 import HttpApi, HttpStage, ThrottleSettings
from aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration
from aws_cdk.aws_ecr_assets import Platform
from aws_cdk.aws_iam import AnyPrincipal, Effect, PolicyStatement
from aws_cdk.aws_lambda import Code, Function, Runtime
from aws_cdk.aws_lambda import DockerImageCode, DockerImageFunction, Runtime
from aws_cdk.aws_logs import RetentionDays
from aws_cdk.aws_s3 import BlockPublicAccess, Bucket
from aws_cdk.custom_resources import (
Expand Down Expand Up @@ -99,24 +100,25 @@ def __init__(

CfnOutput(self, "BucketName", value=bucket.bucket_name)

api_lambda = Function(
api_lambda = DockerImageFunction(
scope=self,
id="lambda",
runtime=runtime,
handler="handler.handler",
memory_size=config.memory,
log_retention=RetentionDays.ONE_WEEK,
timeout=Duration.seconds(config.timeout),
code=Code.from_docker_build(
path=os.path.abspath("../.."),
code=DockerImageCode.from_image_asset(
directory=os.path.abspath("../.."),
file="infrastructure/aws/lambda/Dockerfile",
build_args={
"PYTHON_VERSION": runtime.to_string().replace("python", ""),
},
exclude=["**/cdk.out"],
platform=Platform.LINUX_AMD64,
),
environment={
"STAC_FASTAPI_GEOPARQUET_HREF": f"s3://{bucket.bucket_name}/{config.geoparquet_key}",
"HOME": "/tmp", # for duckdb's home_directory
"TZ": "UTC",
},
)

Expand Down
13 changes: 10 additions & 3 deletions infrastructure/aws/lambda/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ RUN dnf install -y findutils binutils && \

WORKDIR /tmp
COPY pyproject.toml pyproject.toml
COPY uv.lock uv.lock
COPY README.md README.md
COPY src/stac_fastapi/ src/stac_fastapi/

RUN uv pip install --compile-bytecode .[lambda] --target /asset
RUN uv export --frozen --extra lambda > requirements.txt && \
uv pip install install --compile-bytecode --target ${LAMBDA_TASK_ROOT} -r requirements.txt

# Reduce package size and remove useless files
WORKDIR /asset
WORKDIR ${LAMBDA_TASK_ROOT}
RUN find . -type f -name '*.pyc' | while read f; do n=$(echo $f | sed 's/__pycache__\///' | sed 's/.cpython-[0-9]*//'); cp $f $n; done;
RUN find . -type d -a -name '__pycache__' -print0 | xargs -0 rm -rf
RUN find . -type f -a -name '*.py' -print0 | xargs -0 rm -f
Expand All @@ -25,4 +27,9 @@ RUN find . -type d -a -name 'tests' -print0 | xargs -0 rm -rf
# Strip debug symbols from compiled C/C++ code
RUN find . -type f -name '*.so*' -exec strip --strip-unneeded {} \;

COPY infrastructure/aws/lambda/handler.py /asset/handler.py
COPY infrastructure/aws/lambda/handler.py ${LAMBDA_TASK_ROOT}/handler.py

# install DuckDB extensions needed by DuckDB client at build time
RUN python -c "import stacrs; stacrs.DuckdbClient()"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ceholden I'm going to take over stac-utils/rustac#655 and implement that this morning.


CMD [ "handler.handler" ]
52 changes: 16 additions & 36 deletions uv.lock

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

Loading