aws-cli dynamodb创建具有多个二级索引的表 [英] aws-cli dynamodb create table with multiple secondary index

查看:126
本文介绍了aws-cli dynamodb创建具有多个二级索引的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用2个本地二级索引创建一个dynamodb表.我执行了以下操作,仅应用了后者index(index-2).正确的方法是什么?

I am trying to create a dynamodb table with 2 local secondary indexes. I did the following and only the latter index(index-2) applied. What's the correct way of doing this?

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

推荐答案

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

You only need to specify single --local-secondary-indexes such as

之前

 --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]}' \

之后

 --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]}' \

最终

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

这篇关于aws-cli dynamodb创建具有多个二级索引的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆