You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Lambda执行代码返回后10秒才结束的问题求助

Lambda函数在callback complete输出后延迟10秒响应的问题

日志截图

我编写了一个TypeScript Lambda API,如图中callback complete日志所示,Lambda在输出该日志后10秒才返回响应,时间戳也能证明这一延迟情况。

以下是我的Lambda处理函数代码:

export const handler = async (event, context, callback) => {
  const { headers: { Authorization } } = event

  start = Date.now()

  const auth = await authorizer(Authorization)

  console.log(`Authorizer took ${Date.now() - start} seconds to complete`)

  if (!auth.isAuthenticated) {
    callback(null, { statusCode: 401, body: JSON.stringify("Unauthorized") })
    return
  }

  start = Date.now()
  const associations = await dynamoDb.query({
    // DynamoDB Query params
  }).promise()

  console.log(`DynamoDB query took ${Date.now() - start} seconds to complete`)

  const customers = associations.Items.map(association => association.customer)

  if (customers.length === 0) {
    callback(null, { statusCode: 200, body: JSON.stringify([]) })
    return
  }

  start = Date.now()
  const customerDetails = await pool.query(`XXXXXXXX`)

  console.log(`PostgreSQL query took ${Date.now() - start} milliseconds to complete`)

  const { rows } = customerDetails

  callback(null, { statusCode: 200, body: JSON.stringify(rows) })
  console.log('callback complete')
  return
}

内容的提问来源于stack exchange,提问作者MegaMind

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 03:32:47