amplify-js: Storage, missing credentials in config

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",

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 12
  • Comments: 47 (10 by maintainers)

Most upvoted comments

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)

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

removing of node_modules didn’t work for me.

@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, aws-sdk@2.371.0, 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.

removing of node_modules didn’t work for me.

same here unfortunately

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

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

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

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 had to downgrade to 1.0.2 from ^1.0.6 for it to work

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