Query local table: Full scan of table: Describe table: Create Global Secondary Index: The KeySchema.AttributeName should be the name of the attribu...

Categories

Query local table:

aws dynamodb query \
    --table-name us_zipcodes \
    --index-name zipcodeIndex \
    --key-condition-expression "postalcode = :zip" \
    --expression-attribute-values  '{":zip":{"S":"64324"}}' \
    --endpoint-url http://localhost:8000

Full scan of table:

aws dynamodb scan \
    --table-name us_zipcodes \
    --index-name zipcodeIndex \
    --endpoint-url http://localhost:8000

Describe table:

aws dynamodb describe-table --table-name us_zipcodes --endpoint-url http://localhost:8000

Create Global Secondary Index:

The KeySchema.AttributeName should be the name of the attribute you want to be your key. In this case, the attribute name is ‘postalcodes’ in the table.

aws dynamodb update-table \
    --table-name us_zipcodes \
    --attribute-definitions AttributeName=postalcode,AttributeType=S \
    --global-secondary-index-updates file://add_global_secondary_index.json \
    --endpoint-url http://localhost:8000 \

contents of add_global_secondary_index.json:

[
    {
        "Create": {
            "IndexName": "zipcodeIndex",
            "KeySchema": [
                {
                    "AttributeName": "postalcode",
                    "KeyType": "HASH"
                }
            ],
            "ProvisionedThroughput": {
                "ReadCapacityUnits": 1,
                "WriteCapacityUnits": 1
            },
            "Projection": {
                "ProjectionType": "ALL"
            }
        }
    }
]

DELETE Global Secondary Index from table:

aws dynamodb update-table \
    --table-name us_zipcodes \
    --global-secondary-index-updates file://delete_index.json \
    --endpoint-url http://localhost:8000 \

contents of delete_index.json:

[
  {
    "Delete": {
      "IndexName": "zipcodeIndex"
    }
  }
]

Run the local dynamoDB after you download it:

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

List tables:

aws dynamodb list-tables --endpoint-url http://localhost:8000