Which solution will meet these requirements with the LEAST amount of configuration?
In the central AWS CDK application, write a handler function in the code that uses AWS SDK calls to check for and delete unused resources. Create an AWS CloudFormation template from a JSON file. Use the template to attach the function code to an AWS Lambda function and to invoke the Lambda function when the deployment stack runs.
In the central AWS CDK application, write a handler function in the code that uses AWS SDK calls to check for and delete unused resources. Create an AWS CDK custom resource. Use the custom resource to attach the function code to an AWS Lambda function and to invoke the Lambda function when the deployment stack runs.
In the central AWS CDK, write a handler function in the code that uses AWS SDK calls to check for and delete unused resources. Create an API in AWS Amplify. Use the API to attach the function code to an AWS Lambda function and to invoke the Lambda function when the deployment stack runs.
In the AWS Lambda console, write a handler function in the code that uses AWS SDK calls to check for and delete unused resources. Create an AWS CDK custom resource. Use the custom resource to import the Lambda function into the stack and to invoke the Lambda function when the deployment stack runs.
Explanations:
This option suggests creating a CloudFormation template from a JSON file to attach a Lambda function, which introduces unnecessary complexity and deviates from the seamless integration within the AWS CDK. The CDK is designed to manage resources declaratively, and this approach complicates the process by requiring manual handling of templates.
This option utilizes the AWS CDK’s ability to create custom resources, allowing for a cleaner integration within the existing CDK application. The handler function can be directly attached to a Lambda function using CDK constructs, enabling automatic invocation during stack deployment with minimal configuration.
This option proposes creating an API in AWS Amplify to attach the Lambda function. However, this adds an unnecessary layer of complexity and management overhead, as the goal is to automate resource cleanup within the deployment process without the need for an API layer. This deviates from a direct integration approach.
This option suggests writing the handler function directly in the AWS Lambda console, which is not ideal as it removes the function from the CDK deployment lifecycle. The purpose of using CDK is to maintain all resources and their configurations within the code, which is not achieved by manually creating a Lambda function in the console. This option also adds complexity by needing a custom resource to import the Lambda function.