DVA-C02 · Question #260
A developer is building a new application that will be deployed on AWS. The developer has created an AWS CodeCommit repository for the application. The developer has initialized a new project for…
The correct answer is B. Use the CDK assertions module to integrate unit tests with the application. Run the unit tests in a E. Use the CDK Aspects class to create custom rules to apply to the CDK application. Fall the stack. The CDK assertions module enables unit testing of synthesized CloudFormation templates, and CDK Aspects allow applying custom validation rules across all constructs in an application.
Question
A developer is building a new application that will be deployed on AWS. The developer has created an AWS CodeCommit repository for the application. The developer has initialized a new project for the application by invoking the AWS Cloud Development Kit (AWS CDK) cdk init command. The developer must write unit tests for the infrastructure as code (IaC) templates that the AWS CDK generates. The developer also must run a validation tool across all constructs in the CDK application to ensure that critical security configurations are activated. Which combination of actions will meet these requirements with the LEAST development overhead? (Choose two.)
Options
- AUse a unit testing framework to write custom unit tests against the cdk.out file that the AWS CDK
- BUse the CDK assertions module to integrate unit tests with the application. Run the unit tests in a
- CUse the CDK runtime context to set key-value pairs that must be present in the cdk.out file that
- DWrite a script that searches the application for specific key configuration strings. Configure the
- EUse the CDK Aspects class to create custom rules to apply to the CDK application. Fall the stack
How the community answered
(35 responses)- A17% (6)
- B66% (23)
- C6% (2)
- D11% (4)
Why each option
The CDK assertions module enables unit testing of synthesized CloudFormation templates, and CDK Aspects allow applying custom validation rules across all constructs in an application.
Writing custom tests directly against the cdk.out file requires parsing raw CloudFormation JSON manually, which has significantly higher development overhead than using the built-in assertions module.
The CDK assertions module (aws-cdk-lib/assertions) provides fine-grained assertions against synthesized CloudFormation templates, integrating natively with testing frameworks like Jest or pytest with minimal setup overhead.
CDK runtime context (context key-value pairs) is used for lookups and configuration values at synthesis time, not for validating the content of synthesized templates.
Writing a custom script to grep for configuration strings is brittle, requires ongoing maintenance, and has much higher development overhead than using native CDK tooling.
CDK Aspects implement the visitor pattern, traversing every construct in the CDK app tree to enforce custom rules or security checks. Using cdk.Aspects.of(stack).add() applies the validation globally, meeting the requirement with no additional tooling.
Concept tested: AWS CDK unit testing with assertions module and Aspects for validation
Source: https://docs.aws.amazon.com/cdk/v2/guide/testing.html
Community Discussion
No community discussion yet for this question.