amazon-web-services - AWS Amplify AppSync IAM 401

标签 amazon-web-services amazon-iam aws-appsync aws-amplify

我收到 GraphQLError: Request failed with status code 401
我按照以下自动配置说明进行操作:

https://aws.github.io/aws-amplify/media/api_guide#automated-configuration-with-cli

我尝试寻找,但缺乏 IAM 资源。看起来一切都应该自动设置,并在我输入 IAM 访问 key 和 secret 后使用 Amplify CLI 完成。

是否需要进一步设置?这是我的代码:

import Amplify, { API, graphqlOperation, Hub } from "aws-amplify";
import aws_config from "../../aws-exports";

Amplify.configure(aws_config);

const ListKeywords = `query ListKeywords {
  listKeyword {
    keyword {
      id
      name
    }
  }
}`;

const loop = async () => {
  const allKeywords = await API.graphql(graphqlOperation(ListKeywords));
}

是否也可能是因为我的 GraphQL 解析器尚未为 ListKeywords 设置?

最佳答案

如果您在 AppSync API 上使用 IAM 作为授权类型,那么问题是在调用 Amplify.configure() 时未授予 GraphQL 操作权限时,与 Auth 类别一起使用的 Cognito 角色。它需要附上这样的东西:

{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Effect": "Allow",
         "Action": [
            "appsync:GraphQL"
         ],
         "Resource": [
            "arn:aws:appsync:us-west-2:123456789012:apis/YourGraphQLApiId/*"
         ]
      }
   ]
}

更多细节在这里:https://docs.aws.amazon.com/appsync/latest/devguide/security.html

关于amazon-web-services - AWS Amplify AppSync IAM 401,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50394268/

相关文章:

amazon-web-services - 如何直接从请求映射器返回?

amazon-web-services - 如何将 AWS SSO 设置为 Auth0 Enterprise SAML 连接

amazon-ec2 - 没有从 ELB 到其中一个 Auto Scaling 实例的流量

ruby-on-rails - AWS实例运行时间

amazon-web-services - AWS 云信息 :Template validation error Role and policy

php - 通过使用 AWS-SDK PHP 生成的预签名帖子拒绝 AWS S3 上传访问

amazon-dynamodb - 应用同步 + DynamoDB : filter by owner

java - Rekognition 客户端不断根据每个请求进行重建

amazon-web-services - API 网关 : how to grant permissions based on the policy of the caller

javascript - 如何将项目添加到列表?