DVA-C02 Development with AWS Services Practice Question
Exhibit
Refer to the exhibit.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"MyQueue": {
"Type": "AWS::SQS::Queue",
"Properties": {
"QueueName": "my-queue",
"RedrivePolicy": {
"deadLetterTargetArn": "arn:aws:sqs:us-east-1:123456789012:my-dlq",
"maxReceiveCount": 5
}
}
},
"MyDLQ": {
"Type": "AWS::SQS::Queue",
"Properties": {
"QueueName": "my-dlq"
}
}
}
}A developer creates the CloudFormation stack with the template above. After the stack is created, messages that are not processed after 5 receives are moved to the DLQ. However, the developer notices that the RedrivePolicy references a queue ARN that is hardcoded. What is the best practice to avoid this hardcoded ARN?
⚠ Common exam trap
Many candidates confuse `Ref` (which returns the QueueName or Queue URL) with `Fn::GetAtt` (which returns the ARN), leading them to choose Option A or attempt manual ARN construction with `Fn::Sub`.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use Fn::GetAtt with "Arn" attribute on the DLQ resource.
`Fn::GetAtt` with the `Arn` attribute retrieves the actual Amazon Resource Name (ARN) of the Dead Letter Queue (DLQ) resource dynamically at stack creation time. This avoids hardcoding the ARN, making the template portable across accounts and regions. The RedrivePolicy property requires the full ARN of the DLQ, and `Fn::GetAtt` is the intrinsic function designed to return resource attributes like ARN.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use Ref to reference the DLQ's QueueName and construct the ARN.
Why it's wrong here
Ref for an AWS::SQS::Queue resource returns the queue's URL (e.g., https://sqs.us-east-1.amazonaws.com/123456789012/my-queue), not its ARN directly. While the queue name is part of the URL, constructing a valid ARN from this URL or just the queue name returned by Ref would still require manually concatenating other ARN components like the AWS account ID and region, which is error-prone and defeats the purpose of dynamic referencing. This approach does not provide the full ARN in a usable format.
- ✗
Use Fn::Sub to substitute the queue name into a hardcoded ARN template.
Why it's wrong here
Using Fn::Sub to construct the ARN would involve creating a template string like arn:aws:sqs:${AWS::Region}:${AWS::AccountId}:${QueueName}. While Fn::Sub can resolve pseudo-parameters like AWS::Region and AWS::AccountId, and substitute a Ref'erenced QueueName, this method still relies on knowing the exact ARN format and explicitly providing all its components. It is less direct and more prone to errors if the ARN structure changes or if the goal is simply to retrieve the complete ARN attribute of an existing resource without manual string assembly.
- ✗
Use Fn::ImportValue to import the DLQ ARN from another stack.
Why it's wrong here
Fn::ImportValue is designed exclusively for retrieving values that have been explicitly Fn::Exported from *other* CloudFormation stacks. Since the Dead-Letter Queue (DLQ) is being created and defined within the *same* CloudFormation template, its attributes, including its ARN, are directly accessible within that template. Therefore, attempting to use Fn::ImportValue to reference a resource within the same stack is fundamentally incorrect and unnecessary.
- ✓
Use Fn::GetAtt with "Arn" attribute on the DLQ resource.
Why this is correct
Fn::GetAtt is the correct and most robust intrinsic function for retrieving a specific attribute from a resource defined within the same CloudFormation template. For an AWS::SQS::Queue resource, the Arn attribute directly provides the complete Amazon Resource Name (ARN) of the queue. This approach dynamically fetches the fully qualified ARN, eliminating the need for hardcoding account IDs, regions, or manual string construction, ensuring accuracy and portability across environments.
Go deeper
Related to this question
About these practice questions
One of 724 original DVA-C02 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DVA-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DVA-C02 exam.