https://i.sstatic.net/kcB03.png
In a TypeScript Lambda API I developed, there is a specific point where the callback complete
logs occur. Following those logs, the lambda takes approximately 10 seconds to respond as shown by the timestamps.
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
}