【问题标题】:AWS DynamoDB Local add global secondary index using awscliAWS DynamoDB Local 使用 awscli 添加全局二级索引
【发布时间】:2020-08-24 16:53:38
【问题描述】:

您好,我尝试执行以下命令以将全局二级索引添加到现有表:

aws dynamodb update-table \
    --region eu-west-1 \
    --endpoint-url http://127.0.0.1:8000/ \
    --table-name ssib_dev_assetsTable \
    --attribute-definitions AttributeName=AssetGroup,AttributeType=S \
    --global-secondary-index-updates  \
    Create="{IndexName=gsi_group,KeySchema=[{AttributeName=AssetGroup,KeyType=HASH}],Projection={ProjectionType=ALL}}" \
    --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=10 \

+ 或 - 10 秒后,我得到以下响应,没有任何明确的错误消息。我使用https://hub.docker.com/r/cnadiminti/dynamodb-local/ 来模拟我的数据库。

调用 UpdateTable 时发生错误 (InternalFailure) operation (reached max retries: 9): 请求处理失败 由于未知的错误、异常或失败。

【问题讨论】:

  • 去掉--region eu-west-1选项会有影响吗?
  • 没有任何变化。
  • DynamoDB Local 实际上正在运行,是吗?
  • 是的,没问题
  • 仅供参考,文档指出端点 URL 应该是 localhost:8000,所以请测试它以确保它不是那么简单。

标签: amazon-web-services amazon-dynamodb amazon-dynamodb-local


【解决方案1】:

参数--global-secondary-index-updates 应该是一个有效的 JSON 字符串,但在你的情况下不是这样。它还缺少一个强制密钥,ProvisionedThroughput

https://docs.aws.amazon.com/cli/latest/reference/dynamodb/update-table.html

这里是:

aws dynamodb update-table \
    --region eu-west-1 \
    --endpoint-url http://127.0.0.1:8000 \
    --table-name ssib_dev_assetsTable \
    --attribute-definitions AttributeName=AssetGroup,AttributeType=S \
    --global-secondary-index-updates '[{"Create":{"IndexName":"gsi_group","KeySchema":[{"AttributeName":"AssetGroup","KeyType":"HASH"}],"Projection":{"ProjectionType":"ALL"},"ProvisionedThroughput":{"ReadCapacityUnits":5,"WriteCapacityUnits":5}}}]'

By the way, you should probably use the official image instead of some image by some random user docker user: https://hub.docker.com/r/amazon/dynamodb-local/

【讨论】:

  • 谢谢它完美地运行它有点奇怪,在一些遗留命令上我得到了像 `IndexName=gsi_name_parent,KeySchema=["{AttributeName=GroupName,KeyType=HASH}","{AttributeName= GroupParent,KeyType=RANGE}"],Projection="{ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=10,WriteCapacityUnits=10}" ` 并且有效。至少只有json是清楚的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-01
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
相关资源
最近更新 更多