I have used dynamodb-session to set DynamoDB for Asp.net Session state provider.
In my ASP.NET_SessionState table in DynamoDb There is "Conditional CheckFailed " monitoring.
My question is: In what condition these exceptions happen and how can I reduce them?
Generally speaking, conditional checks are optimistic concurrency control mechanisms provided by DynamoDB. The basic idea is that every write request can specify conditions on the item being written that must be true for the write to succeed. This section of the AWS DynamoDB documentation talks more about conditional writes. Whenever a conditional check on a write fails, DynamoDB pumps a metric for the purposes of monitoring.
The 'Locking Session Data Store' section of the ASP.NET Session-State Store Provider documentation talks about concurrency control that needs to be implemented to prevent concurrency issues between requests that may be trying to access session information. From the description, it seems like contention occurs when you have concurrent requests with some of those requests having EnableSessionState property set to True (which means they intend to update the session state). In this case, each request will have to first acquire a lock on the session by performing a conditional write to DynamoDB (as seen in the DynamoDBSessionState code). Only one of these concurrent requests will succeed. The others requests will fail (causing a conditional check failed metric to be pumped) and then wait for half a second before retrying to acquire a lock by writing to DynamoDB. This process of waiting, failing, pumping metric and retrying continues until all the requests have been fulfilled. Note that the requests that are readers (EnableSessionState property set to ReadOnly) also have to wait for writers to release their locks before they can proceed. The only difference is that readers do not acquire a lock by writing to DynamoDB.
Based on this, the only way to have no contention then is to have all concurrent requests with EnableSessionState set to False or ReadOnly.