serverless-stack-demo-api icon indicating copy to clipboard operation
serverless-stack-demo-api copied to clipboard

500 error on running serverless invoke local

Open quantuminformation opened this issue 7 years ago • 14 comments

When running

$ serverless invoke local --function create --path mocks/create-event.json from https://serverless-stack.com/chapters/add-a-create-note-api.html

I get

{
    "statusCode": 500,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{\"status\":false}"
}

I added a log and get: { UnrecognizedClientException: The security token included in the request is invalid.

quantuminformation avatar Sep 22 '17 12:09 quantuminformation

@QuantumInformation Are you using multiple AWS credentials? Or do you have multiple credentials? This usually happens in that case.

jayair avatar Sep 22 '17 20:09 jayair

Yeah I have 2 profiles:

same error even with --profile personal

serverless-stack-demo-api git:(master) ✗ serverless invoke local --function create --path mocks/create-event.json --profile personal 
Serverless: Bundling with Webpack...
Time: 641ms
    Asset     Size  Chunks             Chunk Names
create.js  7.19 kB       0  [emitted]  create
   [0] ./create.js 2.81 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] external "uuid" 42 bytes {0} [not cacheable]
   [4] ./libs/dynamodb-lib.js 485 bytes {0} [built]
   [5] external "aws-sdk" 42 bytes {0} [not cacheable]
   [6] ./libs/response-lib.js 721 bytes {0} [built]
   [7] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
{ UnrecognizedClientException: The security token included in the request is invalid.

quantuminformation avatar Sep 22 '17 21:09 quantuminformation

@QuantumInformation The serverless invoke local command does not support the --profile option.

Did you specify the profile in your serverless.yml?

jayair avatar Sep 22 '17 22:09 jayair

Yup , get same error:

   [7] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
{ UnrecognizedClientException: The security token included in the request is invalid.
provider:
  name: aws
  runtime: nodejs6.10
  stage: prod
  region: eu-west-2
  profile: personal

and in ~/.aws/credentials:

[personal]
aws_access_key_id

for some reasons image uploads dont work

quantuminformation avatar Sep 25 '17 21:09 quantuminformation

@QuantumInformation Do these credentials have access to the DynamoDB that was previously created?

jayair avatar Sep 25 '17 21:09 jayair

[ Personal ] IAM user has the admin policy on this account.

Does invoke local do anything to the live AWS account and data?

quantuminformation avatar Sep 25 '17 21:09 quantuminformation

@QuantumInformation It invokes your Lambda function locally but any resources used inside it are the ones on live.

jayair avatar Sep 25 '17 22:09 jayair

I'm going to test the react app against the api, sls deploy worked

quantuminformation avatar Sep 25 '17 22:09 quantuminformation

Had this same problem. Changed region to my real ones in serverless.yml and create.js

luanau avatar Oct 14 '17 21:10 luanau

I also am seeing this error or something very similar. I tried to go ahead and deploy the serverless package and got the same error with Webpack. I'll keep digging, but wanted to post the issue I'm seeing.

[11:08:10]dcharling@us-c02tf23vg8wn:~/Personal/dev/scratch> serverless invoke local --function create --path mocks/create-event.json
Serverless: Bundling with Webpack...
Time: 604ms
          Asset  Size  Chunks             Chunk Names
notes/create.js  5 kB       0  [emitted]  notes/create
   [0] ./notes/create.js 2.16 kB {0} [built]
   [1] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
   [2] external "uuid" 42 bytes {0} [not cacheable]
   [3] external "aws-sdk" 42 bytes {0} [not cacheable]
{
    "statusCode": 500,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{\"status\":false}"
}

dougharling avatar Nov 01 '17 16:11 dougharling

@dougharling You can debug these by adding a console.log like so - https://serverless-stack.com/chapters/add-a-create-note-api.html#common-issues

jayair avatar Nov 01 '17 17:11 jayair

  1. click on your username on top nav, My Security Credentials
  2. Click on Access Key Tab, Create New, copy the key and secret.
  3. in terminal, run $ aws configure and use the new key and secret.
  4. Run the command again: serverless invoke local --function create --path mocks/create-event.json

enriqueheyhey avatar Nov 30 '18 22:11 enriqueheyhey

Yup , get same error:

   [7] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
{ UnrecognizedClientException: The security token included in the request is invalid.
provider:
  name: aws
  runtime: nodejs6.10
  stage: prod
  region: eu-west-2
  profile: personal

and in ~/.aws/credentials:

[personal]
aws_access_key_id

for some reasons image uploads dont work

Found the following steps to be the solution to the exact problem -

  1. Remove the current aws config and credentials by : sudo rm ~/.aws/config and sudo rm ~/.aws/credentials
  2. Recreate an access key for the User, from the IAM Console
  3. Reconfigure your AWS CLI with aws configure and make sure you put the correct region

Worked for me!

iamsaurabhc avatar Jan 07 '19 17:01 iamsaurabhc

I had this error. It was because I forgot to create the table in DynamoDB

mmjosedaniel avatar Jul 07 '20 20:07 mmjosedaniel