简体   繁体   中英

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.

我必须在我的serverless deploy命令中指定 sls deploy --aws-profile ,如下所示:

sls deploy --aws-profile common

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.

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

在此处输入图片说明

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.

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM