Api Gateway Step Functions integration - xml payload problem

110 Views Asked by At

I'm a bit struggling with Api Gateway Step Functions integration. This snippet of my integration:

export const integration = (stateMachineArn: string, accessRole: Role): AwsIntegration =>
  new AwsIntegration({
    service: 'states',
    integrationHttpMethod: 'POST',
    action: 'StartExecution',
    options: {
      credentialsRole: accessRole,
      requestTemplates: {
        'application/xml': JSON.stringify({
          stateMachineArn,
          input: JSON.stringify({
            requestId: '$context.requestId',
            xml: '$input.body',
          }),
        }),
      },
      integrationResponses: [
        {
          statusCode: '200',
          responseTemplates: {
            'application/xml': `
            <ID>$context.requestId</ID>
          `,
          },
        },
      ],
    },
  });

API Gateway exposes POST endpoint which consumes application/xml content type. I need to pass it to step functions, but exactly this line does not work:

xml: '$input.body',

I see in API Gateway logs that the content is properly recognized:

(0dc586c4-a266-48d6-9df7-00793c068230) Endpoint request body after transformations: 
{
    "stateMachineArn": "arn:aws:states:eu-central-1:9999999999999:stateMachine:my-best-state-machine",
    "input": "{\"requestId\":\"0dc586c4-a266-48d6-9df7-00793c068230\",\"xml\":\"\\\"<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>\\\"\"}"
}

But I'm getting 400 when passing to step functions state machine.

Is this a matter of xml characters? Shouldn't I convert or transform it somehow to successfully pass it to underlaying integration?

According to the official docs: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html it should just return raw request payload as string. Not sure what to do more here. Anyone can help?

0

There are 0 best solutions below