无权使用联合身份未授权用户角色从 Amplify graphQL 访问类型 Y 上的 X

问题描述 投票:0回答:0

我正在为 Web 应用程序(应用程序 A)使用 Amplify,但我有另一个 node.js 应用程序(应用程序 B),我想用它来将一些数据写入 DynamoDB 表。应用程序 B 没有前端,因此,我需要应用程序 B 能够进行未经授权的访问(或找到一种在后端进行身份验证的方法。

我做了以下事情:

  • 初始化放大
  • 在 Cognito 应用程序池中设置
  • 为 team-provider-info.json 中列出的 unauth 角色配置各种策略
  • 将 unauth 角色附加到联合身份策略
  • 尝试了 aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS" 和 "IAM"
  • 将授权规则设置为在模型上公开

然而,在 Amplify CLI 和在 AppSync 控制台中使用查询时,我仍然收到错误“未授权访问类型查询的 listPersonalInfos”。

下面是 CloudWatch 的报错

{
    "logType": "RequestMapping",
    "path": [
        "listPersonalInfos"
    ],
    "fieldName": "listPersonalInfos",
    "resolverArn": "arn:aws:appsync:ap-southeast-2:771661204178:apis/6pu5wf3wvfcr7dh3zribqhp6ua/types/Query/resolvers/listPersonalInfos",
    "functionName": "QuerygetPersonalInfoauth0Function",
    "requestId": "1817ebd7-80d3-48da-93d3-471f37aa665a",
    "context": {
        "arguments": {},
        "prev": {
            "result": {}
        },
        "stash": {
            "authRole": "arn:aws:sts::771661204178:assumed-role/amplify-talentui-dev-122653-authRole/CognitoIdentityCredentials",
            "conditions": [],
            "connectionAttributes": {},
            "fieldName": "listPersonalInfos",
            "hasAuth": true,
            "metadata": {
                "dataSourceType": "AMAZON_DYNAMODB",
                "apiId": "6pu5wf3wvfcr7dh3zribqhp6ua"
            },
            "tableName": "PersonalInfo-6pu5wf3wvfcr7dh3zribqhp6ua-dev",
            "typeName": "Query",
            "unauthRole": "arn:aws:sts::771661204178:assumed-role/amplify-talentui-dev-122653-unauthRole/CognitoIdentityCredentials"
        },
        "outErrors": []
    },
    "fieldInError": true,
    "errors": [
        "Not Authorized to access listPersonalInfos on type Query"
    ],
    "parentType": "Query",
    "graphQLAPIId": "6pu5wf3wvfcr7dh3zribqhp6ua",
    "functionArn": "arn:aws:appsync:ap-southeast-2:771661204178:apis/6pu5wf3wvfcr7dh3zribqhp6ua/functions/2zc46rgvzjgn3osvltkfuz4g3y"
}
node.js aws-lambda amazon-dynamodb aws-amplify aws-appsync
© www.soinside.com 2019 - 2024. All rights reserved.