Description
Describe the bug
We've observed that the initial call to DynamoDB is quite slow, often exceeding 2000ms, and sometimes even approaching 10,000ms. Subsequent calls improve significantly (usually under 20ms), but we occasionally see slower calls (500ms+) after periods of inactivity.
We are seeing the same performance using both IDynamoDBContext and the IAmazonDynamoDB.
We tried using strategies outlined here to improve the situation but no luck. I even tried hardcoding the accessKey but to no avail.
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
Client execution time even for the first request should not be an outlier by such a huge margin.
Current Behavior
Example of metrics for the first request vs followup request
[
{
"properties": {
"AsyncCall": "True",
"CanonicalRequest": "",
"StringToSign": "AWS4-HMAC-SHA256",
"ServiceName": "Amazon.DynamoDBv2",
"ServiceEndpoint": "https://dynamodb.eu-west-1.amazonaws.com/",
"MethodName": "GetItemRequest",
"RequestSize": "126",
"StatusCode": "OK",
"BytesProcessed": "209",
"AWSRequestID": "K19J5R1DG85P5U40973N60VP7VVV4KQNSO5AEMVJF66Q9ASUAAJG"
},
"timings": {
"CredentialsRequestTime": 0.9548,
"RequestSigningTime": 244.6937,
"HttpRequestTime": 502.974,
"ResponseUnmarshallTime": 5.8003,
"ResponseProcessingTime": 21.274,
"ClientExecuteTime": 879.363
},
"counters": {}
},
{
"properties": {
"AsyncCall": "True",
"CanonicalRequest": "",
"ServiceName": "Amazon.DynamoDBv2",
"ServiceEndpoint": "https://dynamodb.eu-west-1.amazonaws.com/",
"MethodName": "GetItemRequest",
"RequestSize": "126",
"StatusCode": "OK",
"BytesProcessed": "209",
"AWSRequestID": "03U2E2TDLSRB3T87ACBEP0BEN3VV4KQNSO5AEMVJF66Q9ASUAAJG"
},
"timings": {
"CredentialsRequestTime": 0.0058,
"RequestSigningTime": 0.2945,
"HttpRequestTime": 2.7207,
"ResponseUnmarshallTime": 0.0642,
"ResponseProcessingTime": 0.2808,
"ClientExecuteTime": 3.6218
},
"counters": {}
}
]
Reproduction Steps
Minimal code directly copied from tutorials exhibit the same issue. I pasted an example in lambda for IDynamoDBContext
, but it's the same executing from ECS container.
public class Functions
{
private IDynamoDBContext _dynamoDbContext;
public Functions()
{
_dynamoDbContext = new DynamoDBContext(new AmazonDynamoDBClient());
}
[LambdaFunction]
[RestApi(LambdaHttpMethod.Get, "/")]
public async Task<IHttpResult> Get(ILambdaContext context)
{
var queryConfig = new DynamoDBOperationConfig
{
OverrideTableName = "paywall-cwwebsite-subscriptions-qa",
QueryFilter = new List<ScanCondition>
{
new("sk", ScanOperator.Equal, "GLOBAL")
}
};
var subscriberInfo = await _dynamoDbContext.QueryAsync<SubscriberInfoDto>("google.com", queryConfig).GetRemainingAsync();
return HttpResults.Ok();
}
}
Possible Solution
No response
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
Targeted .NET Platform
net8.0
Operating System and version
Lambda