AWS Cognito IdentityId 和 IdentityPoolId 为 null

Mar*_*cak 5 amazon-cognito aws-api-gateway

我一直在尝试使用联合身份和身份池的 Cognito 用户池。我创建了身份池并指定 cognito 作为其身份验证提供者。Cognito 有 Google 身份提供商。我使用 Amplify 进行注册/登录,它配置了身份池和我的用户池。当我登录时,身份会在身份池中正确创建,并链接到用户池中的用户。我可以在 Amplify 会话中的可用凭据中看到 IdentityId 和 IdentityPoolId,两者都包含有效信息,我能够毫无问题地调用 Cognito 同步并交换身份数据。

我在通过 API Gateway 发送到集成的 API Lambda 处理程序的身份时遇到问题。我使用 REST API(旧的),集成为 Lambda 代理,并创建了 Lambda 授权方,它只是将事件转储到日志中。

当我检查 CloudWatch 日志时,我看到

"identity": {
            "cognitoIdentityPoolId": null,
            "accountId": null,
            "cognitoIdentityId": null,
            "caller": null,
            "sourceIp": "185.5.69.158",
            "principalOrgId": null,
            "accessKey": null,
            "cognitoAuthenticationType": null,
            "cognitoAuthenticationProvider": null,
            "userArn": null,
            "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
            "user": null
        },
Run Code Online (Sandbox Code Playgroud)

为什么我们 cognitoIdentityPoolId 和 cognitoIdentityId 为 null?我使用 Amplify API 集成,并且在日志中看到带有预签名请求的授权标头。

需要什么才能访问 lambda 授权者中的身份?