DVA-C02 practice question 19 of 35
A company wants to automate part of its deployment process. A developer needs to automate the process of checking for and deleting unused resources…
Full set: 598 questionsDomain Troubleshooting and Optimization
The most seamless and efficient way to run custom logic during a deployment managed by the AWS Cloud Development Kit (AWS CDK) is to use a CDK custom resource. This approach allows the developer to define the Lambda function's handler code directly within the central CDK application. The custom resource construct then handles the creation of the Lambda function and its invocation during the CloudFormation stack lifecycle events (create, update, delete). This keeps all logic and infrastructure definition within a single, version-controlled application, meeting the requirements for seamless integration and minimal configuration.
A: Manually creating a CloudFormation template from a JSON file is redundant and counterintuitive when using the AWS CDK, which is designed to generate these templates programmatically. C: Introducing AWS Amplify and an API is overly complex for a task that needs to run during a deployment. This adds unnecessary components and configuration. D: Writing the Lambda function code in the console separates it from the infrastructure-as-code (IaC) in the CDK application, breaking the principle of a single source of truth and seamless integration.
1. AWS CDK Developer Guide - Custom Resources: "Sometimes you need to add AWS or third-party resources to your CDK app that aren't available in the AWS CloudFormation Registry. In these cases, you can use a custom resource. A custom resource is an AWS CloudFormation resource that is implemented by a Lambda function." This confirms that custom resources are the standard CDK mechanism for this scenario. (AWS Cloud Development Kit (AWS CDK) v2 Developer Guide, "Custom resources").
2. AWS CloudFormation User Guide - Custom Resources: "Custom resources enable you to write custom provisioning logic in templates that AWS CloudFormation runs during a stack operation... AWS CloudFormation invokes the function that's associated with the custom resource's service token." This explains the underlying mechanism that the CDK custom resource construct utilizes. (AWS CloudFormation User Guide, "Custom resources").
3. AWS CDK API Reference - aws-cdk-lib.customresources module: The documentation for the AwsCustomResource construct shows how it integrates with AWS SDK calls and is triggered on onCreate, onUpdate, or onDelete events, directly aligning with the question's need to run code when a stack is deployed. (AWS CDK API Reference, aws-cdk-lib.customresources module, AwsCustomResource class).
Keep practicing
Take the free DVA-C02 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other DVA-C02 practice questions
- Question 1A company has a multi-node Windows legacy application that runs on premises. The applicat…
- Question 2A developer migrated a legacy application to an AWS Lambda function. The function uses a …
- Question 3A development learn has an Amazon API Gateway REST API that is backed by an AWS Lambda fu…
- Question 4A company is expanding the compatibility of its photo-snaring mobile app to hundreds of a…
- Question 5A company has an ecommerce application. To track product reviews, the company's developme…
- Question 6A social media company is designing a platform that allows users to upload data, which is…
