【问题标题】:awscli doesn't consider global-secondary-indexes when validating attribute-definitionsawscli 在验证属性定义时不考虑全局二级索引
【发布时间】:2020-08-03 17:20:37
【问题描述】:

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

【问题讨论】:

    标签: amazon-dynamodb aws-cli localstack amazon-dynamodb-local


    【解决方案1】:

    我猜你不能指定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
    

    【讨论】:

    • 天哪!看起来它奏效了。这是我遇到的最糟糕的错误。非常感谢,我不会弄明白的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 2021-07-06
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    相关资源
    最近更新 更多