From 19ca7937e3a9f975d561b62dbc0403da809b002e Mon Sep 17 00:00:00 2001 From: Graham Lee Date: Mon, 7 Mar 2022 13:24:45 +0000 Subject: [PATCH] Configure AWS region from env #1564 And define envs in Docker/CD action --- .github/workflows/ingestion-error-reporter-deploy.yml | 3 +++ ingestion/monitoring/Dockerfile | 6 ++++-- ingestion/monitoring/errorLogsToSlack.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ingestion-error-reporter-deploy.yml b/.github/workflows/ingestion-error-reporter-deploy.yml index bcbda12a5..f55e70a33 100644 --- a/.github/workflows/ingestion-error-reporter-deploy.yml +++ b/.github/workflows/ingestion-error-reporter-deploy.yml @@ -54,6 +54,9 @@ jobs: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: gdh-ingestor-error-monitor IMAGE_TAG: ${{ github.sha }} + # This is a webhook for a test channel: override it on job submission! + SLACK_WEBHOOK: https://hooks.slack.com/services/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 + AWS_REGION: eu-central-1 run: | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:stable -f Dockerfile . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG diff --git a/ingestion/monitoring/Dockerfile b/ingestion/monitoring/Dockerfile index 5c8b57216..2629cb61a 100644 --- a/ingestion/monitoring/Dockerfile +++ b/ingestion/monitoring/Dockerfile @@ -66,7 +66,9 @@ COPY errorLogsToSlack.py poetry.lock pyproject.toml ./ # quicker install as runtime deps are already installed RUN poetry install -# notice I haven't set the environment variables or args here. -# the slack webhook should be configured in the job definition, +# notice I haven't set the environment variable values or args here. +# the slack webhook and AWS region should be configured in the job definition, # and the args should be configured at submission time +ENV AWS_REGION +ENV SLACK_WEBHOOK CMD ["poetry", "run", "python3", "./errorLogsToSlack.py"] diff --git a/ingestion/monitoring/errorLogsToSlack.py b/ingestion/monitoring/errorLogsToSlack.py index c7cdf066a..e4e9615d3 100644 --- a/ingestion/monitoring/errorLogsToSlack.py +++ b/ingestion/monitoring/errorLogsToSlack.py @@ -73,7 +73,7 @@ def log_messages(cloudwatch_response, logger): logger.info(f"Output from {logGroup}/{logStream}:") hasMore = False oldNext = '' - logClient = boto3.client('logs') + logClient = boto3.client('logs', region_name=os.getenv('AWS_REGION')) response = logClient.get_log_events( logGroupName=logGroup, logStreamName=logStream,