Complete the code to create a DynamoDB table with a primary key.
aws dynamodb create-table --table-name Users --attribute-definitions AttributeName=UserId,AttributeType=S --key-schema AttributeName=UserId,KeyType=[1] --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
The primary key in DynamoDB is defined as a HASH key. This uniquely identifies each item in the table.
Complete the code to add a Global Secondary Index (GSI) to the DynamoDB table.
aws dynamodb update-table --table-name Users --attribute-definitions AttributeName=Email,AttributeType=S --global-secondary-index-updates '[{"Create":{"IndexName":"EmailIndex","KeySchema":[{"AttributeName":"Email","KeyType":"[1]"}],"Projection":{"ProjectionType":"ALL"},"ProvisionedThroughput":{"ReadCapacityUnits":5,"WriteCapacityUnits":5}}}]'
The partition key for a Global Secondary Index must be a HASH key.
Fix the error in the DynamoDB query to get an item by its primary key.
aws dynamodb get-item --table-name Users --key '{"UserId": {"[1]": "12345"}}'
The attribute type for a string in DynamoDB JSON format is 'S'.
Fill both blanks to write a DynamoDB update expression that sets a new attribute and increments a counter.
aws dynamodb update-item --table-name Users --key '{"UserId": {"S": "12345"}}' --update-expression "SET [1] = :val, [2] = [2] + :inc" --expression-attribute-values '{":val": {"S": "active"}, ":inc": {"N": "1"}}'
The update expression sets the 'Status' attribute and increments the 'Counter' attribute.
Fill all three blanks to write a DynamoDB query that filters items with Age greater than 25 and projects only Name and Age.
aws dynamodb scan --table-name Users --filter-expression "[1] > :age" --expression-attribute-names '{"#N": "[2]", "#A": "[3]"}' --expression-attribute-values '{":age": {"N": "25"}}' --projection-expression "#N, #A"
The filter expression uses 'Age' to compare, and the projection expression uses 'Name' and 'Age' attributes.