aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.5k stars 3.84k forks source link

(cdk.aws_events): Unable to send XML (application/xml) via API Destinations #30704

Closed dobeerman closed 3 weeks ago

dobeerman commented 2 months ago

Describe the bug

Our server is configured to accept only XML messages. In our application, we send an object where one of the attributes contains an XML message. However, when using AWS EventBridge API Destinations, the XML message is being wrapped in double quotes, leading to incorrect formatting that the server cannot parse correctly.

Below the transformation we use:

rule.addTarget(
  new destinations.ApiDestination(apiDestination, {
    pathParameterValues: destination.pathParameterValues,
    retryAttempts: 3,
    event: events.RuleTargetInput.fromEventPath("$.detail.xml"),
    headerParameters: {
      "content-type": "application/xml",
      accept: "application/xml",
    },
  }),
);

Expected Behavior

  1. The server should receive the XML message as raw XML without any additional double quotes or other modifications.
  2. The content-type and accept headers should be correctly set to application/xml.

Current Behavior

  1. The XML message is being wrapped in double quotes, making it a JSON string instead of raw XML.
  2. The server is unable to parse the incorrectly formatted XML payload.

Reproduction Steps

Configure an EventBridge rule to send an event with an XML payload in one of its attributes. Use the current transformation method to target an API Destination. Observe that the server receives the XML payload wrapped in double quotes.

Possible Solution

Investigate a method to transform and send the XML content as raw XML without any additional wrapping or formatting. Ensure that the content-type and accept headers are correctly set for XML.

{
  "EventBusName": "example-event-bus",
  "Source": "com.example.source",
  "DetailType": "ExampleDetailType",
  "Detail": "{\"attribute\":\"value\", \"xml\":\"<root><child>content</child></root>\"}"
}

Additional Information/Context

This issue prevents the server from correctly processing XML messages, which can lead to failed requests and disrupted workflows.

CDK CLI Version

2.147.2

Framework Version

No response

Node.js Version

v20.10.0

OS

*nix

Language

TypeScript

Language Version

5.4.5

Other information

No response

ashishdhingra commented 2 months ago

@dobeerman Good afternoon. Could you please share the following:

Per RuleTargetInput.fromEventPath takes the event target input from a path in the event JSON, which would be an escaped string. So I'm unsure if this is a CDK issue.

Thanks, Ashish

dobeerman commented 2 months ago

Hi @ashishdhingra Thank you for the swift reply.

Target settings:

Input to target:       Part of the matched event       "$.detail.xml"
Additional parameters: PathParameterValues: ["$.detail.teamId","$.detail.userId","$.detail.orderId"]
HeaderParameters:
     accept: application/xml
     content-type: application/xml
Dead-letter queue (DLQ): -
Retry policy:
     24h
     Retry attempts: 3

API Destination: Active / Authorized

ashishdhingra commented 3 weeks ago

@dobeerman Apologies for late response. Please let us know if you are able to get workaround this issue. As mentioned in my previous comment, per RuleTargetInput.fromEventPath takes the event target input from a path in the event JSON, which would be an escaped string.

Thanks, Ashish

dobeerman commented 3 weeks ago

Please let us know if you are able to get workaround this issue.

Hey @ashishdhingra,

Unfortunately, I couldn't find a workaround, so I had to write a Lambda function instead. And I know, this is not an issue of CDK, and CloudFormation itself.

cheers, alex

github-actions[bot] commented 3 weeks ago

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.