Eventbridge Pipe: SQS > EventBus - using sqs message body as event detail

0

I have a simple AWS EventBridge pipe: SQS > EventBus

The message body of the SQS message (which is a JSON object) should be the event detail of the EventBus event. But the input template (while working in the AWS console preview) causes the pipe execution to fail. No idea why

My pipe definition in CDK which would describe what I want to achieve:

    new pipes.CfnPipe(this, "pipe", {
      roleArn: pipeRole.roleArn,
      source: queue.queueArn,
      target: eventBus.eventBusArn,
      targetParameters: {
        eventBridgeEventBusParameters: {
          detailType: "FbaNotifcation",
          source: serviceName,
        },
        inputTemplate: `<$.body>`,
      },
    });

So inputTemplate: <$.body> does not work (execution fails). Omitting inputTemplate works, but produces a different result. Using {Payload: <$.body>} does not work, but also not ideal.

Is it not possible to create a top level object from JSON path with pipes?

  • Which is the error message that it is returning?

1 Answer
0

Based on your code, it seems you are trying to use AWS Pipes, which is a feature that allows data to be streamed from a source to a target. However, the issue here is that the inputTemplate is expecting a valid JSONPath expression. The JSONPath expression <$.body> might not be valid in this context. JSONPath expressions usually start with $, and they use dot notation or bracket notation to traverse the JSON structure.

In the case of SQS messages, the body of the message is not a top-level field in the message attributes, so it cannot be accessed directly with a JSONPath expression. Instead, you may need to use a Lambda function to transform the SQS message into the format that EventBridge requires.

Here is an example of how you can do this:

  1. Create a Lambda function that is triggered by SQS messages.
  2. In the Lambda function, parse the SQS message to extract the body.
  3. Format the body into the detail field of the EventBridge event.
  4. Use the AWS SDK to send the event to EventBridge.
profile picture
EXPERT
answered a year 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