From 41f4582869e9dc38265f438d7f0fdb57dd44a0a7 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/api/config-register.yaml | 6 +++++ infra/api/config-scan.yaml | 6 +++++ .../{lambda-test-event.json => event.json} | 0 infra/api/requirements.txt | 1 + 5 files changed, 35 insertions(+), 5 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/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