DynamoDB TTL

  • Time To Live attribute defines an expiry time for your data
  • Expired items marked for deletion
  • Great for removing irrelevant or old data:
    • Session data
    • Event logs
    • Temporary Data
  • Reduces cost by automatically removing data which is no longer relevant

Session Data Table

  • TTL Expressed as epoch time (unix time)
    • number of seconds since 12 am Jan 1st, 1970
  • Expiration is set for 2 hours after the session began (in this example)
  • When the current time is greater than the TTL, the item will be expired and marked for deletion
  • You can filter out expired items from your queries and scans
  • Gets deleted within 48 hours

  • you must give the attribute that will be the TTL attribute

Atomic Counters

  • You can use the UpdateItem operation to implement an atomic counter
    • a numeric attribute that is incremented, unconditionally, without interfering with other write requests
    • All write requests are applied in the order in which they are received
  • With an atomic counter, the updates are not idempotent.
    • the number value will increment each time you call UpdateItem
  • Might use an atomic counter to keep track of the number of visitors to a website
    • In this case, your application would increment a numeric value, regardless of its current value
    • If an UpdateItem operation should fail, the application could siumply retry the operation
    • This would risk updating the counter twice, but you could probably tolerate a slight overcounting or undercounting of website visitors
  • An Atomic Counter would not be appropriate where overcounting or undercounting cannot be tolerated
    • In banking applications
    • In this case, it would be safer to use a conditional update instead of atomic counter

BatchGetItem and BatchWriteItem

For applications that need to read or write multiple items, DynamoDB provides the BatchGetItem and BatchWriteItem operations. Using these operations can reduce the number of network round trips from your application to DynamoDB. In addition, DynamoDB performs the individual read or write operations in parallel. Your applications benefit from this parallelism without having to manage concurrency or threading.

The batch operations are esseentially wrappers around multiple read or write requests. For example, if a BatchGetItem requests contains five items, DynamoDB performs five GetItem operations on your behalf. Similarly, if a BatchWriteItem request contains two requests and four delete requests, DynamoDB performs two PutItem and four DeleteItem requests.

ReturnConsumedCapacity Parameter

  • Total
    • returns the total number of write capacity units consumed
  • Indexes
    • returns the total number of write capacity units consumed, with subtotals for the table and any secondary indexes that were affected by the operation
  • none
    • no write capacity details are returned (this is the default).

Extras

  • Hot Partitions
    • It is not always possible to dstribute read and write activity evenly all the time
    • When data access is imbalanced, a "hot" partition can receive a much higher volume of read and write traffic compared to other partitions
  • UpdateTable does not use capacity
    • It is used to change provisioned throughput capacity
  • Conditional operations allow users to implement optimistic concurrency control systems on DynamoDB.
    • OCC assumes that multiple transactions can frequently complete without interfering with each other.
  • If you attempt to create more than one table with a secondary index at the same time:
    • You will receive the LimitExceededException Error
  • Number of DynamoDB Tables per account can be increased by AWS Support
  • BatchGetItem can retrieve up to 100 items
    • 16MB of data
  • Data plane operations are for CRUD actions
  • Control Plane operations are for managing DynamoDB tables
    • let you work with indexes, streams, and other objects that are dependant on tables
  • The BatchWriteItem operation puts or deletes multiple items in one or more tables.
    • When called in a loop, it also checks for unprocessed items and submits a new BatchWriteItem request with those unprocessed items until all items have been processed.
  • DynamoDB write operations that allow conditional writes:
    • PutItem
    • UpdateItem
    • DeleteItem
    • Note: Specify an expression that must evaluate to true in order for the operation to succeed
  • A Single DynamoDB partition can support a maximum of 3,000 read capacity units or 1,000 write capacity units
    • When you create a new table, the initial number of partitions can be expressed as folows:
      • (readCapacityUnits / 3,000 ) + ( writeCapacityUnits / 1,000 ) = initialPartitions (rounded up)
  • While the UpdateTable operation is executing, the table status changes from ACTIVE to UPDATING.
    • While it is UPDATING, you cannot issue another UpdateTable request.
    • When the table returns to the ACTIVE state, the UpdateTable operation is complete and another UpdateTable request may be issued.
  • Maximum Length of a Partition Key Value
    • 2048
    • Minimum is 1 byte
  • Maximum Length of a sort Key Value
    • 1024 bytes
    • Minimum is 1 byte
  • ListTables will give a list of all your DynamoDB tables
    • A single ListTables call can return a maximum of 100 table names;
    • if you have more than 100 tables, you can request that ListTables return paginated results, so that you can retrieve all of the table names.