Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding SQS to manage messages in the SRE bot #666

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions terraform/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,42 @@ resource "aws_iam_role_policy_attachment" "sre_bot_bucket" {
role = aws_iam_role.sre-bot.name
policy_arn = aws_iam_policy.sre_bot_bucket.arn
}

# Create an IAM role and policy to allow the SRE Bot to access the SQS queue
resource "aws_iam_role" "sre_bot_sqs_access_role" {
name = "sre_bot_sqs_access_role"

assume_role_policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Principal = {
Service = "ecs-tasks.amazonaws.com",
},
Action = "sts:AssumeRole",
},
],
})
}

# Create an IAM policy to allow the SRE Bot to access the SQS queue via the role
resource "aws_iam_role_policy" "sre_bot_sqs_access_policy" {
name = "sre_bot_sqs_access_policy"
role = aws_iam_role.sre_bot_sqs_access_role.id

policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Action = [
"sqs:SendMessage",
"sqs:ReceiveMessage",
"sqs:DeleteMessage",
],
Resource = aws_sqs_queue.sre_bot_fifo_queue.arn,
},
],
})
}
22 changes: 22 additions & 0 deletions terraform/sqs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Create a FIFO SQS queue for the SRE Bot
resource "aws_sqs_queue" "sre_bot_fifo_queue" {
name = "sre-bot-fifo-queue.fifo"
fifo_queue = true # Make sure that it is FIFO queue
content_based_deduplication = true # Enable content-based deduplication
delay_seconds = 0 # Specify delay time for messages
visibility_timeout_seconds = 30 # Specify the visibility timeout

depends_on = [aws_sqs_queue.sre_bot_dead_letter_queue]

# Specify dead-letter queue (DLQ) settings
redrive_policy = jsonencode({
deadLetterTargetArn = aws_sqs_queue.sre_bot_dead_letter_queue.arn
maxReceiveCount = 5 # Number of times a message is delivered before sending to DLQ
})
}

# Dead-letter queue resource, which is used to store messages that cannot be processed
resource "aws_sqs_queue" "sre_bot_dead_letter_queue" {
name = "sre-bot-dead-letter-queue.fifo"
fifo_queue = true
}
Loading