Getting 500 status code


#1

I’m running

AWS_PROFILE=dev serverless invoke local --function create --path mocks/create-event.json

and I’m getting below response

Serverless: Bundling with Webpack...
Time: 2157ms
Built at: 2018-09-30 20:47:16
        Asset      Size  Chunks             Chunk Names
    create.js  7.22 KiB  create  [emitted]  create
create.js.map  7.11 KiB  create  [emitted]  create
Entrypoint create = create.js create.js.map
[./create.js] 2.14 KiB {create} [built]
[aws-sdk] external "aws-sdk" 42 bytes {create} [built]
[babel-runtime/core-js/json/stringify] external "babel-runtime/core-js/json/stringify" 42 bytes {create} [built]
[source-map-support/register] external "source-map-support/register" 42 bytes {create} [built]
[uuid] external "uuid" 42 bytes {create} [built]
Serverless: INVOKING INVOKE
{
    "statusCode": 500,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{\"status\":false}"
}

#2

@vaidehip try adding a console.log(e) in the catch of the try block.

catch(e) {
 console.log(e);
 callback(null, failure({status: false}));

}

That should give you a clue as to why your getting the 500 error.

Mike


#3

Hi !!
I’m in the same situation and i add the console.log(e); and this is the response:

serverless invoke local --function create --path mocks/create-event.json
Serverless: Bundling with Webpack…
Time: 827ms
Built at: 2018-10-31 21:38:11
Asset Size Chunks Chunk Names
create.js 9.36 KiB create [emitted] create
create.js.map 6.56 KiB create [emitted] create
Entrypoint create = create.js create.js.map
[./create.js] 2.4 KiB {create} [built]
[./libs/dynamodb-lib.js] 468 bytes {create} [built]
[./libs/response-lib.js] 762 bytes {create} [built]
[aws-sdk] external “aws-sdk” 42 bytes {create} [built]
[babel-runtime/core-js/json/stringify] external “babel-runtime/core-js/json/stringify” 42 bytes {create} [built]
[babel-runtime/helpers/asyncToGenerator] external “babel-runtime/helpers/asyncToGenerator” 42 bytes {create} [built]
[babel-runtime/regenerator] external “babel-runtime/regenerator” 42 bytes {create} [built]
[source-map-support/register] external “source-map-support/register” 42 bytes {create} [built]
[uuid] external “uuid” 42 bytes {create} [built]
Serverless: INVOKING INVOKE
{ ResourceNotFoundException: Requested resource not found
at Request.extractError (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\protocol\json.js:48:27)
at Request.callListeners (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\sequential_executor.js:105:20)
at Request.emit (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\sequential_executor.js:77:10)
at Request.emit (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\request.js:683:14)
at Request.transition (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\request.js:22:10)
at AcceptorStateMachine.runTo (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\state_machine.js:14:12)
at C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\state_machine.js:26:10
at Request. (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\request.js:38:9)
at Request. (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\request.js:685:12)
at Request.callListeners (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\sequential_executor.js:115:18)
at Request.emit (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\sequential_executor.js:77:10)
at Request.emit (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\request.js:683:14)
at Request.transition (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\request.js:22:10)
at AcceptorStateMachine.runTo (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\state_machine.js:14:12)
at C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\state_machine.js:26:10
at Request. (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\request.js:38:9)
at Request. (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\request.js:685:12)
at Request.callListeners (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\sequential_executor.js:115:18)
at callNextListener (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\sequential_executor.js:95:12)
at IncomingMessage.onEnd (C:\Projects\serverless-stack-demo-api\node_modules\aws-sdk\lib\event_listeners.js:269:13)
at IncomingMessage.emit (events.js:187:15)
at IncomingMessage.EventEmitter.emit (domain.js:442:20)
at endReadableNT (_stream_readable.js:1081:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
message: ‘Requested resource not found’,
code: ‘ResourceNotFoundException’,
time: 2018-10-31T20:38:12.713Z,
requestId: ‘0UB2831NJGVNUCEHFJBGA3V1BBVV4KQNSO5AEMVJF66Q9ASUAAJG’,
statusCode: 400,
retryable: false,
retryDelay: 45.64612865975057 }
{
“statusCode”: 500,
“headers”: {
“Access-Control-Allow-Origin”: “*”,
“Access-Control-Allow-Credentials”: true
},
“body”: “{“status”:false}”
}


#4

@vaidehip @mas57es Hey guys, I had the same problem. It has to deal with AWS’s sdk. You have to fix the aws config and credentials files. I run linux, so I ran “ls ~/.aws” to view the files and change as admin (“sudo nano file”). Change to the desired IAM. (https://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html). This should fix it.


#5

It looks like it is complaining about some resource not being found. Most likely that is your DyanmoDB table. Can you ensure that it has been created properly?