DEV Community

Roman
Roman

Posted on • Originally published at romankurnovskii.com

AWS DynamoDB Cheat Sheet

  • Global tables are useful for having multiple copies of tables in different region.
  • All DynamoDB tables are encrypted at rest using an AWS owned CMK by default.
  • A primary key can either be a sinale-attribute partition key or a composite partition-sort key.
  • Both partition and sort keys attributes must be defined as type string, number, or binary.
  • Global secondary index:
    • Different partition key and sort key from base table
    • Only eventually consistent
    • Can be created after table is created
    • Using a random prefix for the GSI partition key enables to have high cardinality for the partition key
  • Local secondary index
    • Same partition key, different sort key from base table
    • Eventual and strongly consistent
    • Should be created when creating a table
  • Calculate RCU (read capacity unit) & WCU (write capacity unit):
    • 1 RCU = 2 eventual consistent read of 4 KB, 1 strongly consistent read of 4 KB
    • 1 WCU = 1 write per second for data for an item as large as 1 KB.
  • Queries or scan on GSI consume RCU on index not on table
  • Storing session state could be on elastic cache or dynamodb
  • Best practices when using Scan in dynamodb - Use parallel scan
    • to control the amount of data returned per request use the Limit parameter. This can help prevent situations where one worker consumes all the provisioned throuahput at the expense of all other workers
    • DynamoDB does not support item locking, and conditional writes are perfect for implementing optimistic concurrency.

Top comments (0)