awscli не учитывает глобальные вторичные индексы при проверке определений атрибутов - PullRequest
0 голосов
/ 03 августа 2020

Я пытаюсь инициализировать таблицу Dynamodb при создании контейнера localstack. Рассмотрим следующую команду:

awslocal dynamodb create-table \
  --debug \
  --table-name Journal \
  --global-secondary-indexes 'IndexName=GetJournalRowsIndex, KeySchema=[{AttributeName=persistence-id, KeyType=HASH},{AttributeName=sequence-nr,KeyType=RANGE}], Projection={ProjectionType=ALL}, ProvisionedThroughput={ReadCapacityUnits=10,WriteCapacityUnits=10}' \
  --global-secondary-indexes 'IndexName=TagsIndex, KeySchema=[{AttributeName=tags,KeyType=HASH}],Projection={ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=10,WriteCapacityUnits=10}' \
  --key-schema \
      AttributeName=pkey,KeyType=HASH \
      AttributeName=skey,KeyType=RANGE \
  --attribute-definitions \
      AttributeName=persistence-id,AttributeType=S \
      AttributeName=pkey,AttributeType=S \
      AttributeName=skey,AttributeType=S \
      AttributeName=sequence-nr,AttributeType=N \
      AttributeName=tags,AttributeType=S \
  --billing-mode PAY_PER_REQUEST

Я получаю следующую ошибку:

An error occurred (ValidationException) when calling the CreateTable operation: The number of attributes in key schema must match the number of attributesdefined in attribute definitions.

Я использую их в GSI, поэтому мне интересно, что я здесь делаю не так?

1 Ответ

3 голосов
/ 03 августа 2020

Думаю, вы не можете указать флаг global-secondary-indexes дважды. Попробуйте следующее

awslocal dynamodb create-table \
  --debug \
  --table-name Journal \
  --global-secondary-indexes "[{\"IndexName\": \"GetJournalRowsIndex\", \"KeySchema\": [{\"AttributeName\": \"persistence-id\", \"KeyType\": \"HASH\"}, {\"AttributeName\": \"sequence-nr\", \"KeyType\": \"RANGE\"}], \"Projection\": {\"ProjectionType\": \"ALL\"}, \"ProvisionedThroughput\": {\"ReadCapacityUnits\": 1, \"WriteCapacityUnits\": 1}}, {\"IndexName\": \"TagsIndex\", \"KeySchema\": [{\"AttributeName\": \"tags\", \"KeyType\": \"HASH\"}], \"Projection\": {\"ProjectionType\": \"ALL\"}, \"ProvisionedThroughput\": {\"ReadCapacityUnits\": 1, \"WriteCapacityUnits\": 1}}]" \
  --key-schema \
      AttributeName=pkey,KeyType=HASH \
      AttributeName=skey,KeyType=RANGE \
  --attribute-definitions \
      AttributeName=persistence-id,AttributeType=S \
      AttributeName=pkey,AttributeType=S \
      AttributeName=skey,AttributeType=S \
      AttributeName=sequence-nr,AttributeType=N \
      AttributeName=tags,AttributeType=S \
  --billing-mode PAY_PER_REQUEST
...