任务超时表达AWS Lambda

时间:2019-01-08 06:21:18

标签: node.js amazon-web-services express aws-lambda amazon-cognito

我在命中端点请求时收到“内部服务器错误”。我已经将claudia与express框架和AWS lambda一起使用了。 但是在检查cloudwatch上的日志后,我得到了错误任务在3.00秒后超时,您能帮我吗?

源代码:

客户JS:

module.exports = { 
 login : async (req,res) => {
  var param = '+0855xxxx';
    var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails({
        Username : param,
        Password : '11111111'
    });

    var userData = {
        Username : param,
        Pool : userPool
    };
    var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function (result) {
            // console.log(result.idToken.payload)
            var rez = {
                accesstoken : result.getAccessToken().getJwtToken(),
                idtoken : result.getIdToken().getJwtToken(),
                refreshtoken : result.getRefreshToken().getToken()
            }
            // var obj = JSON.parse(result)
            // console.log(obj.idToken.payload)
            res.json({status:"Success", message: rez})
        },
        onFailure: function(err) {
            console.log(err);
        },

    })

 }
}

UserRoute JS

const router = require('express-promise-router')();
const customerHandlers = require('../app/handlers/customer')

router.route('/test')
    .get(customerHandlers.test)

router.route('/login')
    .post(customerHandlers.login)

module.exports = router;

App JS

const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const router = require('./routes/usersRoute')

//middleware
app.use(bodyParser.urlencoded({ extended: true }));

//routes
app.use('/customer', router)


//local
module.exports = app;

Lambda JS

'use strict'
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const binaryMimeTypes = [
    'application/octet-stream',
    'font/eot',
    'font/opentype',
    'font/otf',
    'image/jpeg',
    'image/png',
    'image/svg+xml'
]
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context)

为什么总是出现错误“内部服务器错误”?您能帮我解决这个问题吗?我已经阅读了Node.js中的AWS Lambda函数处理程序的文档 当我使用此导出处理程序时,文档说我的代码中使用了export.Handler?你能告诉我正确的方法吗?谢谢。

1 个答案:

答案 0 :(得分:2)

3秒听起来像Lambda的默认超时。尝试增加超时时间,看看会发生什么。可以将其增加到15分钟。您可以在Lambda函数的“基本设置”下更改设置。

enter image description here