0
0
AWScloud~10 mins

SNS and SQS integration pattern (fan-out) in AWS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an SNS topic named 'MyTopic'.

AWS
resource "aws_sns_topic" "example" {
  name = [1]
}
Drag options to blanks, or click blank then click option'
A"MyBucket"
B"MyQueue"
C"MyFunction"
D"MyTopic"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a queue or bucket name instead of a topic name.
Forgetting to put the name in quotes.
2fill in blank
medium

Complete the code to create an SQS queue named 'MyQueue'.

AWS
resource "aws_sqs_queue" "example" {
  name = [1]
}
Drag options to blanks, or click blank then click option'
A"MyTopic"
B"MyQueue"
C"MyBucket"
D"MyFunction"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the SNS topic name instead of the queue name.
Not using quotes around the name.
3fill in blank
hard

Fix the error in the subscription resource to connect the SNS topic to the SQS queue.

AWS
resource "aws_sns_topic_subscription" "example" {
  topic_arn = aws_sns_topic.example.arn
  protocol  = [1]
  endpoint  = aws_sqs_queue.example.arn
}
Drag options to blanks, or click blank then click option'
A"sqs"
B"http"
C"email"
D"lambda"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' or 'email' instead of 'sqs' as the protocol.
Using the queue URL instead of ARN for the endpoint.
4fill in blank
hard

Fill both blanks to allow the SNS topic to send messages to the SQS queue by setting the correct policy.

AWS
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]
        }
      }
    }]
  })
}
Drag options to blanks, or click blank then click option'
A"sqs:SendMessage"
B"sns:Publish"
Caws_sns_topic.example.arn
Daws_sqs_queue.example.arn
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sns:Publish' as the action instead of 'sqs:SendMessage'.
Using the queue ARN instead of the topic ARN in the condition.
5fill in blank
hard

Fill all three blanks to create a complete fan-out pattern with two SQS queues subscribed to one SNS topic.

AWS
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
}
Drag options to blanks, or click blank then click option'
A"FanOutTopic"
B"QueueOne"
C"MyQueue"
D"FanOutQueue"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same name for topic and queue.
Not matching queue names with subscription endpoints.