Exams / DVA-C02 / AWS SAM, CloudFormation and CDK / Question 1
DVA-C02 practice question: AWS SAM, CloudFormation and CDK (1 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.
An AWS SAM template defines twelve functions. Each one repeats the same Timeout and the same LOG_LEVEL environment variable, for example:
Transform: AWS::Serverless-2016-10-31
Resources:
OrdersFunction:
Type: AWS::Serverless::Function
Properties:
Timeout: 30
Environment:
Variables:
LOG_LEVEL: INFO
How can the developer declare these settings once for all functions?
Choose one answer.
- AA. Move them into the Parameters section and reference them from each function.
- BB. Move them into the Mappings section keyed by function name.
- CC. Move them into a Globals section under the Function key.
- DD. Move them into the Outputs section so other resources can import them.
Show the answer and explanation
Answer: C
- A. Wrong: Parameters still have to be referenced in every function, so the repetition remains.
- B. Wrong: Mappings are lookup tables that still need a lookup in each function. They do not apply settings automatically.
- C. Right: Correct. Every AWS::Serverless::Function inherits properties declared in Globals, and a function can still override them.
- D. Wrong: Outputs return values from a stack. They do not set properties on resources.
Explanation
The Globals section of a SAM template declares properties shared by serverless resources such as functions and APIs. Resources inherit them. Primitive values can be overridden per resource, maps such as environment variables are merged, and lists are added to.
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.