From 3d1733bdc6813da98dfb4467f94e2cf117c48d4d Mon Sep 17 00:00:00 2001 From: aloftus23 <79927030+aloftus23@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:35:21 -0400 Subject: [PATCH] Move SQS to Serverless to fix lambda mapping and deploy (#2282) * Create the queue in Serverless instead of terraform * fix sqs policy for db accessor ec2 --- backend/env.yml | 2 -- backend/serverless.yml | 7 +++++++ backend/src/tasks/functions.yml | 2 +- infrastructure/database.tf | 2 +- infrastructure/prod.tfvars | 1 - infrastructure/sqs.tf | 14 -------------- infrastructure/stage.tfvars | 1 - infrastructure/vars.tf | 7 ------- 8 files changed, 9 insertions(+), 27 deletions(-) delete mode 100644 infrastructure/sqs.tf diff --git a/backend/env.yml b/backend/env.yml index ac16d4ddc..4a922725a 100644 --- a/backend/env.yml +++ b/backend/env.yml @@ -41,7 +41,6 @@ staging: EXPORT_BUCKET_NAME: cisa-crossfeed-staging-exports PE_API_URL: ${ssm:/crossfeed/staging/PE_API_URL} REPORTS_BUCKET_NAME: cisa-crossfeed-staging-reports - SQS_QUEUE_NAME: crossfeed-staging-worker-queue CLOUDWATCH_BUCKET_NAME: cisa-crossfeed-staging-cloudwatch prod: @@ -78,7 +77,6 @@ prod: EXPORT_BUCKET_NAME: cisa-crossfeed-prod-exports PE_API_URL: ${ssm:/crossfeed/staging/PE_API_URL} REPORTS_BUCKET_NAME: cisa-crossfeed-prod-reports - SQS_QUEUE_NAME: crossfeed-prod-worker-queue CLOUDWATCH_BUCKET_NAME: cisa-crossfeed-prod-cloudwatch dev-vpc: diff --git a/backend/serverless.yml b/backend/serverless.yml index 0524e0af4..c8e4f94d3 100644 --- a/backend/serverless.yml +++ b/backend/serverless.yml @@ -79,6 +79,13 @@ provider: - logs:StopLiveTail Resource: '*' +resources: + Resources: + MySQSQueue: + Type: AWS::SQS::Queue + Properties: + QueueName: ${self:provider.stage}-worker-queue + functions: - ${file(./src/tasks/functions.yml)} - ${file(./src/api/functions.yml)} diff --git a/backend/src/tasks/functions.yml b/backend/src/tasks/functions.yml index c12b3cfbe..cc373c320 100644 --- a/backend/src/tasks/functions.yml +++ b/backend/src/tasks/functions.yml @@ -36,7 +36,7 @@ scanExecution: - sqs: arn: Fn::GetAtt: - - ${file(env.yml):${self:provider.stage}.SQS_QUEUE_NAME, ''} + - ${self:provider.stage}-worker-queue - Arn batchSize: 5 # Number of messages the lambda can continue to process while a Fargate is still running diff --git a/infrastructure/database.tf b/infrastructure/database.tf index 125fc33be..fd516fb92 100644 --- a/infrastructure/database.tf +++ b/infrastructure/database.tf @@ -180,7 +180,7 @@ resource "aws_iam_role_policy" "sqs_send_message_policy" { "sqs:GetQueueUrl" ], Effect = "Allow", - Resource = aws_sqs_queue.terraform_queue.arn + Resource = "*" } ] }) diff --git a/infrastructure/prod.tfvars b/infrastructure/prod.tfvars index 3db2dd255..db987357d 100644 --- a/infrastructure/prod.tfvars +++ b/infrastructure/prod.tfvars @@ -70,4 +70,3 @@ create_db_accessor_instance = true db_accessor_instance_class = "t3.2xlarge" create_elk_instance = false elk_instance_class = "t3.2xlarge" -sqs_queue_name = "crossfeed-prod-worker-queue" diff --git a/infrastructure/sqs.tf b/infrastructure/sqs.tf deleted file mode 100644 index 2a62f8449..000000000 --- a/infrastructure/sqs.tf +++ /dev/null @@ -1,14 +0,0 @@ - -# SQS Queue -resource "aws_sqs_queue" "terraform_queue" { - name = var.sqs_queue_name - delay_seconds = 90 - max_message_size = 262144 - message_retention_seconds = 345600 # 4 days - receive_wait_time_seconds = 10 - - tags = { - Project = var.project - Stage = var.stage - } -} \ No newline at end of file diff --git a/infrastructure/stage.tfvars b/infrastructure/stage.tfvars index 6eac78731..a0a05cef0 100644 --- a/infrastructure/stage.tfvars +++ b/infrastructure/stage.tfvars @@ -70,4 +70,3 @@ create_db_accessor_instance = true db_accessor_instance_class = "t3.2xlarge" create_elk_instance = true elk_instance_class = "t3.2xlarge" -sqs_queue_name = "crossfeed-staging-worker-queue" diff --git a/infrastructure/vars.tf b/infrastructure/vars.tf index b80769e84..c3d05237b 100644 --- a/infrastructure/vars.tf +++ b/infrastructure/vars.tf @@ -429,10 +429,3 @@ variable "create_elk_instance" { type = bool default = false } - -variable "sqs_queue_name" { - description = "sqs_queue_name" - type = string - default = "crossfeed-staging-worker-queue" -} -