Serverless Error: The security token included in the request is invalid

Viewed 12066

when i type serverless deploy appear this error: ServerlessError: The security token included in the request is invalid.

7 Answers

I had to specify sls deploy --aws-profile in my serverless deploy commands like this:

sls deploy --aws-profile common

Create a new user in AWS (don't use the root key).

In the SSH keys for AWS CodeCommit, generate a new Access Key.

Copy the values and run this:

serverless config credentials --overwrite --provider aws --key bar --secret foo

sls deploy

enter image description here

In my case it was missing the localstack entry in the serverless file. I had everything that should be inside it, but it was all inside custom (instead of custom.localstack).

In my case, I added region to the provider. I suppose it's not read from the credentials file.

provider:
  name: aws
  runtime: nodejs12.x
  region: cn-northwest-1

In my case, multiple credentials are stored in the ~/.aws/credentials file.

And serverless is picking the default credentials.

So, I kept the new credentials under [default] and removed the previous credentials. And that worked for me.

enter image description here

to run the function from AWS you need to configure AWS with access_key_id and secret_access_key but to might get this error if you want to run the function locally so for that use this command

sls invoke local -f functionName

it will run the function locally not on aws

Related