Course menuDVA-C03

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

DVA-C03 practice question: AWS SAM, CloudFormation and CDK (1 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 developer maintains an AWS SAM template with twelve AWS::Serverless::Function resources.

Every function repeats the same Runtime and Timeout, and the same LOG_LEVEL environment variable. One function needs a longer Timeout than the others. The developer wants to declare the shared settings once and still allow that exception.

What should the developer do?

Choose one answer.

  1. A. Move the shared settings to a Globals section under the Function key, and set the longer Timeout on that one function.
  2. B. Move the shared settings to the Parameters section and reference them from each function with Ref.
  3. C. Move the shared settings to the Mappings section and read them in every function with Fn::FindInMap.
  4. D. Move the shared settings to the Outputs section so that each function can import them with Fn::ImportValue.
Show the answer and explanation

Answer: A

  • A. Right: Correct. Globals settings are inherited by every function of that type, and a value set on a resource replaces the global one for scalar properties such as Timeout. Environment variables are merged, so LOG_LEVEL stays shared. Learn more: SAM Globals section (opens in a new tab)
  • B. Wrong: Parameters hold values supplied at deploy time, but each function would still have to reference them, so the repetition stays. They are not a way to apply properties to many resources at once.
  • C. Wrong: Mappings are lookup tables, and every function would still need its own Fn::FindInMap lines. This reduces the values repeated but not the repeated declarations.
  • D. Wrong: Outputs publish values from a stack, usually for other stacks. They do not apply properties to resources in the same template.

Explanation

The SAM Globals section declares properties once for all resources of a type. A property set on a single resource overrides the global value for scalars like Timeout, and maps like environment variables are merged. Parameters, Mappings and Outputs still need a reference in every function.

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