GetItem, BatchGetItem

GetItem

Documentation

GetItem API is a single item operation. It returns a set of attributes for the item with the given primary key. If there is no matching item, GetItem does not return any data and there will be no Item element in the response.

  • TableName is a required parameter for the write operation.

  • Key MUST be set to item’s primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.

  • ConsistentRead a boolean that may be set to true for carrying out strongly consistent read. Recall that a strongly consistent read is relatively expensive.

  • ProjectionExpression is an optional parameter that identifies one or more attributes to retrieve from the item. If this parameter is missing then all item attributes are returned. If the specified attribute does not exist in the item then it is ignored.

aws dynamodb  get-item \
    --table-name   Employee  \
    --key '{"LoginAlias": {"S": "irenes"}}' 

BatchGetItem

Documentation

A single operation can retrieve up to 16 MB of data, which can contain as many as 100 items

The BatchGetItem API can retrieve an item collection from one or more tables. Under the covers, this operation invokes the GetItem operation for all the Item primary keys specified in the operation. For each item only the attributes specified in the projections will be returned.

batch-reads

This operation returns a partial result if the

  • Response size limit is exceeded,
  • The table’s provisioned throughput is exceeded,
  • Or an internal processing failure occurs.

If a partial result is returned, the operation returns a value for UnprocessedKeys. You can use this value to retry the operation starting with the next item to get.

  • RequestItems is a required parameter to provide the table name and keys. It’s a map of one or more table names and, for each table, a map that describes one or more items to retrieve from that table. Each table name can be used only once per BatchGetItem request.

    • ProjectionExpression for attribute projections

    • ExpressionAttributeNames for providing the names for placeholder in the expression

    • Keys is an array of primary key attribute values that define specific items in the table.

AWS CLI

  • Accepts the RequestItems in the form of a JSON file with no data descriptors
aws dynamodb batch-get-item \
    --request-items file://./dynamodb/api/walkthrough-2-batch-get.json 

JSON

  • In this example, items are specified in a file. Items are getting requested from a single table Employee
  • Items specified with the Partition Key LoginAlias will be retrieved
{
    "Employee": {
        "Keys": [
            {
                "LoginAlias": {
                    "S": "rajs"
                }
            },
            {
                "LoginAlias": {
                    "S": "johns"
                }
            }
        ],
        "ProjectionExpression": "FirstName,LastName"
    }
}