Reputation: 15424
I have lambda function and dynamo db table in the same region (us-east-1). In lambda function I perform very simple query:
params =
TableName: 'users'
Item:
email:
S: event.body.email
ConditionExpression: 'attribute_not_exists (email)'
dynamodb.putItem(params, context.done)
There are only few rows in DynamoDB table, there is Hash Key on email and Read/Write throughtputs are set to 5/5.
Lambda function exeutes in ~4 seconds... This is very slow. Am I doing something wrong?
I've tested my function with different memory settings for lambda function (it was set to 128mb previously):
So it seems that response time depends 1-1 on memory (well in fact on compute capacity as AWS scales it along with memory). Still this is crazy because to make very simple REST API I have to set 1536mb memory to make it "responsive" while my program uses 17mb!
Hmm on the other hand I've calculated that it will cost:
So it's not so bad I guess...
Upvotes: 30
Views: 11501
Reputation: 7122
Well, the problem might also be related to un-pausing the container the Lambda
function is running at. You also may want to optimize how you initialize your objects so they don't get re-initialized every time the function is called.
See the article Container reuse in Lambda.
Upvotes: 2