serverless-stack-demo-api
serverless-stack-demo-api copied to clipboard
500 error on running serverless invoke local
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 Are you using multiple AWS credentials? Or do you have multiple credentials? This usually happens in that case.
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 The serverless invoke local
command does not support the --profile
option.
Did you specify the profile in your serverless.yml
?
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 Do these credentials have access to the DynamoDB that was previously created?
[ Personal ] IAM user has the admin policy on this account.
Does invoke local do anything to the live AWS account and data?
@QuantumInformation It invokes your Lambda function locally but any resources used inside it are the ones on live.
I'm going to test the react app against the api, sls deploy
worked
Had this same problem. Changed region to my real ones in serverless.yml and create.js
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 You can debug these by adding a console.log
like so - https://serverless-stack.com/chapters/add-a-create-note-api.html#common-issues
- click on your username on top nav, My Security Credentials
- Click on Access Key Tab, Create New, copy the key and secret.
- in terminal, run $ aws configure and use the new key and secret.
- Run the command again: serverless invoke local --function create --path mocks/create-event.json
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 -
- Remove the current aws config and credentials by :
sudo rm ~/.aws/config
andsudo rm ~/.aws/credentials
- Recreate an access key for the User, from the IAM Console
- Reconfigure your AWS CLI with
aws configure
and make sure you put the correct region
Worked for me!
I had this error. It was because I forgot to create the table in DynamoDB