Is there a way to conditionally trigger the delete API on custom resources formed using the cloudformation template?

0

Hi. My use case requires that I'll be onboarding an AWS account onto my platform and for that I'll be creating some aws as well as custom resources. These custom resources will be calling my lambda function which will point to the respective add API in backend. After successful onboarding, if I onboard that same account again, the backend checks should throw an error that says account is already onboarded and this will trigger the delete api automatically in the rollback process. What if, through my cloudformation template I want to stop the delete API call just in this case as a conditional requirement? Or is there a way to do it by changing the execution of my lambda functions? If there are any examples or solutions that you can point me to it'd be of a great help. Thanks.

1 Answer
0

The DELETE operation will be invoked only for resources that have been created. Add a check in your lambda function to verify if the account has already been on-boarded and return a FAILED status in such case. This causes the stack creation to fail and triggers the rollback of anything that has been created. By putting the custom resource that does the check as dependency of all the other resources in the stack, you avoid the creation of any further resource unless the custom resource succeeds.

EXPERT
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions