How to exclude new lines in InputTransformer template in EventBridge event rule

0

Hi all,

I have an EventBridge rule with an InputTransformer block that looks like:

InputTransformer:
  InputPathsMap:
    Id: "$.id"
    Source: "$.source"
    PublisherName: "$.source"
  InputTemplate: >-
      {
        "EventBridgeEventId": <Id>,
        "Source": <Source>,
        "PublisherName": <PublisherName>,
      }

The target of this event rule is an SQS queue. I can see that when the transformed event is ingested into the queue, it also contains the newlines from the above InputTemplate template:

{
  "Records": [
      {
          "messageId": "77a71036-bb28-4ece-9081-d94ec47a4486",
          "body": "{\n  \"EventBridgeEventId\": \"2gka6aad-45jk-23gh-8204-bn692392jda4\",\n  \"PublisherName\": \"some-publisher\",\n  \"Source\": \"some-publisher\"\n}",
          "eventSource": "aws:sqs",
          "awsRegion": "eu-west-1"
      }
  ]
}

Is it possible to have the above event rule InputTemplate exclude new line characters from the event that is sent to the target?

If I construct the InputTemplate as a single line like below, it works fine and new lines characters are not included in the event:

InputTransformer:
  InputPathsMap:
    Id: "$.id"
    Source: "$.source"
    PublisherName: "$.source"
  InputTemplate: >-
      {"EventBridgeEventId": <Id>,"PublisherName": <PublisherName>,"Source": <Source>}

Thank you in advance! Pierin

Pier
질문됨 2년 전945회 조회
1개 답변
0

That is exactly the way to do it. Do not include the new lines in the template to begin with.

profile pictureAWS
전문가
Uri
답변함 2년 전
  • Thanks for the answer, Uri!

    I have a long InputTemplate (the above was a simplified example) so keeping it as a single line doesn't help for readability. That's why I wanted to keep it in the above multi-line structure.

  • The issue is with your leading spaces. If you will change it to:

      InputTemplate: >-
          {
          "EventBridgeEventId": <Id>,
          "Source": <Source>,
          "PublisherName": <PublisherName>,
          }
    

    It should work. This is how YAML works.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠