首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有多个辅助索引的aws-cli dynamodb创建表

具有多个辅助索引的aws-cli dynamodb创建表
EN

Stack Overflow用户
提问于 2018-09-19 09:15:58
回答 1查看 1.8K关注 0票数 1

我正在尝试创建一个包含2个本地辅助索引的dynamodb表。我执行了以下操作,并且只应用了后一个索引(index-2)。正确的方法是什么?

代码语言:javascript
复制
aws dynamodb create-table \
 --table-name test_table_name \
 --attribute-definitions \
     AttributeName=type,AttributeType=S \
     ...
 --key-schema \
     AttributeName=type,KeyType=HASH \
     AttributeName=id,KeyType=RANGE \
 --provisioned-throughput \
     ReadCapacityUnits=5,WriteCapacityUnits=5 \
 --local-secondary-indexes \
     'IndexName=index-1,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk1,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[A,B,C,D]}' \
 --local-secondary-indexes \
     'IndexName=index-2,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk2,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[B,D,F,H]}' \
 --region us-east-1
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-19 10:00:31

您只需要指定单个--local-secondary-indexes,例如

先于

代码语言:javascript
复制
 --local-secondary-indexes \
     'IndexName=index-1,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk1,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[A,B,C,D]}' \
 --local-secondary-indexes \
     'IndexName=index-2,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk2,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[B,D,F,H]}' \

代码语言:javascript
复制
 --local-secondary-indexes \
     'IndexName=index-1,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk1,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[A,B,C,D]}' \
     'IndexName=index-2,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk2,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[B,D,F,H]}' \

最终

代码语言:javascript
复制
aws dynamodb create-table \
 --table-name test_table_name \
 --attribute-definitions \
     AttributeName=type,AttributeType=S \
     ...
 --key-schema \
     AttributeName=type,KeyType=HASH \
     AttributeName=id,KeyType=RANGE \
 --provisioned-throughput \
     ReadCapacityUnits=5,WriteCapacityUnits=5 \
 --local-secondary-indexes \
     'IndexName=index-1,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk1,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[A,B,C,D]}' \
     'IndexName=index-2,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk2,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[B,D,F,H]}' \
 --region us-east-1
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52402300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档