Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
dobeerman opened this issue Jun 28, 2024 · 5 comments
Closed
Labels
@aws-cdk/aws-events Related to CloudWatch Events bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@dobeerman
Copy link

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

@dobeerman dobeerman added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 28, 2024
@github-actions github-actions bot added the @aws-cdk/aws-events Related to CloudWatch Events label Jun 28, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Jun 28, 2024

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

  • Self contained minimal CDK code to reproduce the issue.
    • What does you API destination looks like?
  • Output of cdk synth command (basically generated CloudFormation template)
  • After deployment of CDK stack, what does the target settings look like in AWS console?

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

@ashishdhingra ashishdhingra added p2 effort/medium Medium work item – several days of effort response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 28, 2024
@ashishdhingra ashishdhingra self-assigned this Jun 28, 2024
@dobeerman
Copy link
Author

dobeerman commented Jun 29, 2024

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

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 29, 2024
@ashishdhingra
Copy link
Contributor

@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

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 14, 2024
@ashishdhingra ashishdhingra removed their assignment Aug 14, 2024
@dobeerman
Copy link
Author

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 github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 15, 2024
@ashishdhingra ashishdhingra closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2024
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
@aws-cdk/aws-events Related to CloudWatch Events bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants