From 755b5fca114a28a07ed0da6476770b416660bc0e Mon Sep 17 00:00:00 2001 From: Bill Metangmo <25366207+billmetangmo@users.noreply.github.com> Date: Wed, 26 Jul 2023 16:16:41 +0000 Subject: [PATCH] feat: allow to deploy lambda func locally (#96) --- README.md | 27 +++++++++++++++---- infra/.env | 19 +++++++------ infra/api/config-register.yaml | 6 +++++ infra/api/config-scan.yaml | 6 +++++ .../{lambda-test-event.json => event.json} | 0 infra/api/requirements.txt | 1 + 6 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 infra/api/config-register.yaml create mode 100644 infra/api/config-scan.yaml rename infra/api/{lambda-test-event.json => event.json} (100%) diff --git a/README.md b/README.md index 7e06a94..105a214 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ If you are here, it means that you are interested in an in-house deployment of t * Run the following commands: - ``` + ```bash cd infra/ terraform init secretsfoundry run --script "terraform apply" @@ -69,8 +69,8 @@ If you are here, it means that you are interested in an in-house deployment of t ### Pyramid test #### Unit tests - ``` - cd api/ + ```bash + cd infra/api/ pytest test_extract.py pytest test_notify.py ``` @@ -78,18 +78,35 @@ If you are here, it means that you are interested in an in-house deployment of t #### Integration tests To launch integration tests locally : - ``` + ```bash act -j --secret-file .env ``` -#### End to end +To invoke register handler locally (lambda function): + ```bash + cd infra/api + secretsfoundry run -p ../ --script "lambda invoke -v --config-file config-register.yaml" + ``` +To invoke scan handler locally (lambda function): + ```bash + cd infra/api + secretsfoundry run -p ../ --script "lambda invoke -v --config-file config-scan.yaml" + ``` +#### End to end +```bash +sudo apt-get install -y chromium-browser +pip install -r requirements.txt +pip install -r infra/api/requirements.txt +pytest infra/api/test_liveness_mtchoun-mouh.py +``` ### Application monitoring The API Gateway and Lambda services save logs in CloudWatch. The tracking of the visits on the website is done with https://fr.matomo.org/ (opensource alternative to Google Analytics). +Sentry is used to detection and tracking of errors (UI+backend) ### Application performance diff --git a/infra/.env b/infra/.env index c070cdb..8896c75 100644 --- a/infra/.env +++ b/infra/.env @@ -1,10 +1,9 @@ -TF_VAR_MAINTAINER_MAIL="${aws-ssm(region=eu-central-1):/mtchoun-mouh/maintainer_mail}" -TF_VAR_WEBSITE_BUCKET_NAME="mtchoun-mouh" -TF_VAR_IMAGES_BUCKET_NAME="djansang2" -TF_VAR_SENTRY_DNS="${aws-ssm(region=eu-central-1):/mtchoun-mouh/sentry_dsn}" -TF_VAR_API_KEY="${aws-ssm(region=eu-central-1):/mtchoun-mouh/zulip_api_key}" -#source api/venv/bin/activate -# export TF_LOG="DEBUG" -GITHUB_HEAD_REF=develop -GITHUB_REF_NAME=test-branch -export REGION="eu-central-1" \ No newline at end of file +API_KEY="${aws-ssm(region=eu-central-1):/mtchoun-mouh/zulip_api_key}" +BUCKET_NAME="${BRANCH_NAME}-djansang" +ENV="local" +LINKS_TABLE="mtchoun-mouh-${BRANCH_NAME}-Link_table" +MAINTAINER_MAIL="${aws-ssm(region=eu-central-1):/mtchoun-mouh/maintainer_mail}" +REGION="eu-central-1" +REGISTERS_TABLE="mtchoun-mouh-${BRANCH_NAME}-Register" +SENTRY_DNS="${aws-ssm(region=eu-central-1):/mtchoun-mouh/sentry_dsn}" +USERS_TABLE="mtchoun-mouh-${BRANCH_NAME}-Users" diff --git a/infra/api/config-register.yaml b/infra/api/config-register.yaml new file mode 100644 index 0000000..a479d54 --- /dev/null +++ b/infra/api/config-register.yaml @@ -0,0 +1,6 @@ +region: eu-central-1 + +function_name: my_lambda_function +handler: lambda.register_handler +runtime: python3.8 +# role: lambda_basic_execution diff --git a/infra/api/config-scan.yaml b/infra/api/config-scan.yaml new file mode 100644 index 0000000..e8a988f --- /dev/null +++ b/infra/api/config-scan.yaml @@ -0,0 +1,6 @@ +region: eu-central-1 + +function_name: my_lambda_function +handler: lambda.scan_handler +runtime: python3.8 +# role: lambda_basic_execution diff --git a/infra/api/lambda-test-event.json b/infra/api/event.json similarity index 100% rename from infra/api/lambda-test-event.json rename to infra/api/event.json diff --git a/infra/api/requirements.txt b/infra/api/requirements.txt index c087620..fab8add 100644 --- a/infra/api/requirements.txt +++ b/infra/api/requirements.txt @@ -6,3 +6,4 @@ requests==2.31.0 soupsieve==2.0.1 zulip==0.8.2 sentry-sdk==1.14.0 +python-lambda==11.8.0 \ No newline at end of file