awsmobile-cli icon indicating copy to clipboard operation
awsmobile-cli copied to clipboard

failed to link to backend awsmobile project with id <XXXX> - the security token included in the request is invalid

Open edzillion opened this issue 5 years ago • 8 comments

getting this error when trying to set up my awsmobile project on a new machine:

> awsmobile init xxxx-xxxx



failed to link to backend awsmobile project with id = xxxx-xxxx

the security token included in the request is invalid

{ UnrecognizedClientException: The security token included in the request is invalid.
    at Object.extractError (/home/ed/dev/circles-mobile/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/protocol/json.js:48:27)
    at Request.extractError (/home/ed/dev/circles-mobile/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/protocol/rest_json.js:52:8)
    at Request.callListeners (/home/ed/dev/circles-mobile/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/home/ed/dev/circles-mobile/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/home/ed/dev/circles-mobile/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/home/ed/dev/circles-mobile/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/ed/dev/circles-mobile/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/ed/dev/circles-mobile/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/ed/dev/circles-mobile/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/ed/dev/circles-mobile/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:685:12)
  message: 'The security token included in the request is invalid.',
  code: 'UnrecognizedClientException',
  time: 2018-08-10T13:32:54.803Z,
  requestId: 'fe82cd85-841d-47e8-9815-6c56f8e181a9',
  statusCode: 403,
  retryable: false,
  retryDelay: 28.37176829358361 }

Visit the following address to setup your aws account/user credentials:
https://console.aws.amazon.com/iam/home?region={region}#/users$new?step=final&accessKey&userNames={userName}&permissionType=policies&policies=arn:aws:iam::aws:policy%2FAdministratorAccess

# to set up the credentials for the awsmobile-cli
    $ awsmobile configure aws

npm ERR! code ELIFECYCLE
npm ERR! errno 4
npm ERR! [email protected] init: `awsmobile init 770910f7-fd56-4dde-8c4a-a2eb555047c7`
npm ERR! Exit status 4
npm ERR! 
npm ERR! Failed at the [email protected] init script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

and versions:

> node --version; npm --version; awsmobile --version
v10.4.1
6.1.0
1.1.4

I am definitely using valid AWS credentials. The project definitely exists.

Surely AWS Amplify is not just single user? We are trying to use it for our project and 80% of the time I can't set users up with awsmobile because of this problem. Here is our repo FYI

hope you can help

edzillion avatar Aug 10 '18 13:08 edzillion

This is a pretty serious issue, or at least a question that can be easily answered:

Is AWS Amplify just meant for single users?

edzillion avatar Aug 14 '18 17:08 edzillion

Or putting a more positive spin on it:

Can you provide a working example of an AWS repo with setup instructions?

edzillion avatar Aug 15 '18 08:08 edzillion

@edzillion As a note, I had this problem if I had run awsmobile configure globally and setup a user for it.

By clearing all the awsmobile related folders on my user directory and just starting from scratch on the project directory with awsmobile init , it worked. During the process it had to create a new user on AWS which is a bit weird, at least it works.

I hope this helps.

oliveiraa avatar Aug 15 '18 18:08 oliveiraa

Hi @edzillion

Sorry to hear that you are having trouble using the awsmobile-cli. The awsmobile-cli and the Amplify library are not meant to be used by single user.

When you init a project on a new machine, the awsmobile-cli will try to resolve aws access credentials from the credentials file in the ~/.aws/ folder. If there is a default profile in the file, it will be used.

If that's not the case, you will need to run awsmobile configure aws to set the credential for the cli, before you can execute the init command.

UnleashedMind avatar Aug 16 '18 06:08 UnleashedMind

The easiest way to resolve your issue is to go to the IAM console, and create a new user will admin rights, and get the accesskeyid and secrect-access-key, then on the new machine, execute awsmobile configure aws and paste the key id and the key at the prompt. This link might be helpful. https://docs.aws.amazon.com/aws-mobile/latest/developerguide/aws-mobile-cli-credentials.html

UnleashedMind avatar Aug 16 '18 06:08 UnleashedMind

Ok thanks for the input. I think I may have resolved this:

It seems to want to create a new awsmobilejs folder each time I run awsmobile init with a suffix of the date and time; I decided to wipe all of them and then try again, and it worked fine.

So I am wonderng whether it is a bad idea to commit the awsmobile folder?

There really should be a document outlining this stuff. I looked but couldn't find one.

edzillion avatar Aug 16 '18 10:08 edzillion

yes, the cli will create another awsmobilejs folder for most scenarios when you run awsmobile init, and at the same time back up the old contents in the awsmobilejs in a folder that has ~ prefix and timestamp suffix. The contents in the backup folder(s) are not used anymore by the cli. The cli inserts a section in the .gitignore file, and that's the recommended on what should and should not be committed to code repo

UnleashedMind avatar Aug 17 '18 17:08 UnleashedMind

Googlers from the future, use npm i -g @aws-amplify/cli

fabiosantoscode avatar Dec 11 '18 22:12 fabiosantoscode