diff --git a/Dockerfile b/Dockerfile index bd28334..1fc71db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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()" + CMD [ "/app/.venv/bin/uvicorn", "stac_fastapi.geoparquet.main:app" ] diff --git a/infrastructure/aws/__init__.py b/infrastructure/aws/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/infrastructure/aws/app.py b/infrastructure/aws/app.py index 47e67b9..22843ac 100644 --- a/infrastructure/aws/app.py +++ b/infrastructure/aws/app.py @@ -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 ( @@ -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", }, ) diff --git a/infrastructure/aws/lambda/Dockerfile b/infrastructure/aws/lambda/Dockerfile index 57e0033..e50d100 100644 --- a/infrastructure/aws/lambda/Dockerfile +++ b/infrastructure/aws/lambda/Dockerfile @@ -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 @@ -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()" + +CMD [ "handler.handler" ] diff --git a/uv.lock b/uv.lock index c582a4c..a725987 100644 --- a/uv.lock +++ b/uv.lock @@ -1616,42 +1616,22 @@ wheels = [ [[package]] name = "stacrs" -version = "0.4.0" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/ab/09/87fe159ee6f58e410f14f1fe825bf8ea84ecc8d0d74bfc4082f4c54d47a2/stacrs-0.4.0.tar.gz", hash = "sha256:75afc72bad675b865fa98d6a892b47c21d6ee77a8e0170c9d908a25f494fe289", size = 543429 } -wheels = [ - { url = "https://files.pythonhosted.org/packages/ec/56/0e071dac6ad4cc94ed6ab5dd96cc4725ae1efbfbec833f9904316214f6c9/stacrs-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:7dfb30f2c701a6a8c4753e9b5f2547424481c3447438c98c63af08e216d9ee00", size = 19002353 }, - { url = "https://files.pythonhosted.org/packages/9d/7b/bd25423dfb78856fbd038d87d4b70cc58a5af58c7c9116842d4dd88da624/stacrs-0.4.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:d0d8c1ab5e4ed382eac25204d660c3d6823edc03383fbbc6eefa349fcb43ef9b", size = 17182983 }, - { url = "https://files.pythonhosted.org/packages/ff/54/406c614f926be3d188791d0c5dddc74feb99a9f1c6efb316107125144f7e/stacrs-0.4.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:fac7f157b9a19f58979a8e4ad4fe03ac51068043dc6acb7ab98418d36edc2ab5", size = 19747555 }, - { url = "https://files.pythonhosted.org/packages/bf/a6/a23b07536c9d7f4e0a7a9ab9859002b9ca489a6e150a4f959a0de72d1ba3/stacrs-0.4.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:245027c71297f2f4ce9bbc5b2b786a5b609adcaaf95ba349f0d813e0de0692dd", size = 23554734 }, - { url = "https://files.pythonhosted.org/packages/71/92/949ed4ababf6ed7da89065cc272fdf608c54002add6fdd28135363c773df/stacrs-0.4.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2c76dc04b8070f7219c9ec088efaa064d5ae4044eea00b34671d8ac358fcb677", size = 21481928 }, - { url = "https://files.pythonhosted.org/packages/4c/65/022ecde617223b1b50a23d244a5e4459f801cf26f8e35da369d7c76a7d55/stacrs-0.4.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:75cfa20f86e10376f9550f437abb4aa60afecb9de25e4597aa20280c9c626936", size = 22338591 }, - { url = "https://files.pythonhosted.org/packages/7d/e9/57c7ca8bd8ae0c16f841908c4881d909c5400fbc5e8669941bbe5bb7d365/stacrs-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:05740e48f018ca7682309c43b2df8f4e2b4958ec8a8dd37a1dec40c665bdbaa4", size = 21184292 }, - { url = "https://files.pythonhosted.org/packages/5d/47/5353b76a908c53ac8ea5fd29813c7766922963cdcd436cb8294a3ca4b2ab/stacrs-0.4.0-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:28417d75c825c497c48b6eb094b7ecbedbf2785e0823cc389d11b3294d3ba145", size = 19837041 }, - { url = "https://files.pythonhosted.org/packages/9d/96/5c9215e2c7319309890f2193578317305636fde7ea0ad87bb65d46e4962b/stacrs-0.4.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:79a84ca1615852c882abb0e98dcfd7db31d72de72545bf953a6241b8784b1cf7", size = 25698023 }, - { url = "https://files.pythonhosted.org/packages/77/97/5ec6d6632674a188b9d464760f3ee496aed80ff8a93f6209d5ed5140773c/stacrs-0.4.0-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:3646761bfa6089dfb7cbd7edd2588e80ad97ab98766ff708034e2dc6ae07c5c4", size = 26406179 }, - { url = "https://files.pythonhosted.org/packages/7d/7b/83d11f48824cbbafeed88b5229a8bf79396d53a4ba78c9866929d83a05bc/stacrs-0.4.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:becc7f2b67091c0ea2ec72f7fd888659b3b98211fec3f5581a950eb71d418d7e", size = 28904179 }, - { url = "https://files.pythonhosted.org/packages/a3/a4/2dd823e101cef7c5440e7b2e1e8c72ece59f8cca63e13fb180aeb07963af/stacrs-0.4.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:353cbddad879ec3a0ef0090913e64ae199cfdac1f3f9872414130844c6b2e066", size = 27185428 }, - { url = "https://files.pythonhosted.org/packages/4a/c6/aba27ac3a15f581eb9038bc4012c051e2fe006baca61b90daf858ad45d3f/stacrs-0.4.0-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:09d1ae25a2b1496128bab6a0abf8508e745f358d366ef4547be0c4c7f2d53ef3", size = 19002153 }, - { url = "https://files.pythonhosted.org/packages/ae/86/24628f6576dce571cf0b8f877f73faf6e832f3a5c5cb87c63f790d941fc5/stacrs-0.4.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:80e0a43c2e29ed8f2eec7c8c9e08757e673b0eed7d92ba247f428beb04796d01", size = 17182128 }, - { url = "https://files.pythonhosted.org/packages/16/d0/f91f4a8e492ce7bbd1fb7d2281c63dcafd495363ad63d3214eeac8a5ab93/stacrs-0.4.0-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:41d0ac126e8355f6b71cacd905fc42f81efe0cb6676acd715c7950825980d2c4", size = 19746621 }, - { url = "https://files.pythonhosted.org/packages/6d/44/13199476641d1b9b9cf13c83ab49c0c74dc7ffd13dec28265bf015115093/stacrs-0.4.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3df9ea3ce961b31885c7b0e8787c79da3e400b12f574ffc22cce221e96d2ae84", size = 23553865 }, - { url = "https://files.pythonhosted.org/packages/fd/4d/35005a4b813e3f49a7186bb0262a225550915abd296745f6c3489ab3528e/stacrs-0.4.0-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:510727fdb5f6fa0a2d7f910a216e5592eaa9ba5bf8172daa262340e8ba9431fd", size = 21480557 }, - { url = "https://files.pythonhosted.org/packages/f6/15/de853a5bb9a988151d74021ec45fdfdb4cb5714eceebfcec2dcd55b8da22/stacrs-0.4.0-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9341c774b67f6149da25573af04f32d3bf506a12ec712eda5a756dedce5383a1", size = 22337747 }, - { url = "https://files.pythonhosted.org/packages/d9/db/84d77a1ddc4c1e25708b73bc2f0ee460aad2d8dc70119b6288c31aa7ea2a/stacrs-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4cb6d29535395938d228e8e6ce9f5c0c08ac24580b0ed37c8e5c5980eefc9139", size = 21183936 }, - { url = "https://files.pythonhosted.org/packages/e9/f5/1eb1d58107ff3f5064d59645e1232ae778b6ef20084aa0f8a347510655f4/stacrs-0.4.0-cp313-cp313-manylinux_2_28_aarch64.whl", hash = "sha256:29862ac97f247375e8d7cf1c393129b24d7444e2780f3459a9c1cec2bdb6e9e0", size = 19836207 }, - { url = "https://files.pythonhosted.org/packages/8d/aa/f2750e8d3397b94e92faca42b98e5cb998b3d38064f5cc4cbec9f15db6c5/stacrs-0.4.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:bab70398a0b2e4ab39c838cfec26ba56e2925ae342e2f0b58e6153013e5f02d6", size = 25698666 }, - { url = "https://files.pythonhosted.org/packages/d2/15/86be80f0c89ad30574ca800c1be649b77656a5d30fd023f29fe542209fca/stacrs-0.4.0-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:89590efce08aa5de1e9cb5307981194231f398358bde5eb55693b9e75a282089", size = 26406726 }, - { url = "https://files.pythonhosted.org/packages/d9/27/9f8d448561f3a2d43c6b1b82cf6c224d737eaa6790ec6d9fdb7755645a05/stacrs-0.4.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:8fca755bb974085a767834b7f20eb33e754f3b6b81939909ef9ba1df2cea1824", size = 28904951 }, - { url = "https://files.pythonhosted.org/packages/20/15/36b5ecf19427b26d2f6d56b06aae8c42fb94c52068d466a56f4f6e2986eb/stacrs-0.4.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:784ea6f78553e4b9cf249e92359eb3490859a3c692a0f7c76580ce82f8ac3af8", size = 27185689 }, - { url = "https://files.pythonhosted.org/packages/fe/ef/7b8666871bc2e58a311e3c5d0071402b2fe12f37dd9e3dcfeee4f1e25e92/stacrs-0.4.0-cp313-cp313t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:635cd696b56e89855ab00d5c532e620feb36dd93adfb1c8dad2c8c7b315f844e", size = 19753096 }, - { url = "https://files.pythonhosted.org/packages/25/1a/52066c8b428a9403fe543333c3b13dd0ca0862d5f893c7f22339fbb7b272/stacrs-0.4.0-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0b4f3e6842a021c27ea0ce9b176973803a24f8f49661c3986808fd0456b5f299", size = 21491523 }, - { url = "https://files.pythonhosted.org/packages/c0/6c/bc44adb38a60bd42db2ad002d4205178bc0f656a7a3aa75e45b085a53df0/stacrs-0.4.0-cp313-cp313t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3a1358f329282a903fc446d7957bfe5d974da0ba01310fa155c3e9a85788aaaa", size = 22355242 }, - { url = "https://files.pythonhosted.org/packages/30/f7/1f94586d94dc6802b24610f1a3a3276e9c0f790ffc29dcac144967f9e2b5/stacrs-0.4.0-cp313-cp313t-manylinux_2_28_aarch64.whl", hash = "sha256:50350d0aefabd1d86ed92f1a545fa0dcd50e4b85e4d53cda56cda4d168436ebd", size = 19843086 }, - { url = "https://files.pythonhosted.org/packages/f1/97/4e17fdf350ac5d6088500e697009fc0dbca50364b878a42cdab466336939/stacrs-0.4.0-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:028f14035372c4e6d5181eb22309415b4f4a4cac5cc64a8013a08259a1560daa", size = 25711423 }, - { url = "https://files.pythonhosted.org/packages/b3/64/848c672fcbd17329473d580c6318e7169ee7b1a3a13d8319d761f7f5cb04/stacrs-0.4.0-cp313-cp313t-musllinux_1_2_armv7l.whl", hash = "sha256:53719986778155bc786509ceb84cf2c1046841c95babbd4bcdfb00d7d8007a88", size = 26409598 }, - { url = "https://files.pythonhosted.org/packages/c2/69/fab331fff466fc700f08633e9795f79f0a423b0d0a7c71ca23fec460709b/stacrs-0.4.0-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:cfc0db48438b0d401692f4e1c2e3c9d6482813b49141d96c1f5788a72cee85f3", size = 28917065 }, - { url = "https://files.pythonhosted.org/packages/b0/e2/fe3b7a88bff8a4ea074b00a3f9bd15f5ca92b7dcc8ebe8f548e434b9af46/stacrs-0.4.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:42c88d3acba4d6e972d24c570032efbd340285e8511d6bdfac5c07df34dce4b7", size = 27197732 }, +version = "0.5.5" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/5b/9b/ccc62d0321a05a68bd0e19bd97a52e4deb405db0a255eabd3fa6aea44b81/stacrs-0.5.5.tar.gz", hash = "sha256:22abb773dec5b73c11b81827d73675eb9683dc02b3a93a0e213a15f26d2d7275", size = 559985 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b7/03/cf5c614f55d077155b3007aa498bdc044ae6f8435920a5642fe2adabb0ac/stacrs-0.5.5-cp310-abi3-macosx_10_12_x86_64.whl", hash = "sha256:f1a8009b457696452b230ff29602b2b663267e65eacf710f6d6695935ce77d44", size = 22963772 }, + { url = "https://files.pythonhosted.org/packages/b8/3c/b1b4cbc359bbd87d1a36098c33aab3279322871070077acd233a233e1993/stacrs-0.5.5-cp310-abi3-macosx_11_0_arm64.whl", hash = "sha256:2e8277fbc3e3e00f2647469ff47a2cd69cf86f1419e5fdae21a07a9846c54d99", size = 21127004 }, + { url = "https://files.pythonhosted.org/packages/9e/73/0c87e00a8a893e57c0cb712f463c72b2a00e099ab9e8ce77d5a4b409918f/stacrs-0.5.5-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:937d77fc4cb8963af78b1c485737b7871b2cf4c365853da89b82707a468c7168", size = 23543651 }, + { url = "https://files.pythonhosted.org/packages/4b/e6/fe0ea49ef1b2d552516e1eb556c8d894f559763436cec39015c661db9978/stacrs-0.5.5-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:bcc694323f4a6a36b1ebc6a414f3c1f054917487ee69b80e0cd879b8f20ae6e1", size = 27749622 }, + { url = "https://files.pythonhosted.org/packages/c3/8d/7b78740bec332627d21d29c13bde34ccf856e0f637840d3deeda09e11288/stacrs-0.5.5-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:509d4f71af73443ed10efb5922e7c8cb52754ecbdf6f654d77ea34b20dd662a9", size = 25592737 }, + { url = "https://files.pythonhosted.org/packages/2e/49/fdef2f1925710691e577d859b1033384bb1dcdd6d6be4eef3a35424f5e0b/stacrs-0.5.5-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9c5777da2ab86281ba18a45077a2e0d76878cfb311e6c5b50856ada1700ffe32", size = 26738180 }, + { url = "https://files.pythonhosted.org/packages/01/bc/f5242dddfac08879c673e9439b3531192c7039ea32c6cba06f6337b4ae07/stacrs-0.5.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:22a44eabdd057755fff3d602405c812c205ad09817bea716f0c979a8480ef739", size = 25137689 }, + { url = "https://files.pythonhosted.org/packages/8f/d5/84d44d755a14e31da8f19739fc9bfbedc142dfcb4e0f284548d56d52ea69/stacrs-0.5.5-cp310-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:82c43f29965e05fd0ebc55883ca07b3c1a75206a10b958ca3fcecc8220d30661", size = 23752076 }, + { url = "https://files.pythonhosted.org/packages/8d/ec/87908cd5a92ed55c502c5b3853fbea2eebf2f9e91edd316d75f7529ae53f/stacrs-0.5.5-cp310-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:238a1cc3209e81dc4cc727ab708f81b642b8d6412c6be470748e24987c92afbb", size = 29496450 }, + { url = "https://files.pythonhosted.org/packages/00/cf/96c1ef69737794739a5dca17afbefd95892d226e4ee74e03fdcb80c6ec38/stacrs-0.5.5-cp310-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:c3d7c9c9c858673aeff4635724b4956eb313d0121a6a47e95ff7f8e24934e4c0", size = 30088254 }, + { url = "https://files.pythonhosted.org/packages/1d/2b/abb1af7c293fa695d03f7fbee1a6e9fd8dd02f41a35dca48d0b6b1eed8bd/stacrs-0.5.5-cp310-abi3-musllinux_1_2_i686.whl", hash = "sha256:5d823609ed5bc4e3dd2b49825a559eece3ab3870aff583e1cddb74746771a2da", size = 32815206 }, + { url = "https://files.pythonhosted.org/packages/69/6c/f4b5bdb2d56b191d4c2a1af1f13c78b30623fbf290b5334b09f2414e6678/stacrs-0.5.5-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:4241f4670b15c463f2a65895b04f0aa76bbc37aebaa044f410bfea3f9a2aaac4", size = 31069974 }, ] [[package]]