Retry of Messages Using Amazon EventBridge Pipes, Amazon SQS, And AWS Step Functions
Tags: serverless, eventbridge, stepfunctions, sqs
Published: 2023-01-16 19:21:29


Amazon Eventbridge Pipes was launched on the last re: invent 2022. Amazon EventBridge Pipes allows you to glue different AWS services and optionally filter or enrich the structure of the events passed from consumers to producers.

You can use an SQS queue as a source of the Amazon EventBridge Pipe and an AWS Step Function as a target.

I attached a DLQ to the SQS source, [but reading the documentation it was not clear to me when the message was going to be sent to the DLQ](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes-error-troubleshooting.html), so I decide to give it a try myself.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/utdhiqn6zykgr05jamhn.png)

When the Amazon EventBridge Pipe is created with a State Machine as a target, it is required to [set the type of Invocation as FIRE_AND_FORGET or REQUEST_RESPONSE.](https://docs.aws.amazon.com/eventbridge/latest/pipes-reference/API_PipeTargetStateMachineParameters.html#eventbridge-Type-PipeTargetStateMachineParameters-InvocationType)


### Standard workflows

For Standard workflows, the only type of Invocation allowed is the FIRE_AND_FORGET which means that[ EventBridge doesn’t wait for a response before proceeding](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes.html#pipes-invocation). I set up a Standard Workflow with a Lambda which throw an error when it was invoked.

The Standard Workflow was failing, but the Amazon EventBridge Pipe was not aware of the executions and counted each one of the invocations as successful. I polled the messages of the DLQ over various minutes through the AWS Console, but the DLQ did not have any messages.


<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/skzvgb4qpl4bny0a7y73.png">
  <figcaption>The workflow was failing</figcaption>
</figure>


<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40xtfyz301gknsxhvwyl.png">
  <figcaption>But no Executions errors appeared on the Pipe
</figcaption>
</figure>


<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h79b6cupot47obis4a2f.png">
  <figcaption>The DLQ was empty
</figcaption>
</figure>


### Express workflows

For the test with an Express workflow, I set up the workflow as invocation type REQUEST_RESPONSE. The Amazon EventBridge Pipe this time was aware of the FailedExecutions and it did not take too much time until the messages started appearing in the DLQ. This means that the failed messages were able to be re-driven to the original source queue.

<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2vkspsds725js12faudt.png">
  <figcaption>The EventBridgePipe showed the Failed Executions for Express workflows
</figcaption>
</figure>

<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqpo19tsloqcmdgkmdix.png">
  <figcaption>The messages started appearing in the DLQ
</figcaption>
</figure>

### Summary

A message will never arrive in the DLQ attached to an SQS if we use SQS as a source of the Amazon EventBridge Pipes and a Standard Workflow as a target.

Hopefully in the future, the EventBridge team will make this possible. [But nowadays this does not help in the evolution to an asynchronous world.](https://youtu.be/RfvL_423a-I?t=3)