bsbearden
bsbearden

Reputation: 91

Creating global secondary index from CLI

I am hoping someone can help me with Dynamo CLI syntax.

I have been unable to create a global secondary index from the CLI.

My script before the index works as expected:

aws dynamodb create-table \
--table-name a.b.c \
--attribute-definitions \
  AttributeName=TransactionID,AttributeType=S \
--key-schema \
  AttributeName=TransactionID,KeyType=HASH \
--provisioned-throughput\
  ReadCapacityUnits=5,WriteCapacityUnits=5 \
--endpoint-url $DATABASE_ENDPOINT_URL

When I add the index, I get an error:

aws dynamodb create-table \
--table-name a.b.c \
--attribute-definitions \
  AttributeName=TransactionID,AttributeType=S \
  AttributeName=BatchID,AttributeType=S \
  AttributeName=TransactionStatus,AttributeType=S \
--key-schema \
  AttributeName=TransactionID,KeyType=HASH \
--global-secondary-indexes IndexName=a.b.indexName,\
  KeySchema=["{AttributeName=BatchID,KeyType=HASH}","{AttributeName=TransactionStatus,KeyType=RANGE}"],\
  Projection="{ProjectionType=KEYS_ONLY}",\
  ProvisionedThroughput="{ReadCapacityUnits=5,WriteCapacityUnits=5}"\
--provisioned-throughput\
  ReadCapacityUnits=5,WriteCapacityUnits=5 \
--endpoint-url $DATABASE_ENDPOINT_URL

The error I receive is:

Error parsing parameter '--global-secondary-indexes': Expected: '<second>', received: '<none>' for input: IndexName=a.b.indexName,

This seems to be straight from the examples. I have also tried using a file based on some examples from other questions, but have had no luck there either.

Upvotes: 4

Views: 1393

Answers (2)

Cas
Cas

Reputation: 6684

I encountered the same issue where the forward-slash line-continuation adds extra unwanted spaces. However found we can make use of bash quoting line-continuation to break onto separate lines. There are various options of where to places quotes but this seemed to format nicely for readability:

aws dynamodb create-table \
    --table-name a.b.c \
    --attribute-definitions \
        AttributeName=TransactionID,AttributeType=S \
        AttributeName=BatchID,AttributeType=S \
        AttributeName=TransactionStatus,AttributeType=S \
    --key-schema \
        AttributeName=TransactionID,KeyType=HASH \
    --global-secondary-indexes \
        IndexName=a.b.indexName,KeySchema=["
            {AttributeName=BatchID,KeyType=HASH},
            {AttributeName=TransactionStatus,KeyType=RANGE}
        "],"Projection={
            ProjectionType=KEYS_ONLY
        "},ProvisionedThroughput={"
            ReadCapacityUnits=5,WriteCapacityUnits=5
        "} \
    --provisioned-throughput \
        ReadCapacityUnits=5,WriteCapacityUnits=5 \
    --endpoint-url $DATABASE_ENDPOINT_URL

Upvotes: 0

bsbearden
bsbearden

Reputation: 91

Putting everything on one line fixed it.

This works:

aws dynamodb create-table \
--table-name a.b.c \
--attribute-definitions \
  AttributeName=TransactionID,AttributeType=S \
  AttributeName=BatchID,AttributeType=S \
  AttributeName=TransactionStatus,AttributeType=S \
--key-schema \
  AttributeName=TransactionID,KeyType=HASH \
--global-secondary-indexes IndexName=a.b.indexName,KeySchema=["{AttributeName=BatchID,KeyType=HASH}","{AttributeName=TransactionStatus,KeyType=RANGE}"],Projection="{ProjectionType=KEYS_ONLY}",ProvisionedThroughput="{ReadCapacityUnits=5,WriteCapacityUnits=5}"\
--provisioned-throughput\
  ReadCapacityUnits=5,WriteCapacityUnits=5 \
--endpoint-url $DATABASE_ENDPOINT_URL

Upvotes: 5

Related Questions