node.js - AWS Cognito 登录延迟太高
问题描述
我在我的应用程序中使用 aws cognito 进行注册和登录。我的应用程序后端托管在 aws lambda 上,并且位于我的 api-gateway 支持的 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 冷启动。
有人可以帮我理解为什么我的延迟这么高吗?
解决方案
推荐阅读
- mysql - 在 MySQL 中加载了 ST_GeomFromGeoJSON 的multiplygon 内的搜索点
- python - 如何在单独的位置连接 2 个熊猫列?
- c++ - 不完整的类模板问题 - C++
- excel - 如何使用来自两个不同表单的两个不同按钮打开同一个表单并知道单击了哪个按钮?
- verilog - 如何在 Verilog 中初始化一个 wire[4:0] 数组?
- javascript - 为什么我在模式静态方法上定义的错误消息没有显示,即使错误处理显然有效?
- python - 为什么 Python 的 Decimal() 会稍微改变我传递给它的浮点数?
- r - 使用与向量 (r) 的部分匹配对列表进行排序
- rest - 在 Salesforce 中通过 REST API 编辑自定义对象
- python - 如何指定任意嵌套的 Django 模型(如目录结构)?