【问题标题】:Permissions for a AWS Lambda function to list usersAWS Lambda 函数列出用户的权限
【发布时间】:2019-10-21 04:03:49
【问题描述】:

我有一个需要能够运行此代码的 AWS Lambda 函数:

var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();

cognitoidentityserviceprovider.listUsers(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
  .... other useful code ....
});

换句话说,它应该能够列出用户

在 IAM 中为此设置角色时,我需要什么样的策略?

【问题讨论】:

    标签: amazon-web-services aws-lambda amazon-cognito amazon-iam


    【解决方案1】:

    如果您想列出 Cognito 用户池中的用户,您需要允许 cognito-idp:ListUsers。您可以将此操作限制为特定的用户池,如下所示:

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": "cognito-idp:ListUsers",
                "Resource": "arn:aws:cognito-idp:<region>:<account>:userpool/<userpoolid>"
            }
        ]
    }
    

    看看Actions, Resources, and Condition Keys for Amazon Cognito User Pools

    【讨论】:

    • 我已经尝试过,但是,我不断收到此错误:运行 iOS 应用程序时,我的 Xcode 调试控制台中的配置中缺少凭据 .... No credentials to load ... 在我的 Xcode 调试控制台中。一定有一些我不知道的问题。
    • 在 Lambda 环境中运行代码时不应发生这种情况。您可以尝试在 AWS 控制台中运行您的代码吗?
    • 我第一次在Xcode中看到消息,但是在Lambda环境中做了一些测试。它似乎是一样的。我在这里重新阐述了这个问题:stackoverflow.com/questions/56472969/aws-lambda-functions-issue
    • 我完全是 AWS-Lambda 初学者,所以我可能缺少一些基本元素。
    • 尝试仅使用 var AWS = require('aws-sdk'); 要求 aws-sdk
    【解决方案2】:

    您需要提供 IAM 角色 cognito-identity:ListIdentities 以获取更多信息。 https://iam.cloudonaut.io/reference/cognito-identity.html

    该列表操作可能存在依赖关系。

    你也可以 cognito-identity:* 如果您需要一个限制较少的策略来进行明智的测试。

    【讨论】:

    • 这是不正确的,问题是针对 Amazon Cognito 您的用户池 (cognito-idp) 而不是 Amazon Cognito 联合身份 (cognito-identity) .
    猜你喜欢
    • 1970-01-01
    • 2023-02-02
    • 2018-07-10
    • 2019-10-14
    • 2018-07-17
    • 2020-07-23
    • 1970-01-01
    • 2020-12-12
    • 2017-09-18
    相关资源
    最近更新 更多