Reading data from DynamoDB

DynamoDB supports three ways of querying data:

  • Read the exact item using get-item, providing all the keys.
  • Read the items using a query, providing at least the partition key. You may also provide a sort key and/or a filter expression.
  • Read the items using a scan, providing a filter expression. 

Each of these ways support strongly consistent reads, using an additional option of consistent-read. The default is eventual consistency. By default, all attributes are returned in a read operation. You can use a ProjectionExpression parameter to specify which attributes need to be returned. 

The following are some of the important characteristics of get-item:

  • We cannot use get-item against a local or global secondary index.
  • All key attributes need to be provided, or a ValidationException is thrown.
  • If no items match, it returns nothing (no exception is thrown).

The following are some of the important characteristics of a query:

  • The partition key is mandatory.
  • You can provide a sort key or a range for sort keys.
  • You can filter non-key values, but discarded values are still charged for.
  • If no items match, it returns an empty block.
  • The query results are always sorted by the sort key. The default order is ascending, but we can reverse the order by setting the ScanIndexForward parameter to false.

The following are some of the important characteristics of a scan:

  • Key fields are not mandatory, but may be provided along with filter expressions.
  • It scans the entire table, unlike a query, which scans only the records matching the provided keys. Hence, we should try to use queries instead of scans when possible.
  • DynamoDB supports parallel scans for improved performance.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.134.17