Amplify-js: Storage, missing credentials in config

Created on 14 Jul 2018  ·  46Comments  ·  Source: aws-amplify/amplify-js

My credentials and Auth is working fine, but when I try to use the Storage.get as in

const credentials = await Auth.currentCredentials();
const url = await Storage.get('icon.jpg', { level: 'protected' });

It errors:

Error: Missing credentials in config
    at credError (aws-sdk-core-react-native.js:10589)
    at Config.getCredentials (aws-sdk-core-react-native.js:10658)
    at Request.VALIDATE_CREDENTIALS (aws-sdk-core-react-native.js:11756)
...

The Auth.currentCredentials() works fine. I log in using Auth.federatedSignIn().
I am using amplify version 1.0.0 with react-native 0.56.0.

I also run this in my entry file:

Amplify.configure({
    'aws_app_analytics': 'xxx',
    'aws_auth_facebook': 'xxx',
    'aws_cognito_identity_pool_id': 'xxx',
    'aws_cognito_region': 'xxx',
    'aws_facebook_app_id': 'xxx',
    'aws_facebook_app_permissions': 'xxx',
    'aws_mandatory_sign_in': 'xxx',
    'aws_mobile_analytics_app_id': 'xxx',
    'aws_mobile_analytics_app_region': 'xxx',
    'aws_project_id': 'xxx',
    'aws_project_name': 'xxx',
    'aws_project_region': 'xxx',
    'aws_resource_name_prefix': 'xxx',
    'aws_sign_in_enabled': 'xxx',
    'aws_user_files': 'xxx',
    'aws_user_files_s3_bucket': 'xxx',
    'aws_user_files_s3_bucket_region': 'xxx',
})

EDIT:

Debug info

Everything looks fine to me, the credentials that are logged here match the ones which I also use for authenticating with appsync

[DEBUG] 50:43.447 Credentials - checking if credentials exists and not expired
{[DEBUG] 50:43.449 Credentials - is this credentials expired?: CognitoIdentityCredentials}
[DEBUG] 50:43.449 Credentials - credentials not changed and not expired, directly return
{[DEBUG] 50:43.454 StorageClass - set credentials for storage: {…}}[DEBUG] 50:43.454 StorageClass - set credentials for storage: accessKeyId: "xxx" authenticated: true identityId: "eu-central-1:xxx-xxxx-xxxx-xxxx" secretAccessKey: "xxx" sessionToken: "xxx"
[DEBUG] 50:43.466 StorageClass - get icon.jpg from protected/eu-central-1:xxx-xxxx-xxxx-xxxx/icon.jpg
{[WARN] 50:43.471 StorageClass - get signed url error: Error: Missing credentials in config

I have the following aws related dependencies:

    "aws-amplify": "^1.0.0",
    "aws-amplify-react-native": "^1.0.0",
    "aws-appsync": "^1.2.1",
    "aws-appsync-react": "^1.0.21",
Storage documentation

Most helpful comment

Hi @albertdatui can you remove aws-sdk from your dependencies and try again, maybe aws-sdk is duplicated on your project (aws-amplify has aws-sdk as dependency)

All 46 comments

Hi can you provide some code snippets about this issue and also if you could provide some debug logging info that would be better. You can turn on the debug mode by putting window.LOG_LEVEL='DEBUG' in you code

@powerful23 Hi! Thanks for the response. I added the debug info to the issue. The storage class worked fine before when I tested. What I've changed since is upgrading to react native 0.56.0. Not sure if that's the culprit, it cloud also be that I've upgrades some other libraries since or some new change to my codebase makes the auth break, but afaic the configuration and everything looks fine

+1, I am facing the same issue as well

I can see the Storage class credentials is set

DEBUG] 50:06.861 StorageClass - set credentials for storage:
    accessKeyId :"xxxx" 
    authenticated: true
    identityId: "xxx"
    secretAccessKey: "xxx"
    sessionToken: "xxxx"

But I got this message
originalError : {message: "No credentials to load", code: "CredentialsError", time: Sun Jul 15 2018 21:50:07 GMT+0800 (Singapore Standard Time)}

error stack

"CredentialsError: Missing credentials in config
    at credError (http://localhost:3000/static/js/bundle.js:48620:40)
    at Config.getCredentials (http://localhost:3000/static/js/bundle.js:48661:14)
    at Request.VALIDATE_CREDENTIALS (http://localhost:3000/static/js/bundle.js:50193:26)
    at Request.callListeners (http://localhost:3000/static/js/bundle.js:54933:18)
    at Request.emit (http://localhost:3000/static/js/bundle.js:54909:10)
    at Request.emit (http://localhost:3000/static/js/bundle.js:53546:14)
    at Request.transition (http://localhost:3000/static/js/bundle.js:52885:10)
    at AcceptorStateMachine.runTo (http://localhost:3000/static/js/bundle.js:57748:12)
    at Request.runTo (http://localhost:3000/static/js/bundle.js:53266:15)
    at Request.send (http://localhost:3000/static/js/bundle.js:53230:10)
    at features.constructor.makeRequest (http://localhost:3000/static/js/bundle.js:55268:27)
    at features.constructor.svc.(anonymous function) [as listObjects] (http://localhost:3000/static/js/bundle.js:55574:23)
    at http://localhost:3000/static/js/bundle.js:47085:36
    at new Promise (<anonymous>)
    at StorageClass.<anonymous> (http://localhost:3000/static/js/bundle.js:47084:47)
    at step (http://localhost:3000/static/js/bundle.js:46841:23)
    at Object.next (http://localhost:3000/static/js/bundle.js:46822:53)
    at fulfilled (http://localhost:3000/static/js/bundle.js:46813:58)"

@ricsam can you try to assign the credentials from Auth.currentCrednetials() to AWS.config.credentials?

@albertdatui are you also using the appsync library?

@powerful23 Thanks for the suggestion! I run global.AWS.config.credentials = await Auth.currentCredentials(); but unfortunately the same error persist

@powerful23 apologies, it is just a simple invocation of Storage class.

@powerful23 Hi after a reinstallation of all packages it works! I don't know why or how but afaic this issue can be closed. Thanks for looking in to the problem! @albertdatui You could try the same 🤷‍♂️

@ricsam, I have removed node_modules, do npm install aws-amplify and aws-sdk. It still gave me the same error

"aws-amplify": "^1.0.0", "aws-sdk": "^2.276.1",

Hi @albertdatui can you remove aws-sdk from your dependencies and try again, maybe aws-sdk is duplicated on your project (aws-amplify has aws-sdk as dependency)

@elorzafe I did what you suggested: removed aws-sdk, and it worked!
been having issues getting this to work (it did not work as advertised out of the box, had to tinker):
https://github.com/aws-samples/aws-amplify-graphql
this was the last missing piece, thank you!

I had the same problem, just removing the folder node_modules did not work. I had to delete the package-lock.json file, so it worked

removing aws-sdk seem to fix the issue.thanks

In the version 1.0.5 does not working. I set versin 1.0.2 and works.

Yep same thing for me. Downgrading from 1.0.5 to 1.0.2 fixed the CredentialsError issue.

I am having the same issue. Has it been fixed?

@onyii5119 it should have been fixed. Please make sure you don't have duplicate aws-sdk packages.

I had to downgrade to 1.0.2 from ^1.0.6 for it to work

@jorgedavila25 can you show me your dependencies in the package.json?

Hi, it works very fine on my config!
"aws-amplify": "^1.0.6",
"aws-amplify-react": "^1.0.6",
"aws-appsync": "^1.3.4",
"aws-appsync-react": "^1.1.4",

I was able to resolve the issue by updating aws-amplify from 1.0.2 to 1.0.10.

I also ran into this problem and found that the solution was to remove aws-sdk from my package.json, delete the package-lock.json, remove all node_modules and do a full npm install. With that done everything was fine again.

I add aws-sdk to get access to dynamodb because amplify dosen't able to do that, and I am able to access dynamodb and meet the same error when using Storage to upload a file to S3.

@Sdcxv you don't need to install aws-sdk again when you have installed aws-amplify

I'm using aws-amplify in combination with aws-appsync. I had aws-appsync and aws-appsync-react as first-level dependencies, and kept getting this error until I removed aws-appsync (it was already a dependency under aws-appsync-react).

For those who need to use AWS object from aws-sdk -
After removing 'aws-sdk' you can still get AWS using - import AWS from '@aws-amplify/core';

I also have aws-sdk-mock installed which hoists the installed version of aws-sdk to 2.360.0
Locking the version to that of amplify with a resolution fixes the issue.
add this to package.json (I'm using yarn)

  "resolutions": {
    "aws-sdk": "2.329.0"
  }

If we are not supposed to use aws-sdk then importing services gets challenging. This doesn't work:
import { CognitoIdentityServiceProvider } from '@aws-amplify/core/node_modules/aws-sdk/clients';
How do we use the services from the JavaScript SDK?

@svstartuplab I ended up importing AWS from '../node_modules/aws-sdk'

@paalex I upgraded to Amplify 1.1.12 which was released on NPM 17 hours ago, which would be around 4:30 PM 5 Dec 2018, about 5 hours after I asked my question. Now /core/node_modules is gone and I can't find the aws-sdk anywhere in @aws-amplify.

So I reinstalled aws-sdk, [email protected], and tried the original issue posted here again and had the same error message as the OP posted. Previous to upgrading Amplify this import looked like it would work but I didn't test it today. Damn! import { CognitoIdentityServiceProvider } from '@aws-amplify/core/node_modules/aws-sdk'; I think I tried it yesterday and it didn't but I didn't save that test import.

So now the issue seems to be worse.

@svstartuplab since aws-sdk is one of the dependencies of aws-amplify, there is no need to install it in your app and if you check your node_modules, the aws-sdk package should be under the path: node_modules/aws-sdk. Can you remove your node modules, make sure no aws-sdk dependency in your package.json and reinstall again?

@svstartuplab I had similar issues of the folder mysteriously disappearing on npm installs , therefore I use 'node_modules/aws-sdk' from the project root folder

@powerful23, I deleted node_modules/aws-sdk yesterday because per advice above it is included in @aws-amplify/core/node_modules/aws-sdk, which is was until I upgraded amplify today. So I did a fresh install of node_modules/aws-sdk.

I just tried this. It imports the service but the same error as the OP. The imports work in the code in that they don't produce errors in the IDE so they are being imported.

import Amplify, { Auth  } from 'aws-amplify';
import { AWS } from '@aws-amplify/core';
import { CognitoIdentityServiceProvider } from 'aws-sdk';
// import * as AWS from 'aws-sdk';

The error I'm receiving is a little different than the OP:

Error: Missing credentials in config
    at credError (config.js:352)
    at getStaticCredentials (config.js:373)
    at Config.getCredentials (config.js:382)
    at Request.VALIDATE_CREDENTIALS (event_listeners.js:81)
    at Request.callListeners (sequential_executor.js:102)
    at Request.emit (sequential_executor.js:78)
    at Request.emit (request.js:683)
    at Request.transition (request.js:22)
    at AcceptorStateMachine.runTo (state_machine.js:14)
    at Request.runTo (request.js:403)

My code is here in S.O. This doesn't include the many functions I copied from the AWS docs and the limited other sources. Few of those worked at all but I commented them out for reference.

https://stackoverflow.com/questions/53597300/how-to-list-all-aws-cognito-users-amplify-javascript-sdk-angular-app

@svstartuplab I see. Maybe it's because you are not passing the correct credentials. Could you try changing your code to:

public buildAWSConfig() {

    Auth.currentCredentials().then(credentials => {
        // Constructor for the global config.
    this.AWSconfig = new AWS.Config({
      apiVersion: '2016-04-18',
      credentials: credentials,
      region: this.cognitoIdPoolRegion
    });

    this.cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider(this.AWSconfig);

    /*  This doesn't get creds, probably because of Amplify.
        this.cognitoidentityserviceprovider.config.getCredentials(function(err) {
          if (err) console.log('No creds: ', err);    // Error: Missing credentials
          else console.log("Access Key:", AWS.config.credentials.accessKeyId);
        });
    */

    console.log('cognitoidentityserviceprovider: ', this.cognitoidentityserviceprovider);

    this.getCognitoUsers();
    }).catch(e => {
         console.log('Failed to get the credentials: ' + e);
    });

}

@powerful23 You got it! Thank you!

Calling Auth.currentCredentials() gets the whole user object that I received from Amplify and puts it in the CognitoIdentityServiceProvider object's config.credentials field. I thought only the JWT should go there, and there is no guidance about this anywhere that I've found.

That was the key issue although the OP's issue and suggested workarounds were probably a problem until I updated per my above post and changed my imports to use the JavaScript SDK differently than the docs suggest. For reference again:

import Amplify, { Auth  } from 'aws-amplify';
import { AWS } from '@aws-amplify/core';
import { CognitoIdentityServiceProvider } from 'aws-sdk';
// import * as AWS from 'aws-sdk';  // Don't do this.

One small problem with your code and my import setup. The AWS object doesn't have the CognitoIdentityServiceProvider method. I had to drop AWS. Easy to fix.

The docs need to be updated and need to make clear that now you use both Amplify and the JavaScript SDK. Amplify is NOT a replacement for the SDK as the docs state, at least at this date. That instruction along with other issues in the docs cost me a couple of weeks of screwing around. Ugh.

I had this problem, solved it by upgrading to the latest versions of aws-appsync and aws-appsync-react.

I put my code in Stack Overflow for those who want my full solution.

Is this issue safe to close?

Well, it is if the docs were improved to provide guidance on the issue. A big issue with Amplify are the docs.

I have created an issue in the docs repo to track this. I will close this issue for now as the inital problem seems to have been solved.

removing of node_modules didn't work for me.

removing of node_modules didn't work for me.

same here unfortunately

removing of node_modules didn't work for me.

same here unfortunately

Likewise, I've been stuck with this issue for a couple days.

I had this exact error when my device was disconnected from the internet.
When I connected it, the error goes away.
Hope it would help someone

import Amplify, { Auth } from 'aws-amplify';
import { AWS } from '@aws-amplify/core';

After changing to this import I can't able to upload image to s3. Failed to upload the image

I am using aws-amplify and aws-amplify-react-native latest versions
undefined is not an object (evaluating '_core.AWS.config')]

Was this page helpful?
0 / 5 - 0 ratings