Invoking DynamoDB operations from AWS Lambda takes much longer than expected

0

DynamoDB operations are taking 200 to 600 ms to complete when invoked from AWS Lambda. Some research on the internet states that operations should be as quick as 10 - 20 ms (https://dynobase.dev/dynamodb-performance-latency/). My question is, what could cause my operations to take so long?

This image shows the CloudWatch logs that I am using to determine the DynamoDB operation length This image shows the CloudWatch logs that I am using to determine the DynamoDB operation length

This image shows the yaml definition for the DyanmoDB table that is being pulled from in that operation This image shows the yaml definition for the DyanmoDB table that is being pulled from in that operation

This is the javascript code that is logging the start GetDBItem and end GetDBItem logs This is the javascript code that is logging the start GetDBItem and end GetDBItem logs

There is 18 items in the ChessCardArchetypeData table.

Let me know if there is any other information that I can provide to help debug this.

2 Answers
2
Accepted Answer

There is a couple of things at play here when you state that you are not seeing the expected latency:

  1. DynamoDB offers server-side latency in the single-digit milliseconds (measured for the full round trip).
  2. The single-digit millisecond latency is applicable mainly to singleton operations (such as GetItem), which is acceptable.
  3. This low latency can be attained when there is consistent traffic on the table since DynamoDB extensively utilizes internal metadata caching to minimize response times.
  4. In order to achieve this level of latency, it is essential to establish your connection outside of the request handler and enable TCP Keep-alive to allow the reuse of connections.

In summary, you measure timings for Lambda init and also the for the full round trip to DynamoDB, which includes connection establishment times etc.. You are also likely making infrequent requests which do not utilize the internal caching to reduce response timings. To measure DynamoDB's timings, its best to use SuccessfulRequestLatency metric on CloudWatch.

profile pictureAWS
EXPERT
answered 9 months ago
-1

Hi Mitchell, you use async programming with await. So, you may also here include the time for your promise to complete as you measure it with your current logs. So, can you add an intermediate log after statement item = data.Item to see if duration of request itself is better?

Best, Didier

profile pictureAWS
EXPERT
answered 9 months ago
  • Try also increasing the function's memory. The more memory you set, the more CPU your functions get.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions