Skip to content

Commit

Permalink
update CDK code
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Oct 7, 2021
1 parent 51ee29a commit 04308ef
Show file tree
Hide file tree
Showing 7 changed files with 2,788 additions and 29 deletions.
6 changes: 4 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Ignore cdk folder
cdk.out
.history
.tox
.git
.github
.vscode

deployment/*
docs/*
3 changes: 3 additions & 0 deletions deployment/aws/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cdk.out
node_modules
.mypy_cache
10 changes: 2 additions & 8 deletions deployment/aws/cdk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,8 @@ 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="lambda/Dockerfile",
),
command=["bash", "-c", "cp -R /var/task/. /asset-output/."],
),
code=aws_lambda.Code.from_docker_build(
path=os.path.abspath(code_dir), file="lambda/Dockerfile",
),
handler="handler.handler",
memory_size=memory,
Expand Down
21 changes: 11 additions & 10 deletions deployment/aws/lambda/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
FROM lambci/lambda:build-python3.8
FROM --platform=linux/amd64 lambci/lambda:build-python3.8

WORKDIR /tmp

RUN pip install titiler.application mangum>=0.10.0 -t /var/task --no-binary numpy,pydantic
RUN pip install titiler.application mangum>=0.10.0 -t /asset --no-binary pydantic

# Reduce package size and remove useless files
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 find /var/task -type d -a -name 'tests' -print0 | xargs -0 rm -rf
RUN rm -rdf /var/task/numpy/doc/
RUN rm -rdf /var/task/uvicorn

COPY lambda/handler.py /var/task/handler.py
RUN cd /asset && 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 /asset && find . -type d -a -name '__pycache__' -print0 | xargs -0 rm -rf
RUN cd /asset && find . -type f -a -name '*.py' -print0 | xargs -0 rm -f
RUN find /asset -type d -a -name 'tests' -print0 | xargs -0 rm -rf
RUN rm -rdf /asset/numpy/doc/ /asset/boto3* /asset/botocore* /asset/bin /asset/geos_license /asset/Misc

COPY lambda/handler.py /asset/handler.py

CMD ["echo", "hello world"]
Loading

0 comments on commit 04308ef

Please sign in to comment.