I have been going through some tutorials on AWS Lambda & Dynamodb. I see that, just to get a response with one record which is all the Dyanamodb table has as of now, I see there is a delay of little over a second. My intention is to use aws services for a chat application in the future, but this delay wont be acceptable for a chat application.
How the function is called - I invoke the lambda function using the API Gateway, and the Lambda function in turn calls the Dynamodb table, returns the response through the function and finally through the API back to the user.
Lambda Code -
const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB({region:'ca-central-1', apiVersion:'2012-08-10'});
exports.handler = (event,context,callback) => {
const params = {
Item: {
"UserId": {
S:"user_" Math.random()
},
"Age": {
N:event.age
},
"Height": {
N:event.height
},
"Income": {
N:event.income
}
},
TableName: "compare-yourself"
};
dynamodb.putItem(params, function(err, data) {
if (err) {
console.log(err);
callback(err);
} else {
console.log(data);
callback(null, data);
}
});
};
CodePudding user response:
Try to increase your lambda RAM to approximately 1GB and try again. Often high latencies are caused by small lambda sizes.
Increasing memory also improves other performance metrics likes CPU and therefore generally reduces latency caused by lambda cold starts. Especially lambdas smaller than 512MB are relatively slow to start.