Course menuDVA-C03

Exams / DVA-C03 / AWS SAM, CloudFormation and CDK / Question 3

DVA-C03 practice question: AWS SAM, CloudFormation and CDK (3 of 3)

Testing and Deployment A free question from our original DVA-C03 practice exam. Try it, then open the answer to see why each option is right or wrong.

Last verified against current AWS documentation ·How we write our questions

A security team's stack creates a customer managed AWS KMS key and its alias.

Five application stacks in the same account and Region each need the key's ARN. The team does not want the ARN typed into any template, and CloudFormation must refuse to delete the key stack while any application stack still uses the ARN.

What should the developer do?

Choose one answer.

  1. A. Copy the key ARN into a Mappings section of each of the five application templates.
  2. B. Nest the key template inside each application stack using AWS::CloudFormation::Stack.
  3. C. Use Fn::GetAtt in each application template, naming the key stack and its logical ID.
  4. D. Export the key ARN as an output, and import it with Fn::ImportValue in each stack.
Show the answer and explanation

Answer: D

  • A. Wrong: Mappings fix values inside each template, so the ARN is typed into five places and goes stale if the key is replaced. CloudFormation also records no link between the stacks, so it cannot block a delete of the key stack.
  • B. Wrong: Each nested stack creates its own key, so the application stacks would not share one key and one ARN. Nesting keeps the resources inside a parent stack, so there is no shared value for other stacks to import.
  • C. Wrong: Fn::GetAtt reads an attribute of a resource in the same template, so it cannot reach a resource in another stack. The template would fail to resolve the reference.
  • D. Right: Correct. An export shares an output with other stacks in the same account and Region. CloudFormation then refuses to delete the key stack, or change the exported ARN, until every importing stack has removed its import. Learn more: Get exported outputs from a deployed CloudFormation stack (opens in a new tab)

Explanation

Cross-stack references let one stack export an output value that other stacks in the same account and Region import with Fn::ImportValue. CloudFormation does not allow the exporting stack to be deleted, or its exported value changed, while another stack still imports it. Mappings copy the value into each template, and nested stacks belong to one parent stack, so neither gives a shared, protected value.

Study

Keep practicing

Answer questions with a score at the end, or practice just this topic with the explanation after each one. No sign-up needed.

Want more on AWS SAM, CloudFormation and CDK? The 5 full-length practice sets have 15 more AWS SAM, CloudFormation and CDK questions, 390 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets