Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Sync with titiler (v0.7.0)
Browse files Browse the repository at this point in the history
Update version of (this) package to 0.1.0
Use rio-tiler-pds and titiler 0.7.0.
Advance aws-cdk version to 1.160.0

The titiler package has been split into three packages, do refer to each of them.
Update python imports and usage.

Changed several things in stack/app.py:
* One thing had changed name to apigw_integrations.HttpLambdaIntegration
  and required a new id argument.
* Use a docker image instead of using docker image to construct a usable zip for the python runtime
  FROM_IMAGE

(When trying to build using the old Dockerfile, the output was too big to be used in the old way.)
  • Loading branch information
f-skold committed Jul 7, 2022
1 parent 4b5ec55 commit 7052c36
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ ENV/
.mypy_cache/

cdk.out/
cdk.context.json
29 changes: 14 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
FROM lambci/lambda:build-python3.8
FROM public.ecr.aws/lambda/python:3.9

WORKDIR /tmp

COPY setup.py setup.py
COPY titiler_pds/ titiler_pds/
COPY setup.py ${LAMBDA_TASK_ROOT}
COPY titiler_pds/ ${LAMBDA_TASK_ROOT}/titiler_pds/

# Install dependencies
RUN pip install . rasterio==1.1.8 -t /var/task --no-binary numpy,pydantic

# Leave module precompiles for faster Lambda startup
RUN cd /var/task && find . -type f -name '*.pyc' | while read f; do n=$(echo $f | sed 's/__pycache__\///' | sed 's/.cpython-[2-3][0-9]//'); cp $f $n; done;
RUN cd /var/task && find . -type d -a -name '__pycache__' -print0 | xargs -0 rm -rf
RUN cd /var/task && find . -type f -a -name '*.py' -print0 | xargs -0 rm -f
RUN cd /var/task && find . -type d -a -name 'tests' -print0 | xargs -0 rm -rf
RUN rm -rdf /var/task/numpy/doc/
RUN rm -rdf /var/task/stack

RUN pip3 install . rasterio==1.3a2 -t ${LAMBDA_TASK_ROOT} && \
\
echo "Leave module precompiles for faster Lambda startup" && \
cd ${LAMBDA_TASK_ROOT} && find . -type f -name '*.pyc' | \
while read f; do n=$(echo $f | sed 's/__pycache__\///' | sed 's/.cpython-[2-3][0-9]//'); cp $f $n; done && \
\
cd ${LAMBDA_TASK_ROOT} && find . -type d -a -name '__pycache__' -print0 | xargs -0 rm -rf && \
cd ${LAMBDA_TASK_ROOT} && find . -type f -a -name '*.py' -print0 | xargs -0 rm -f && \
cd ${LAMBDA_TASK_ROOT} && find . -type d -a -name 'tests' -print0 | xargs -0 rm -rf && \
rm -rdf ${LAMBDA_TASK_ROOT}/numpy/doc/ && \
rm -rdf ${LAMBDA_TASK_ROOT}/stack
16 changes: 9 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@
from setuptools import find_packages, setup

inst_reqs = [
"titiler>=0.1.0,<0.2",
"titiler.core>=0.7.0",
"titiler.mosaic>=0.7.0",
"titiler.application>=0.7.0",
"tilebench",
"rio-tiler-pds>=0.5.0,<1.0",
"rio-tiler-pds>=0.7.0,<1.0",
"mangum>=0.10",
]

extra_reqs = {
"deploy": [
"aws-cdk.core==1.76.0",
"aws-cdk.aws_lambda==1.76.0",
"aws-cdk.aws_apigatewayv2==1.76.0",
"aws-cdk.aws_apigatewayv2_integrations==1.76.0",
"aws-cdk.core==1.160.0",
"aws-cdk.aws_lambda==1.160.0",
"aws-cdk.aws_apigatewayv2==1.160.0",
"aws-cdk.aws_apigatewayv2_integrations==1.160.0",
],
"test": ["pytest", "pytest-cov", "pytest-asyncio", "requests"],
}


setup(
name="titiler_pds",
version="0.0.1",
version="0.1.0",
description="TiTiler for AWS Public Dataset",
python_requires=">=3",
classifiers=[
Expand Down
20 changes: 7 additions & 13 deletions stack/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
id: str,
memory: int = 1024,
timeout: int = 30,
runtime: aws_lambda.Runtime = aws_lambda.Runtime.PYTHON_3_8,
runtime: aws_lambda.Runtime = aws_lambda.Runtime.FROM_IMAGE,
concurrent: Optional[int] = None,
permissions: Optional[List[iam.PolicyStatement]] = None,
env: dict = {},
Expand All @@ -59,17 +59,10 @@ def __init__(
self,
f"{id}-lambda",
runtime=runtime,
code=aws_lambda.Code.from_asset(
path=os.path.abspath(code_dir),
bundling=core.BundlingOptions(
image=core.BundlingDockerImage.from_asset(
os.path.abspath(code_dir),
file="Dockerfile",
),
command=["bash", "-c", "cp -R /var/task/. /asset-output/."],
),
code=aws_lambda.Code.from_asset_image(
directory=os.path.abspath(code_dir),
),
handler="titiler_pds.handler.handler",
handler=aws_lambda.Handler.FROM_IMAGE,
memory_size=memory,
reserved_concurrent_executions=concurrent,
timeout=core.Duration.seconds(timeout),
Expand All @@ -82,7 +75,8 @@ def __init__(
api = apigw.HttpApi(
self,
f"{id}-endpoint",
default_integration=apigw_integrations.LambdaProxyIntegration(
default_integration=apigw_integrations.HttpLambdaIntegration(
id=f"{id}-endpoint-lambda",
handler=lambda_function
),
)
Expand Down Expand Up @@ -125,7 +119,7 @@ def __init__(
"Client": settings.client,
}.items():
if value:
core.Tag.add(app, key, value)
core.Tag(key, value, apply_to_launched_instances=False)


LambdaStack(
Expand Down
2 changes: 1 addition & 1 deletion titiler_pds/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rio_tiler_pds.landsat.utils import sceneid_parser as l8_sceneid_parser
from rio_tiler_pds.sentinel.utils import s2_sceneid_parser

from titiler.dependencies import DefaultDependency
from titiler.core.dependencies import DefaultDependency

from .settings import mosaic_config

Expand Down
4 changes: 2 additions & 2 deletions titiler_pds/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from brotli_asgi import BrotliMiddleware
from tilebench.middleware import VSIStatsMiddleware

from titiler.errors import DEFAULT_STATUS_CODES, add_exception_handlers
from titiler.middleware import CacheControlMiddleware, TotalTimeMiddleware
from titiler.application.middleware import CacheControlMiddleware, TotalTimeMiddleware
from titiler.core.errors import DEFAULT_STATUS_CODES, add_exception_handlers

from .routes import landsat_collection2, naip, sentinel
from .settings import api_config
Expand Down
7 changes: 4 additions & 3 deletions titiler_pds/routes/landsat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from rio_tiler_pds.landsat.aws import L8Reader

from titiler.custom.routing import apiroute_factory
from titiler.dependencies import BandsExprParams
from titiler.endpoints.factory import MosaicTilerFactory, MultiBandTilerFactory
from titiler.core.dependencies import BandsExprParams
from titiler.core.factory import MultiBandTilerFactory
from titiler.core.routing import apiroute_factory
from titiler.mosaic.factory import MosaicTilerFactory

from ..dependencies import CustomPathParams, MosaicParams

Expand Down
7 changes: 4 additions & 3 deletions titiler_pds/routes/landsat_collection2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from rio_tiler_pds.landsat.aws import LandsatC2Reader

from titiler.custom.routing import apiroute_factory
from titiler.dependencies import BandsExprParams
from titiler.endpoints.factory import MosaicTilerFactory, MultiBandTilerFactory
from titiler.core.dependencies import BandsExprParams
from titiler.core.factory import MultiBandTilerFactory
from titiler.core.routing import apiroute_factory
from titiler.mosaic.factory import MosaicTilerFactory

from ..dependencies import CustomPathParams, MosaicParams

Expand Down
8 changes: 4 additions & 4 deletions titiler_pds/routes/naip.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""NAIP endpoint."""

from titiler.custom.routing import apiroute_factory
from titiler.endpoints.factory import MosaicTilerFactory
from titiler.resources.enums import OptionalHeaders
from titiler.core.resources.enums import OptionalHeader
from titiler.core.routing import apiroute_factory
from titiler.mosaic.factory import MosaicTilerFactory

from ..dependencies import MosaicParams

Expand All @@ -20,5 +20,5 @@
path_dependency=MosaicParams,
router_prefix="mosaicjson/naip",
router=APIRouter(route_class=route_class),
optional_headers=[OptionalHeaders.server_timing, OptionalHeaders.x_assets],
optional_headers=[OptionalHeader.server_timing, OptionalHeader.x_assets],
)
7 changes: 4 additions & 3 deletions titiler_pds/routes/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from rio_tiler_pds.sentinel.aws import S2COGReader

from titiler.custom.routing import apiroute_factory
from titiler.dependencies import BandsExprParams
from titiler.endpoints.factory import MosaicTilerFactory, MultiBandTilerFactory
from titiler.core.dependencies import BandsExprParams
from titiler.core.factory import MultiBandTilerFactory
from titiler.core.routing import apiroute_factory
from titiler.mosaic.factory import MosaicTilerFactory

from ..dependencies import CustomPathParams, MosaicParams

Expand Down

0 comments on commit 7052c36

Please sign in to comment.