0

I am using NodeJS AWS SDK textract for detecting image (image file dot PNG/JPG). It was working on AWS EC2. But it does not work in an AWS Lambda function.

There is response I get:

    {
        "err": {
            "message": "Request has unsupported document format",
            "code": "UnsupportedDocumentException",
            "time": "2019-12-07T08:49:52.788Z",
            "requestId": "fbd1cab5-d725-4f79-ac15-1f033e82aa79",
            "statusCode": 400,
            "retryable": false,
            "retryDelay": 37.87986431208581
        },
        "stack": "UnsupportedDocumentException: Request has unsupported document format\n    at Request.extractError (/var/task/node_modules/aws-sdk/lib/protocol/json.js:51:27)\n    at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)\n    at Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:78:10)\n    at Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:683:14)\n    at Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)\n    at AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)\n    at /var/task/node_modules/aws-sdk/lib/state_machine.js:26:10\n    at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:38:9)\n    at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:685:12)\n    at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:116:18)"
    }
theduck
  • 2,589
  • 13
  • 17
  • 23
  • Can you share the sample code that works on EC2 but fails on Lambda so as to assist you better? – aksyuma Dec 21 '19 at 10:43

1 Answers1

0

Seems like lambda is not invoke with JSON event, two possible reasons,

Better to show how you invoke the lambda

InvalidRequestContentException

The request body could not be parsed as JSON.

HTTP Status Code: 400

UnsupportedMediaTypeException

The content type of the Invoke request body is not JSON.

HTTP Status Code: 415

Lambda-API_Invoke

handle-errors-in-lambda-integration

Adiii
  • 54,482
  • 7
  • 145
  • 148