-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/issue 7 - Create Docker container for lambda functions (#26)
* docker config * docker config * Update poetry.lock to pass snyk vulnerability given that we are removing flask * Restore tests * typo * Update CHANGELOG.md * Just a bit of clean up * Switched to AWS docker container image. Refactored into single package instead of 3. * Bump connexion version but disable api tests until refactor --------- Co-authored-by: vggonzal <vggonzal@jpl.nasa.gov> Co-authored-by: Frank Greguska <89428916+frankinspace@users.noreply.github.com>
- Loading branch information
1 parent
16726a1
commit 848e082
Showing
33 changed files
with
775 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,3 +169,4 @@ cython_debug/ | |
*.tfstate.* | ||
.vscode/launch.json | ||
.vscode/ | ||
/docker/dynamodb/shared-local-instance.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,60 @@ | ||
version: '3.8' | ||
services: | ||
dynamodb-local: | ||
command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ./data" | ||
image: "amazon/dynamodb-local:latest" | ||
container_name: dynamodb-local | ||
ports: | ||
- "8000:8000" | ||
volumes: | ||
- "./docker/dynamodb:/home/dynamodblocal/data" | ||
working_dir: /home/dynamodblocal | ||
dynamodb-local: | ||
# Uncomment if data should be persisted between container restarts | ||
# command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ./data" | ||
# volumes: | ||
# - "./docker/dynamodb:/home/dynamodblocal/data" | ||
command: "-jar DynamoDBLocal.jar -sharedDb -inMemory" | ||
image: "amazon/dynamodb-local:latest" | ||
container_name: dynamodb-local | ||
ports: | ||
- "8000:8000" | ||
working_dir: /home/dynamodblocal | ||
networks: | ||
- hydrocron | ||
hydrocron-table-create: | ||
image: "amazon/aws-cli" | ||
container_name: hydrocron-table-create | ||
entrypoint: /bin/sh -c | ||
command: > | ||
"aws dynamodb create-table | ||
--table-name hydrocron-swot-reach-table | ||
--attribute-definitions AttributeName=reach_id,AttributeType=S AttributeName=range_start_time,AttributeType=S | ||
--key-schema AttributeName=reach_id,KeyType=HASH AttributeName=range_start_time,KeyType=RANGE | ||
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 | ||
--endpoint-url http://host.docker.internal:8000; | ||
aws dynamodb create-table | ||
--table-name hydrocron-swot-node-table | ||
--attribute-definitions AttributeName=reach_id,AttributeType=S AttributeName=range_start_time,AttributeType=S | ||
--key-schema AttributeName=reach_id,KeyType=HASH AttributeName=range_start_time,KeyType=RANGE | ||
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 | ||
--endpoint-url http://host.docker.internal:8000" | ||
depends_on: | ||
- dynamodb-local | ||
networks: | ||
- hydrocron | ||
environment: | ||
HYDROCRON_ENV: LOCAL | ||
HYDROCRON_dynamodb_endpoint_url: http://host.docker.internal:8000 | ||
AWS_ACCESS_KEY_ID: fakeMyKeyId | ||
AWS_SECRET_ACCESS_KEY: fakeSecretAccessKey | ||
AWS_DEFAULT_REGION: us-west-2 | ||
hydrocron-lambda: | ||
image: "hydrocron:latest" | ||
container_name: hydrocron-lambda | ||
ports: | ||
- "9000:8080" | ||
depends_on: | ||
- hydrocron-table-create | ||
networks: | ||
- hydrocron | ||
environment: | ||
HYDROCRON_ENV: LOCAL | ||
HYDROCRON_dynamodb_endpoint_url: http://host.docker.internal:8000 | ||
AWS_ACCESS_KEY_ID: fakeMyKeyId | ||
AWS_SECRET_ACCESS_KEY: fakeSecretAccessKey | ||
AWS_DEFAULT_REGION: us-west-2 | ||
networks: | ||
# The presence of these objects is sufficient to define them | ||
hydrocron: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Define global args | ||
ARG FUNCTION_DIR="/function" | ||
|
||
FROM public.ecr.aws/lambda/python:3.10 as build_image | ||
# Include global arg in this stage of the build | ||
ARG FUNCTION_DIR | ||
ENV BUILD_DIR=/hydrocron | ||
|
||
RUN curl -sSL https://install.python-poetry.org | python3 - | ||
|
||
WORKDIR $BUILD_DIR | ||
COPY ./hydrocron ./hydrocron | ||
|
||
COPY poetry.lock pyproject.toml README.md ./ | ||
RUN ~/.local/bin/poetry lock --no-update | ||
RUN mkdir -p "${FUNCTION_DIR}" && \ | ||
~/.local/bin/poetry install --only main --sync && \ | ||
cp -r $(~/.local/bin/poetry env list --full-path | awk '{print $1}')/lib/python*/site-packages/* ${FUNCTION_DIR} && \ | ||
cp -r ./hydrocron ${FUNCTION_DIR} && \ | ||
touch ${FUNCTION_DIR}/hydrocron/__init__.py | ||
|
||
COPY docker/docker-entrypoint.sh ${FUNCTION_DIR}/bin/docker-entrypoint.sh | ||
RUN chmod 755 ${FUNCTION_DIR}/bin/docker-entrypoint.sh | ||
|
||
FROM public.ecr.aws/lambda/python:3.10 | ||
# Include global arg in this stage of the build | ||
ARG FUNCTION_DIR | ||
WORKDIR ${FUNCTION_DIR} | ||
|
||
COPY --from=build_image ${FUNCTION_DIR} ${LAMBDA_TASK_ROOT} | ||
ENV PATH="${PATH}:${LAMBDA_TASK_ROOT}/bin" | ||
|
||
CMD [ "hydrocron.api.controllers.timeseries.lambda_handler" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then | ||
exec aws-lambda-rie /usr/bin/python -m awslambdaric $1 | ||
else | ||
exec /usr/bin/python -m awslambdaric $1 | ||
fi |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" | ||
Module for interacting with the hydrocron database | ||
""" | ||
from .schema import HydrocronTable | ||
|
||
__all__ = ['HydrocronTable', ] |
File renamed without changes.
Oops, something went wrong.