serverless-step-functions icon indicating copy to clipboard operation
serverless-step-functions copied to clipboard

500 Internal Server Error

Open motiejuss opened this issue 2 years ago • 1 comments

Bug Report

Description

Ran out of ideas where the actual error may be. I'm testing a very simple setup according to this article. Serverless builds fine and deploys fine.

When I test the endpoint from within API Gateway console, this is the output I get and everything seems to work fine:

Execution log for request e7fd711c-56f7-427e-8e58-87dbe5154193
Fri Jan 13 10:08:40 UTC 2023 : Starting execution for request: e7fd711c-56f7-427e-8e58-87dbe5154193
Fri Jan 13 10:08:40 UTC 2023 : HTTP Method: POST, Resource Path: /schedule
Fri Jan 13 10:08:40 UTC 2023 : Method request path: {}
Fri Jan 13 10:08:40 UTC 2023 : Method request query string: {}
Fri Jan 13 10:08:40 UTC 2023 : Method request headers: {}
Fri Jan 13 10:08:40 UTC 2023 : Method request body before transformations: {
    "dueDate": "2023-01-13T13:04:14.397Z"
}
Fri Jan 13 10:08:40 UTC 2023 : Endpoint request URI: https://states.eu-central-1.amazonaws.com/?Action=StartExecution
Fri Jan 13 10:08:40 UTC 2023 : Endpoint request headers: {Authorization=*****************************************************************************************************************************************************************************************************************************************************************************************270b51, X-Amz-Date=20230113T100840Z, x-amzn-apigateway-api-id=q4wi07nhcj, Accept=application/json, User-Agent=AmazonAPIGateway_q4wi07nhcj, X-Amz-Security-Token=IQoJb3JpZ2luX2VjEHoaDGV1LWNlbnRyYWwtMSJGMEQCIB7rsefFvEzfVHKXnxDHBrJbeAiABf+UzyOYW0qflCzr1USCNB3+rAF4b9lMFPi/Ir0SXmCruAgjT//////////8BEAMaDDMyNTQ1MzEyNTA1MiIMLWI1FLT3D/T/0ZSoKsICfQwQ+wURjQArtSA+UZmhRHZbhqScVfZ+X8uVBK/bkEDyj97aUZqIBr9rzDawkfq5LjnA4Si0aBrrLRcxnb2Xu7j3R4o9k2CRlaS7aAcgXMFmpVnVV/uDi5LXER777iRvBXIn2prwwvN3gdAx4H [TRUNCATED]
Fri Jan 13 10:08:40 UTC 2023 : Endpoint request body after transformations: 
{"input": "{\"dueDate\":\"2023-01-13T13:04:14.397Z\"}", "name": "e7fd711c-56f7-427e-8e58-87dbe5154193", "stateMachineArn":"arn:aws:states:eu-central-1:325453125052:stateMachine:services-scheduler"}
Fri Jan 13 10:08:40 UTC 2023 : Sending request to https://states.eu-central-1.amazonaws.com/?Action=StartExecution
Fri Jan 13 10:08:40 UTC 2023 : Received response. Status: 200, Integration latency: 91 ms
Fri Jan 13 10:08:40 UTC 2023 : Endpoint response headers: {x-amzn-RequestId=61be8d71-a46e-484e-8351-201c59584794, Date=Fri, 13 Jan 2023 10:08:40 GMT, Content-Type=application/x-amz-json-1.0, Content-Length=158}
Fri Jan 13 10:08:40 UTC 2023 : Endpoint response body before transformations: {"executionArn":"arn:aws:states:eu-central-1:325453125052:execution:services-scheduler:e7fd711c-56f7-427e-8e58-87dbe5154193","startDate":1.673604520313E9}
Fri Jan 13 10:08:40 UTC 2023 : Method response body after transformations: {"executionArn":"arn:aws:states:eu-central-1:325453125052:execution:services-scheduler:e7fd711c-56f7-427e-8e58-87dbe5154193","startDate":1.673604520313E9}
Fri Jan 13 10:08:40 UTC 2023 : Method response headers: {X-Amzn-Trace-Id=Root=1-63c12da8-453982ec322ab5856186ef8b, Access-Control-Allow-Origin=*, Content-Type=application/json}
Fri Jan 13 10:08:40 UTC 2023 : Successfully completed execution
Fri Jan 13 10:08:40 UTC 2023 : Method completed with status: 200

If I test the endpoint from outside (postman or curl) I get the following sequence of logs (I have enabled REST API logging in serverless config):

..............
Method request body before transformations: [Binary Data]
Execution failed due to configuration error: Unable to transform request
Method completed with status: 500

There is no setup for authorization or api keys and other endpoints from the same setup execute just fine.

Example request I'm trying with curl:

curl --location --request POST 'https://[API_ID].execute-api.eu-central-1.amazonaws.com/stage/schedule' \
--header 'Content-Type: application/json' \
--data-raw '{
    "dueDate": "2023-01-13T13:04:14.397Z"
}'

Additional Data

  • Serverless Framework Core Version you're using: 3.22.0
  • The Plugin Version you're using: 3.11.1

motiejuss avatar Jan 13 '23 10:01 motiejuss

For others experiencing similar issue, it's because in our serverless config we have apiGateway -> binaryMediaTypes: ['*/*'] which basically means all incoming payload is binary.

Is there a way to convert it to text using body mapping template like described here? https://www.serverless.com/plugins/serverless-step-functions#customizing-request-body-mapping-templates

motiejuss avatar Jan 16 '23 09:01 motiejuss