Complete the code to create an SNS topic named 'MyTopic'.
resource "aws_sns_topic" "example" { name = [1] }
The SNS topic requires a name. Here, 'MyTopic' is the correct name for the SNS topic.
Complete the code to create an SQS queue named 'MyQueue'.
resource "aws_sqs_queue" "example" { name = [1] }
The SQS queue requires a name. 'MyQueue' is the correct name for the queue resource.
Fix the error in the subscription resource to connect the SNS topic to the SQS queue.
resource "aws_sns_topic_subscription" "example" { topic_arn = aws_sns_topic.example.arn protocol = [1] endpoint = aws_sqs_queue.example.arn }
The protocol for subscribing an SQS queue to an SNS topic is 'sqs'.
Fill both blanks to allow the SNS topic to send messages to the SQS queue by setting the correct policy.
resource "aws_sqs_queue_policy" "example" { queue_url = aws_sqs_queue.example.url policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Principal = "*" Action = [1] Resource = aws_sqs_queue.example.arn Condition = { ArnEquals = { "aws:SourceArn" = [2] } } }] }) }
The SQS queue policy must allow the action 'sqs:SendMessage' from the SNS topic ARN to accept messages.
Fill all three blanks to create a complete fan-out pattern with two SQS queues subscribed to one SNS topic.
resource "aws_sns_topic" "example" { name = [1] } resource "aws_sqs_queue" "queue1" { name = [2] } resource "aws_sqs_queue" "queue2" { name = [3] } resource "aws_sns_topic_subscription" "sub1" { topic_arn = aws_sns_topic.example.arn protocol = "sqs" endpoint = aws_sqs_queue.queue1.arn } resource "aws_sns_topic_subscription" "sub2" { topic_arn = aws_sns_topic.example.arn protocol = "sqs" endpoint = aws_sqs_queue.queue2.arn }
The SNS topic is named 'FanOutTopic'. The first SQS queue is named 'QueueOne'. The second SQS queue is named 'MyQueue' to complete the fan-out pattern.