diff --git a/.github/workflows/deploy-backend.yml b/.github/workflows/deploy-backend.yml index 4162a0d37..94a06d6a6 100644 --- a/.github/workflows/deploy-backend.yml +++ b/.github/workflows/deploy-backend.yml @@ -137,6 +137,7 @@ jobs: if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }} working-directory: "./lambdas/mns_subscription" env: + APIGEE_ENVIRONMENT: int SQS_ARN: ${{ env.ID_SYNC_QUEUE_ARN }} run: | poetry install --no-root diff --git a/infrastructure/instance/id_sync_lambda.tf b/infrastructure/instance/id_sync_lambda.tf index 99ca6251a..56b0406c5 100644 --- a/infrastructure/instance/id_sync_lambda.tf +++ b/infrastructure/instance/id_sync_lambda.tf @@ -181,7 +181,7 @@ resource "aws_iam_policy" "id_sync_lambda_exec_policy" { "sqs:DeleteMessage", "sqs:GetQueueAttributes" ], - Resource = "arn:aws:sqs:eu-west-2:${var.immunisation_account_id}:${local.short_prefix}-id-sync-queue" + Resource = aws_sqs_queue.id_sync_queue.arn }, # NB anomaly: in redis_sync this appears in "redis_sync_lambda_kms_access_policy" { @@ -313,8 +313,8 @@ resource "aws_cloudwatch_log_group" "id_sync_log_group" { # NEW resource "aws_lambda_event_source_mapping" "id_sync_sqs_trigger" { - event_source_arn = "arn:aws:sqs:eu-west-2:${var.immunisation_account_id}:${local.short_prefix}-id-sync-queue" - function_name = aws_lambda_function.id_sync_lambda.arn # TODO + event_source_arn = aws_sqs_queue.id_sync_queue.arn + function_name = aws_lambda_function.id_sync_lambda.arn # Optional: Configure batch size and other settings batch_size = 10 diff --git a/infrastructure/instance/sqs_id_sync.tf b/infrastructure/instance/sqs_id_sync.tf index 32404d8ad..b3b17d325 100644 --- a/infrastructure/instance/sqs_id_sync.tf +++ b/infrastructure/instance/sqs_id_sync.tf @@ -1,5 +1,5 @@ resource "aws_sqs_queue" "id_sync_queue" { - name = "${local.short_prefix}-id-sync-queue" + name = "imms-${local.resource_scope}-id-sync-queue" kms_master_key_id = data.aws_kms_key.existing_id_sync_sqs_encryption_key.arn visibility_timeout_seconds = 360 redrive_policy = jsonencode({ @@ -9,7 +9,7 @@ resource "aws_sqs_queue" "id_sync_queue" { } resource "aws_sqs_queue" "id_sync_dlq" { - name = "${local.short_prefix}-id-sync-dlq" + name = "imms-${local.resource_scope}-id-sync-dlq" } resource "aws_sqs_queue_redrive_allow_policy" "id_sync_queue_redrive_allow_policy" { diff --git a/lambdas/mns_subscription/src/subscribe_mns.py b/lambdas/mns_subscription/src/subscribe_mns.py index 78539d044..111871df0 100644 --- a/lambdas/mns_subscription/src/subscribe_mns.py +++ b/lambdas/mns_subscription/src/subscribe_mns.py @@ -1,10 +1,13 @@ import logging +import os from mns_setup import get_mns_service +apigee_env = os.getenv("APIGEE_ENVIRONMENT", "int") + def run_subscription(): - mns = get_mns_service() + mns = get_mns_service(mns_env=apigee_env) return mns.check_subscription() diff --git a/lambdas/mns_subscription/src/unsubscribe_mns.py b/lambdas/mns_subscription/src/unsubscribe_mns.py index b934ccff3..1022cea2e 100644 --- a/lambdas/mns_subscription/src/unsubscribe_mns.py +++ b/lambdas/mns_subscription/src/unsubscribe_mns.py @@ -1,12 +1,14 @@ import logging +import os from mns_setup import get_mns_service +apigee_env = os.getenv("APIGEE_ENVIRONMENT", "int") + def run_unsubscribe(): - mns = get_mns_service() - result = mns.check_delete_subscription() - return result + mns = get_mns_service(mns_env=apigee_env) + return mns.check_delete_subscription() if __name__ == "__main__":