DOP-C02 SDLC Automation Practice Question
Network Topology
Refer to the exhibit. A CloudFormation stack has been deployed. A developer wants to use the S3 bucket name in a subsequent AWS CLI command. Which command will correctly retrieve the bucket name?
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
✓
aws cloudformation describe-stacks --stack-name my-stack --query "Stacks[0].Outputs[?OutputKey=='BucketName'].OutputValue" --output text
The developer can use the --query parameter with the describe-stacks command to extract the OutputValue for the specific OutputKey 'BucketName'. Option C uses the correct JMESPath syntax with the filter [?OutputKey=='BucketName'] to select the matching output and then retrieves its OutputValue. Option A attempts to list all S3 buckets and grep for 'my-stack', which is unreliable and not the intended method. Option B uses describe-stack-resources but incorrectly assumes the bucket name is a physical resource ID when it is actually an output value. Option D uses incorrect JMESPath syntax (single bracket with equality) which is invalid.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
aws s3 ls | grep my-stack
Why it's wrong here
Running `aws s3 ls` lists every S3 bucket in the account, then `grep my-stack` only pattern-matches bucket names containing 'my-stack'. This approach does not query CloudFormation at all, so it ignores the stack's declared `BucketName` output and any resources created outside S3; it also breaks if the bucket name differs from the stack name or if permissions restrict `s3:ListAllMyBuckets`. It is a brittle manual workaround, not a reliable API call tied to the stack.
- ✗
aws cloudformation describe-stack-resources --stack-name my-stack --logical-resource-id BucketName --query "StackResources[0].PhysicalResourceId" --output text
Why it's wrong here
This command retrieves the physical resource ID of the resource with logical ID 'BucketName', which is the bucket name. However, the exhibit shows outputs, not resources. Both could work, but the question asks based on the exhibit which shows outputs. Option A is more direct given the exhibit.
- ✓
aws cloudformation describe-stacks --stack-name my-stack --query "Stacks[0].Outputs[?OutputKey=='BucketName'].OutputValue" --output text
Why this is correct
This command is correct because it uses `aws cloudformation describe-stacks` to retrieve the stack's metadata, then JMESPath `Stacks[0].Outputs[?OutputKey=='BucketName'].OutputValue` filters the outputs array for the output whose `OutputKey` exactly equals `BucketName` and extracts its `OutputValue`. The `--output text` renders the result as plain text (the actual bucket name). This directly matches the exhibit, which shows the stack's outputs, and is the intended way to programmatically retrieve a CloudFormation output value.
- ✗
aws cloudformation describe-stacks --stack-name my-stack --query "Stacks[0].Outputs[OutputKey='BucketName'].OutputValue" --output text
Why it's wrong here
This command fails because the JMESPath filter expression is invalid. In JMESPath, filtering an array uses the syntax `[?condition]` (e.g., `[?OutputKey=='BucketName']`), not bare brackets `[OutputKey=...]`. Additionally, the comparison operator must be `==`, not a single `=`, so the query `Outputs[OutputKey='BucketName']` will cause a JMESPath parse error or return no results. Even if `--query` syntactically accepted it, `--output text` would not produce the intended output, so this is incorrect.
Visual reference
Quick reference
AWS S3 Storage Class Comparison
| Storage Class | Min Duration | Retrieval | Use Case |
|---|---|---|---|
| S3 Standard | None | Immediate | Frequently accessed data |
| S3 Standard-IA | 30 days | Immediate | Infrequent access, rapid retrieval |
| S3 One Zone-IA | 30 days | Immediate | Non-critical infrequent data |
| S3 Intelligent-Tiering | None | Immediate–hours | Unknown or changing access patterns |
| S3 Glacier Instant | 90 days | Milliseconds | Archive with instant retrieval |
| S3 Glacier Flexible | 90 days | Minutes–hours | Archive, flexible retrieval |
| S3 Glacier Deep Archive | 180 days | Hours | Long-term compliance archive |
Go deeper
Related to this question
About these practice questions
Courseiva writes every DOP-C02 question from scratch — 1,013 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DOP-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 DOP-C02 exam.