Course menuDVA-C02

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

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

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

A networking CloudFormation stack creates a VPC and subnets. Several application stacks in the same account and Region must use the subnet IDs, and the developer wants CloudFormation to track the dependency so the networking stack cannot be deleted while it is in use. What should the developer do?

Choose one answer.

  1. A. In each application stack, use Ref with the logical ID of the subnet from the networking stack.
  2. B. Copy the subnet IDs into a Mappings section of each application template.
  3. C. Use Fn::GetAtt with the networking stack's name and the subnet's logical ID.
  4. D. Export the subnet IDs as outputs of the networking stack and use Fn::ImportValue in the application stacks.
Show the answer and explanation

Answer: D

  • A. Wrong: Ref only resolves resources and parameters in the same template.
  • B. Wrong: Hard-coded IDs go stale if the network changes, and CloudFormation would not record any dependency.
  • C. Wrong: Fn::GetAtt reads attributes of resources in the same template, not resources in another stack.
  • D. Right: Correct. Cross-stack references share values, and an exporting stack cannot be deleted while another stack imports its exports.

Explanation

Cross-stack references let one stack export output values and other stacks in the same account and Region import them with Fn::ImportValue. CloudFormation then blocks deletion of the exporting stack, and changes to the exported value, until all imports are removed.

Study

Keep practising

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