简体   繁体   中英

“Missing credentials in config” with aws-amplify Storage

I recently upgraded from an older version of aws-amplify to version

"aws-amplify": "^1.0.2"

and when doing so I immediately started getting errors when trying to upload to my bucket. [WARN] 38:42.445 StorageClass - error uploading": CredentialsError: "Missing credentials in config"

After some digging I discovered that some new keys were added to the Storage configuration in the most recent version of aws-amplify; "credentials" and "level". The documentation does not mentioned these in any way, and I am unable to find exactly what value this "credentials" key needs in order to work properly (with a manual configuration of Auth and Storage). Anyone have any ideas of what this credentials object should look like?

You do not need to set the credentials key manually, the Amplify is setting the credentials for the Storage class automatically. Since your environment was working prior the update the issue maybe related with aws-sdk packages. The issue is related with multiple aws-sdk packages in your node_modules folder. As a rule simple removing an aws-sdk folder is not working since your project files are cached. Below are steps how to fix the issue for a react-native project but you can adjust them according to your environment:

  1. Make sure you do not have aws-sdk under dependencies in your package.json file since aws-amplify already has AWS SDK included. If there is an aws-sdk in the package.json file run the command to remove it:

     $ npm uninstall aws-sdk --save 
  2. Make sure you are using the latest version of aws-amplify package.

  3. Remove the package-lock.json file from your project folder (do not forget to create a copy of the file).

  4. Run

     $ rm -rf node_modules && npm install 

    This command will remove your node_modules folder and reinstall all the packages according to the package.json file.

  5. Optionally you can clear your local caches by entering one-by-one the following commands:

     $ watchman watch-del-all $ rm -rf /tmp/haste-map-react-native-packager-* $ rm -rf /tmp/metro-bundler-cache-* 

This is because Amplify is using aws-sdk to fetch credentials(accessKeyId, secretAccessKey) . But it's not found because you may haven't configured it. So configure it before you configure aws-amplify. No need to uninstall anything.

AWS.config.update({...credential})
Amplify.configure({...credential})

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