Search code examples
amazon-web-servicesaws-lambdaaws-step-functions

Is it possible to have an AWS Step Function wait until a RDS is deleted to continue?


Currently my end to end goal is to create a step function that is ran daily via Event Bridge.

The flow of the Step Function should be as follows:

  1. Delete current QA RDS via Lambda with waitForTaskToken.
  2. Return status of 200 if code deployed, 400 if not.
  3. Once the RDS is deleted send back the taskToken to Step Function.
  4. Step Function moves forward and creates new QA RDS from snapshot.

My issue is around step 3 of the process. How can I send back a taskToken to the Step Function after the completion of the deletion of the RDS?


Solution

  • How can I send back a taskToken to the Step Function after the completion of the deletion of the RDS?

    Send the task token to the Lambda via the task payload ("taskToken.$": "$$.Task.Token"). Once your Lambda has confirmed instance deletion (say, with DescribeDBInstances), call the SendTaskSuccess command with the token. This informs the Step Functions service that the task is done and the execution can continue. Otherwise, if the Lambda fails to confirm deletion, let Step Functions know by invoking SendTaskFailure with the token.

    Is it possible to have an AWS Step Function wait until a RDS is deleted to continue?

    Yes. Instance deletion is an asynchronous task. You have several options to architect waiting for the deletion to finish:

    1. Step Functions Lambda callback pattern: as in OP and above. Polling for deletion is the Lambda's responsibility.
    2. Step Functions Wait -> Lambda -> Choice loop: The State Machine is responsible for polling. Build a loop into the State Machine by chaining a Wait State, a regular request-response Lambda Task, and Choice State. Repeat until deletion has completed or a max iteration count is reached. See @John_Rotenstein's comment.
    3. Event-driven Orchestration Forget the wait. RDS emits a event when an instance is deleted. Create an Eventbridge rule that triggers your Recreate-Lambda upon deletion events. In other words, loosely couple the Delete-Lambda and the Recreate-Lambda with the asynchronous event pattern, rather than tightly coupling them in a State Machine.