Home > Enterprise >  Return only the values of an attribute column from a DynamoDB table
Return only the values of an attribute column from a DynamoDB table

Time:04-14

Is there a way to return all of the values from an attributes (columns) in a DynamoDB Table? And does this operation actually have the same computation costs as a ScanAll operation?

I have a large enough table, which I don't intent to return all of the values, but need only some the values from one of the attributes. I am afraid that if I do a ScanAll (and then reduce the data) or Query the operational costs will be the same. First reading all get the whole object and then cutting it to get the attribute in question.

CodePudding user response:

According to docs: GetItem returns all of the item's attributes. You can use a projection expression to return only some of the attributes.

Having said that, Projection Expression is a string that identifies the attributes that you want. To retrieve a single attribute, specify its name. For multiple attributes, the names must be comma-separated.

aws dynamodb get-item \
    --table-name ProductCatalog \
    --key file://key.json \
    --projection-expression "Description, RelatedItems[0], ProductReviews.FiveStar"

The arguments for --key are stored in the key.json file.

Full docs on that are here.

  • Related