InputTransformer YAML not resolving for event rule

Viewed 429

I am aiming to send following format to the data:

{
  "headers": {
    "Authorization": "Bearer expectedToken"
  },
  "body": {
    "id": "abc",
    "status": "ANY",
    "preferences": [ [Object] ]
  }
}

but struggling with the Input transformer in YAML:

inputTransformer:
  inputPathsMap:
    expectedToken: '$detail.metadata.someToken'
  inputTemplate: '{"headers": {"Authorization": <expectedToken>}}'

And getting this error:

Received response status [FAILED] from custom resource. Message returned: Event pattern is not valid. Reason: "expectedToken" must be an object or an array+ +at [Source: (String)"{"inputTransformer":{"inputPathsMap":{"expectedToken":"$detail.metadata.someToken"},"inputTemplate":"{"headers": {"Authorization": }}"},"

Trigger is an APIGW with a mapping template that appends a Auth token as part of the metadata, but the target expects it as a header. Is it a viable solution? How can this be resolved to the expected format?

Later Edit: Data being sent from APIGW:

 {
    detail: {
        body: {
          id: 'abc',
          extraInfo: 'Postman_15:07',
          preferences: [Array]
        },
        metadata: {
          service: 'my-service',
          status: 'ANY',
          someToken: 'Bearer expectedToken'
        }
      }
}
3 Answers

Could you share an example (scrubbed of personal info) of your event payload - ie the JSON that has the detail, and metadata sub-fields?

You could also try

inputTransformer:
  inputPathsMap:
    expectedToken: '$detail.metadata.someToken'
  inputTemplate: '{"headers": {"Authorization": "Bearer <expectedToken>"}}'

Try it out with an input-path like $.detail.metadata.someToken

If this also doesn't work, as already asked for, give us an example of the event that arrives at the EventBridge itself. If you don't know the event payload you can setup an event rule that forwards the event to a CloudWatch log group so that you can check the logs. (tip: setup the cloudwatch target via AWS console, afaik there are some issues using CloudFormation for this)

Thank you for the suggestions. It looks like the issue was with indentation of the inputTransformer section under eventbridge. That error message was by no means helpful. Final format to match what the target Lambda was expecting was :

 inputTransformer:
      inputPathsMap:
        expectedToken: '$detail.metadata.someToken'
        data: '$.detail.body'
      inputTemplate: '{"headers": {"Authorization": <expectedToken>}, "body": <data>}'
Related