Jeff’s Note #
Unlike generic exam dumps, ADH analyzes this scenario through the lens of a Real-World Lead Developer.
For AWS DVA-C02 candidates, the confusion often lies in how best to integrate custom code into CDK deployments with minimal overhead. In production, this is about knowing exactly how AWS CDK custom resources enable Lambda-driven automation tightly coupled to the deployment lifecycle. Let’s drill down.
The Certification Drill (Simulated Question) #
Scenario #
TechNimbus Solutions is a software company deploying hundreds of microservices across multiple AWS accounts using a central AWS CDK application. Over time, some resources originally provisioned for older versions of their infrastructure become unused and linger, leading to unnecessary costs. The development team wants to automate the detection and deletion of these unused resources during their deployment lifecycle. The solution should integrate smoothly with their existing AWS CDK deployment pipeline and require the least additional configuration to maintain.
The Requirement: #
Automate the detection and cleanup of orphaned resources as part of the stack deployment process with minimal configuration changes, leveraging the existing AWS CDK infrastructure and AWS Lambda.
The Options #
-
A) In the central AWS CDK app, write a Lambda handler using AWS SDK calls to check and delete unused resources. Create a CloudFormation template from JSON that attaches the function code to a Lambda function and invoke it within the deployment stack.
-
B) In the central AWS CDK app, write a Lambda handler using AWS SDK calls to check and delete unused resources. Create an AWS CDK custom resource to attach the function code to a Lambda function and invoke it during stack deployment.
-
C) In the central AWS CDK app, write a Lambda handler using AWS SDK calls to check and delete unused resources. Create an API in AWS Amplify and attach the Lambda function via the API to invoke during stack deployment.
-
D) In the AWS Lambda console, write a Lambda handler using AWS SDK calls to check and delete unused resources. Create an AWS CDK custom resource to import the Lambda function into the stack and invoke it during deployment.
Google adsense #
leave a comment:
Correct Answer #
B
Quick Insight: The Developer Imperative #
For AWS developers working with CDK, the power lies in leveraging custom resources which act as clean, declarative hooks into the CloudFormation lifecycle — allowing Lambda code to run exactly when stacks create, update, or delete. This avoids manual template maintenance (like raw JSON) and external API wiring (like Amplify). The CDK custom resource pattern is the least-config and most integrated approach.
Content Locked: The Expert Analysis #
You’ve identified the answer. But do you know the implementation details that separate a Junior from a Senior?
The Expert’s Analysis #
Correct Answer #
Option B
The Winning Logic #
Option B leverages AWS CDK custom resources, a native and idiomatic way within CDK to embed custom Lambda-backed logic into CloudFormation stacks. This means you can define your Lambda handler directly in your CDK code, deploy it as part of the stack, and invoke it automatically during stack lifecycle events — create, update, or delete. This tight integration requires minimal additional configuration because CDK manages packaging and deployment seamlessly.
- The Lambda function code is bundled and deployed by CDK as part of the custom resource construct.
- CloudFormation automatically invokes the Lambda handler during stack operations, so no manual invocation wiring is needed.
- The use of CDK custom resources avoids the complexity of managing raw CloudFormation JSON templates (A) or extraneous services like AWS Amplify (C).
- Writing the Lambda directly in the Lambda console and trying to import it into CDK (D) adds complexity and breaks the automation flow.
The Trap (Distractor Analysis) #
- Why not A? Creating a separate JSON CloudFormation template is more cumbersome and error-prone compared to using CDK’s native custom resource constructs. It adds manual template maintenance counter to CDK’s purpose.
- Why not C? AWS Amplify is designed primarily for front-end web and mobile app frameworks, not for internal infrastructure automation. Introducing Amplify for infrastructure tasks creates unnecessary complexity.
- Why not D? Developing Lambda functions outside CDK and importing them breaks the seamless deployment lifecycle and increases operational overhead.
The Technical Blueprint #
# Example snippet illustrating how to define a CDK custom resource using the AWS SDK for Lambda invocation
# In TypeScript CDK:
import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as cr from 'aws-cdk-lib/custom-resources';
const stack = new cdk.Stack();
// Lambda function to check and delete unused resources
const cleanupFunction = new lambda.Function(stack, 'CleanupFunction', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('lambda'), // your lambda code folder
});
// Custom resource provider backed by the Lambda function
const provider = new cr.Provider(stack, 'CleanupProvider', {
onEventHandler: cleanupFunction,
});
// Custom resource triggering the Lambda during stack events
new cdk.CustomResource(stack, 'CleanupCustomResource', {
serviceToken: provider.serviceToken,
});
The Comparative Analysis #
| Option | API Complexity | Performance | Use Case |
|---|---|---|---|
| A | Medium (manual CF JSON) | Moderate | Adds manual template management |
| B | Low (CDK native) | High (fully integrated) | Ideal for extending CDK with Lambda logic |
| C | High (Amplify setup) | Variable | Misaligned for infra tasks |
| D | Medium (manual import) | Moderate | Breaks CDK automation flow |
Real-World Application (Practitioner Insight) #
Exam Rule #
For the exam, always pick CDK Custom Resources when you need to run Lambda-backed logic tightly coupled with infrastructure deployments.
Real World #
In production, CDK custom resources reduce DevOps toil, enforce DRY principles by bundling infrastructure and code together, and provide consistent deployment lifecycle hooks.
(CTA) Stop Guessing, Start Mastering #
Disclaimer
This is a study note based on simulated scenarios for the AWS DVA-C02 exam.