【问题标题】:AWS Amplify, "Error: No credentials" when getting items from AppSync graphql APIAWS Amplify,从 AppSync graphql API 获取项目时出现“错误:无凭证”
【发布时间】:2021-06-22 01:45:39
【问题描述】:

我已经发布了我的 React 应用程序以进行放大,那里一切正常。但是,当我打开放大 URL 时,我看到没有从数据库中获取任何项目,并且控制台中出现错误提示“无凭据”

我认为问题出在 AppSync API 上。 我使用 Amplify CLI 制作的,它使用 API 密钥身份验证。

我在本地使用生成的文件aws-exports.js 提供凭据。我像这样在我的index.tsx 中导入这个:

import awsmobile from "./aws-exports";

Amplify.configure(awsmobile);

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

但是这个文件没有被推送到 git,所以 Amplify 显然没有这个来自 repo。但我假设它能够生成自己的aws-exports.js 文件,因为它不会在导入时出现任何错误。

那么,我在这里缺少什么?我是否必须在我的 AppSync api 上使用其他方法进行身份验证,或者这里有什么问题? 谢谢!

【问题讨论】:

    标签: reactjs amazon-web-services aws-amplify aws-appsync


    【解决方案1】:

    我想我可能已经找到了解决办法。

    我只需要像这样用 @aws_api_key 注释我的 schema.graphql:

    type Item @model @aws_api_key {
      id: ID!
      name: String
    }
    

    当然还有您定义的任何自定义突变和订阅。

    见:https://aws.amazon.com/blogs/mobile/graphql-security-appsync-amplify/

    【讨论】:

      猜你喜欢
      • 2020-11-23
      • 1970-01-01
      • 2021-09-23
      • 2019-12-04
      • 2019-08-02
      • 2022-01-23
      • 2020-08-20
      • 2019-07-18
      • 2021-09-28
      相关资源
      最近更新 更多