Our tech stack: DynamoDB + Node.js + Aws Lambda + API Gateway.
As of now we don't have much data in database, around 100 records total. At time of fetching we have used GSI
with query
over scan
for fast result and also used limit with 10. But still it does not return response fast. For just 10 records
it takes 898.50 ms
.
Can anyone help, how to reduce this response time as this is the initial stage of development.
Why it takes this much for this? How we can get faster response and what affects the performance.
Example Code:
const itemParams = {
TableName: CUSTOMER_TABLE,
IndexName: 'companyId-index', // GSI Without range key
KeyConditionExpression: 'companyId = :companyId',
ProjectionExpression: [
'id',
'companyId',
'fullName',
'companyName',
'mobileNumber',
'contactEmail',
'createdAt',
'updatedAt'
],
FilterExpression: 'isDeleted = :isDeleted',
ExpressionAttributeValues: {
':isDeleted': false,
':companyId': authCompanyId
}
};
const customerList = await dynamoUtils.query(itemParams);
Note: function just execute query in dynamo, does not have any complex calculation neither in lambda function itself nor in dynamo query.
Thanks for any help.
As mentioned in the comments, using very small lambda sizes (256MB or less) can get quite slow for cold starts that need to download some packages. This is because the memory of the lambda is strongly correlated to other performance metrics like CPU available to the lambda.
Increasing the memory to 1GB or optimizing it using a tool can significantly reduce this time.