[英]“Missing credentials in config” with aws-amplify Storage
I recently upgraded from an older version of aws-amplify to version 我最近从旧版本的aws-amplify升级到了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; 经过一番挖掘后,我发现在最新版本的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). 文档没有以任何方式提及这些内容,并且我无法确切找到此“凭证”密钥需要什么值才能正常工作(使用Auth和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. 您不需要手动设置凭据密钥,Amplify会自动设置Storage类的凭据。 Since your environment was working prior the update the issue maybe related with aws-sdk
packages. 由于您的环境在更新之前可以正常工作,因此该问题可能与aws-sdk
软件包有关。 The issue is related with multiple aws-sdk
packages in your node_modules
folder. 该问题与node_modules
文件夹中的多个aws-sdk
软件包node_modules
。 As a rule simple removing an aws-sdk
folder is not working since your project files are cached. 通常,简单地删除aws-sdk
文件夹不起作用,因为已缓存了项目文件。 Below are steps how to fix the issue for a react-native
project but you can adjust them according to your environment: 以下是解决react-native
项目问题的步骤,但是您可以根据自己的环境进行调整:
Make sure you do not have aws-sdk
under dependencies in your package.json
file since aws-amplify
already has AWS SDK included. 确保您的package.json
文件中的依赖项下没有aws-sdk
,因为aws-amplify
已包含AWS开发工具包。 If there is an aws-sdk
in the package.json
file run the command to remove it: 如果package.json
文件中包含aws-sdk
,请运行以下命令将其删除:
$ npm uninstall aws-sdk --save
Make sure you are using the latest version of aws-amplify
package. 确保您使用的是最新版本的aws-amplify
软件包。
Remove the package-lock.json
file from your project folder (do not forget to create a copy of the file). 从项目文件夹中删除package-lock.json
文件(不要忘记创建该文件的副本)。
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. 此命令将删除您的node_modules
文件夹,并根据package.json
文件重新安装所有软件包。
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)
. 这是因为Amplify使用aws-sdk来获取credentials(accessKeyId, secretAccessKey)
。 But it's not found because you may haven't configured it. 但找不到它,因为您可能尚未配置它。 So configure it before you configure aws-amplify. 因此,请先配置它,然后再配置aws-amplify。 No need to uninstall anything. 无需卸载任何东西。
AWS.config.update({...credential})
Amplify.configure({...credential})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.