Which statement best describes a Global Secondary Index (GSI) in DynamoDB?
Think about how GSIs let you query data differently than the main table keys.
A Global Secondary Index lets you create an alternate key structure with a different partition key and optional sort key, enabling queries on attributes not part of the base table's primary key.
Given a DynamoDB table Orders with a GSI named CustomerIndex that has CustomerId as the partition key, what will be the output of the following query?
aws dynamodb query \
--table-name Orders \
--index-name CustomerIndex \
--key-condition-expression "CustomerId = :cid" \
--expression-attribute-values '{":cid":{"S":"C123"}}'Assume the table has these items:
- {OrderId: "O1", CustomerId: "C123", Amount: 100}
- {OrderId: "O2", CustomerId: "C456", Amount: 200}
- {OrderId: "O3", CustomerId: "C123", Amount: 150}
The query uses the GSI to find all orders for CustomerId 'C123'.
The query on the GSI with CustomerId = 'C123' returns all items where CustomerId matches, which are orders O1 and O3.
Which option contains a syntax error when creating a GSI in a DynamoDB table using AWS CLI?
aws dynamodb update-table \
--table-name Products \
--attribute-definitions AttributeName=Category,AttributeType=S, AttributeName=Price,AttributeType=N \
--global-secondary-index-updates '[{"Create":{"IndexName":"CategoryPriceIndex","KeySchema":[{"AttributeName":"Category","KeyType":"HASH"},{"AttributeName":"Price","KeyType":"RANGE"}],"Projection":{"ProjectionType":"ALL"},"ProvisionedThroughput":{"ReadCapacityUnits":5,"WriteCapacityUnits":5}}}]'Check the attribute definitions syntax carefully.
In the attribute definitions, the two attributes must be separated by a comma. Missing comma causes a syntax error.
You have a GSI on a DynamoDB table with heavy read traffic but low write traffic. Which option optimizes cost while maintaining performance?
Think about which capacity units affect read and write costs.
ProvisionedThroughput settings control read and write capacity separately. For heavy reads and low writes, increase read units and keep write units low to save cost.
You created a GSI on a DynamoDB table with OrderDate as the partition key. After inserting items, querying the GSI returns no results. What is the most likely cause?
Remember how DynamoDB indexes items in GSIs.
Only items that have the GSI's partition key attribute are indexed. If items lack the attribute, they won't appear in GSI queries.