0

我正在尝试在创建 localstack 容器时初始化 dynamodb 表。考虑以下命令:

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 中使用这些,所以我想知道我在这里做错了什么?

4

1 回答 1

3

我猜你不能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
于 2020-08-03T17:48:41.297 回答