A company uses a central AWS CDK application across multiple accounts to manage deployment stacks. A developer needs to automate detection and deletion of unused resources that supported previous stacks but are no longer needed. The solution must integrate smoothly with the existing CDK-based deployment flow and require the least configuration. Which approach satisfies these requirements?
Choose an answer
Tap an option to check your answer.
Correct answer: In the central AWS CDK application, add a handler function that uses the AWS SDK to detect and delete unused resources. Implement an AWS CDK custom resource that provisions an AWS Lambda function with the handler code and invokes it during stack deployment..
Why this is the answer
The correct approach is to use an AWS CDK custom resource. CDK custom resources allow you to extend CloudFormation's capabilities by invoking a Lambda function during stack deployment, update, or deletion. This integrates seamlessly with the existing CDK-based deployment flow, as the Lambda function for detecting and deleting unused resources is provisioned and invoked directly within the stack. This requires minimal configuration because the custom resource handles the Lambda creation and invocation lifecycle. The first incorrect option involves generating a CloudFormation template from a JSON file and attaching the function code, which is less integrated and more manual than a CDK custom resource. The third incorrect option uses AWS Amplify, which is designed for front-end web and mobile applications and is not suitable for this backend resource management task. The fourth incorrect option suggests writing the handler in the Lambda console, which deviates from the "central AWS CDK application" requirement and makes the Lambda function external to the CDK stack's lifecycle management.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed