Testing and Deployment

A CloudFormation template must create a Lambda function in every environment, but include its VpcConfig property only when a UseVpc condition is true. Which template approach meets this requirement?

Show the answer

Correct answerC. Use Fn::If for VpcConfig, returning AWS::NoValue when false.

AWhy not this: DependsOn controls resource creation order; it does not conditionally include properties or depend on conditions.

BWhy not this: A false resource-level condition prevents creation of the entire function rather than omitting only VpcConfig.

CWhy this is right: Fn::If selects the configuration or AWS::NoValue, which removes the property from the resource.

DWhy not this: An empty string is not an omitted property and does not satisfy VpcConfig's required object structure.

Fn::If can return a VPC configuration when the condition is true and AWS::NoValue when false, removing the property. A resource-level Condition would omit the entire function, violating the requirement to create it in every environment.