AWS Lambda函数问题 [英] AWS Lambda functions issue

查看:117
本文介绍了AWS Lambda函数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始尝试使用AWS Lambda函数.单击 Test 按钮后,这就是Lambda控制台的执行结果窗口中显示的信息.

I have recently started trying to use AWS Lambda functions. Here is what I get in the Execution results window of the Lambda console, when clicking the Test button.

Response:
{
  "statusCode": 500,
  "body": "{\"message\":\"Missing credentials in config\",
  \"code\":\"CredentialsError\",\"time\":\"2019-06-06T07:11:53.538Z\",
  \"originalError\":{\"message\":\"No credentials to load\",
  \"code\":\"CredentialsError\",\"time\":\"2019-06-06T07:11:53.538Z\"}}"
}

这是Lambda函数源代码:

And here is the Lambda function source code:

var AWS = require('aws-sdk/dist/aws-sdk-react-native');

AWS.config.update({
    region:'ap-northeast-1'
});

exports.handler = async (event,context) => {
    var params = {
        UserPoolId: 'ap-northeast-1MY-POOL-ID',
        AttributesToGet: [
            'email'
        ],
        Limit: '2',
    };

    var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();

    try {
      const data = await cognitoidentityserviceprovider.listUsers(params).promise()
      const response = {
        inBound: event.sub,
        statusCode: 200,
        body: JSON.stringify(data)
      }
      return response;
    } catch (err) {
        const response = {
            inBound: event.sub,
            statusCode: 500,
            body: JSON.stringify(err)
        };
        return response;
    }
};

由于我已经设置了角色和策略,所以我不确定错误消息指的是哪种凭据和哪种配置.

Since I have set up the roles and policy, I am not sure what kind of credentials and which config the error message is referring to.

推荐答案

首先,将现有的import语句替换为以下内容.

First, replace the existing import statement with follows.

var AWS = require('aws-sdk');

第二,按如下所示,授予认知用户列表访问lambda角色的权限.

Second, allow the cognito user list permission to lambda role as follow.

{
  "Effect": "Allow",
    "Action": [
        "cognito-idp:ListUsers"
    ],
    "Resource": [
        "arn:aws:cognito-idp:ap-northeast-1:AWS_ACCOUNT_NO:userpool:*"
    ]
}

注意:将AWS_ACCOUNT_NO替换为您的实际AWS帐号.

Note: Replace AWS_ACCOUNT_NO with your actual aws account number.

这篇关于AWS Lambda函数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆