Steven Giraldo
Steven Giraldo

Reputation: 369

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

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

Upvotes: 17

Views: 20306

Answers (9)

Rubén
Rubén

Reputation: 1

If your credentials on ~/.aws/credentials file are fine. Delete line on your .yml config file

region: us-east-1

and try again

Upvotes: 0

J.dev
J.dev

Reputation: 1045

If none of these answers work, it's maybe because you need to add a provider in your serverless account and add your AWS keys.

enter image description here

Upvotes: 0

jazeb007
jazeb007

Reputation: 668

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

Upvotes: 0

Yashwant Rautela
Yashwant Rautela

Reputation: 59

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

Upvotes: 0

zixu
zixu

Reputation: 11

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

Upvotes: 1

Fernando Terra
Fernando Terra

Reputation: 81

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).

Upvotes: 0

live-love
live-love

Reputation: 52366

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

Upvotes: 3

Mikeumus
Mikeumus

Reputation: 3878

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

sls deploy --aws-profile common

Upvotes: 17

bwest
bwest

Reputation: 9814

Can you provide more information?

Make sure that you've got the correct credentials in ~/.aws/config and ~/.aws/credentials. You can set these up by running aws configure. More info here: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-quick-configuration

Also make sure that the IAM user in question has as an attached security policy that allows access to everything you need, such as CloudFormation.

Upvotes: 3

Related Questions