Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js AWS Cognito SignIn延迟太高_Node.js_Authentication_Aws Lambda_Amazon Cognito - Fatal编程技术网

Node.js AWS Cognito SignIn延迟太高

Node.js AWS Cognito SignIn延迟太高,node.js,authentication,aws-lambda,amazon-cognito,Node.js,Authentication,Aws Lambda,Amazon Cognito,我正在使用aws cognito注册和登录我的应用程序。我的应用程序后端托管在aws lambda上,前面是我的api网关支持的api。例如,我使用“amazon cognito identity js”库并在后端从我的nodejs lambda调用注册。我向用户公开的api是/user/login 我的后端lambda调用登录中的代码如下: exports.signIn = (email, password) => new Promise((resolve, reject) =&

我正在使用aws cognito注册和登录我的应用程序。我的应用程序后端托管在aws lambda上,前面是我的api网关支持的api。例如,我使用“amazon cognito identity js”库并在后端从我的nodejs lambda调用注册。我向用户公开的api是/user/login

我的后端lambda调用登录中的代码如下:

exports.signIn = (email, password) =>
    new Promise((resolve, reject) => {
        const authenticationDetails = new Cognito.AuthenticationDetails({
            Username: email,
            Password: password
        });

        const cognitoUser = new Cognito.CognitoUser({
            Username: email,
            Pool: userPool
        });

        cognitoUser.authenticateUser(authenticationDetails, {
            onSuccess: result => {
                resolve({
                    data: {
                        token: result.getIdToken().getJwtToken(),
                        refreshToken: result.getRefreshToken().getToken()
                    }
                })
            },
            onFailure: err => {
                console.log(err);
                reject({
                    data: {
                        errorCode: err.code,
                        errorMessage: err.message
                    },
                    statusCode: 400
                })
            }
        });
});
API工作正常,正如预期的那样,我能够拿回令牌

我面临的问题是该API的高延迟。延迟大约为5-8秒,这太高了。我已经测试过,这种高延迟不能归因于lambda冷启动


有人能帮我理解为什么am的延迟如此之高吗?

您的Cognito和API网关在同一地区吗?