使用 CognitoIdentityServiceProvider 的 adminCreateUser 方法的 AWS Lambda 函数突然失败

时间:2021-04-19 11:15:27

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

在过去的几天里,我一直在使用 AWS Lambda 函数测试某个流程,我的 lambda 函数在 Cognito 用户池中预注册后被触发,该函数工作正常,并能很好地返回回调函数。但从昨天开始,我一直看到以下错误:-

ntime/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:690:12)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
2021-04-19T11:09:07.321Z    b42b6dd0-b290-454c-afa9-6be666903995    INFO    InvalidLambdaResponseException: Invalid lambda function output : Invalid JSON
    at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:52:27)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:688:14)
    at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:690:12)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
  code: 'InvalidLambdaResponseException',
  time: 2021-04-19T11:09:07.260Z,
  requestId: 'a52a10ae-efdf-4358-b6e0-8c6bbbc10f26',
  statusCode: 400,
  retryable: false,
  retryDelay: 45.341053308762234
}
2021-04-19T11:09:07.508Z    b42b6dd0-b290-454c-afa9-6be666903995    INFO    InvalidLambdaResponseException: Invalid lambda function output : Invalid JSON
    at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:52:27)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:688:14)
    at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:690:12)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
  code: 'InvalidLambdaResponseException',
  time: 2021-04-19T11:09:07.260Z,
  requestId: 'a52a10ae-efdf-4358-b6e0-8c6bbbc10f26',
  statusCode: 400,
  retryable: false,
  retryDelay: 48.61578358654741
} InvalidLambdaResponseException: Invalid lambda function output : Invalid JSON
    at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:52:27)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:688:14)
    at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:690:12)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
END RequestId: b42b6dd0-b290-454c-afa9-6be666903995
REPORT RequestId: b42b6dd0-b290-454c-afa9-6be666903995  Duration: 2564.50 ms    Billed Duration: 2565 ms    Memory Size: 128 MB Max Memory Used: 88 MB  Init Duration: 427.70 ms

这是 lambda 函数:-

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

var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider({
    apiVersion: '2016-04-18'
});

exports.handler = async (event, context, callback) => {
    console.log("Event input => ", event);

    const attributes = event.arguments;
    const userPoolId = process.env.USERPOOL_ID;

    var params = {
        UserPoolId: userPoolId,
        Username: attributes.username,
        DesiredDeliveryMediums: ["EMAIL"],
        UserAttributes: [{
                Name: "email",
                Value: attributes.email,
            },
            {
                Name: "email_verified" /* required */ ,
                Value: "true",
            },
            {
                Name: "name" /* required */ ,
                Value: attributes.name,
            }
        ]
    };


    try {
        const data = await cognitoidentityserviceprovider
            .adminCreateUser(params, function(err, data) {
                if (err) {
                    console.log(err, err.stack);
                    // an error occurred
                }
                else {
                    console.log("SUCCESS", JSON.stringify(data)); // successful response

                }
                callback(null, data);
            })
            .promise();
    } catch (error) {
        console.log(error);
    }
};

这是我正在使用的测试事件:-

{
  "arguments": {
    "name": "John Smith",
    "username": "jsmith",
    "email": "jsmith.com@gmail.com",
  }
}

我不确定我是否不小心更改了代码中的某些内容并且不记得了,或者是否 AWS 方面的某些更改导致了这种情况。我已经确定当我从 try catch 块调用 adminCreateUser 方法时会出现问题。但是无法从错误堆栈中找出导致错误的具体原因。帮助将不胜感激!

0 个答案:

没有答案