aws-cdk
aws-cdk copied to clipboard
(cdk.aws_events): Unable to send XML (application/xml) via API Destinations
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
- The server should receive the XML message as raw XML without any additional double quotes or other modifications.
- The content-type and accept headers should be correctly set to
application/xml.
Current Behavior
- The XML message is being wrapped in double quotes, making it a JSON string instead of raw XML.
- 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 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 synthcommand (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
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
@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
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
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.