2

This question resolves how to fix serializaion errors caused by a bad template, but if they are cause by input errors like a missing param, they are returned with a 200.

I'm trying to add a response template for errors using the CDK on an DynamoDb integration

 read_integration_responses=[aws_apigateway.IntegrationResponse(
                        status_code="200",
                        response_templates= {"application/json":read_response_template}),
                        aws_apigateway.IntegrationResponse(status_code="400",
                                                            response_templates={"text/html": "Client Error"},
                                                             selection_pattern="400" )
                        ])

The 200 works fine, but I get a 500 server error when I have an error. The logs are no help:

Fri Feb 10 21:37:37 UTC 2023 : Sending request to https://dynamodb.us-east-1.amazonaws.com/?Action=Query Fri Feb 10 21:37:37 UTC 2023 : Received response. Status: 400, Integration latency: 6 ms Fri Feb 10 21:37:37 UTC 2023 : Endpoint response headers: {Server=Server, Date=Fri, 10 Feb 2023 21:37:37 GMT, Content-Type=application/x-amz-json-1.0, Content-Length=60, Connection=keep-alive, x-amzn-RequestId=HB4E7S3FS0NIMM44OQRN6RPBEBVV4KQNSO5AEMVJF66Q9ASUAAJG, x-amz-crc32=3948637019} Fri Feb 10 21:37:37 UTC 2023 : Endpoint response body before transformations: {"__type":"com.amazon.coral.service#SerializationException"} Fri Feb 10 21:37:37 UTC 2023 : Execution failed due to configuration error: Output mapping refers to an invalid method response: 400 Fri Feb 10 21:37:37 UTC 2023 : Method completed with status: 500

Per the method documentation selection_pattern is a string that matches the response code.

fedonev
  • 20,327
  • 2
  • 25
  • 34
MikeF
  • 764
  • 9
  • 26

0 Answers0