2016-05-20 57 views
1

有關創建全局二級索引的AWS CLI for Dynamodb create-table有點混淆。在CLI document,它說,全球二級索引可以用下面的表達式(簡寫)表示:如何使用AWS CLI創建Dynamodb全局二級索引?

IndexName=string,KeySchema=[{AttributeName=string,KeyType=string},{AttributeName=string,KeyType=string}],Projection={ProjectionType=string,NonKeyAttributes=[string,string]},ProvisionedThroughput={ReadCapacityUnits=long,WriteCapacityUnits=long} ... 

我的理解是,我應該做的

--global-secondary-indexes IndexName=requesterIndex,Projection={ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=1,WriteCapacityUnits=1} 

請注意,我不包括KeySchema這裏推斷複雜性。控制檯給我以下錯誤:

Parameter validation failed: 
Missing required parameter in GlobalSecondaryIndexes[0]: "KeySchema" 
Unknown parameter in GlobalSecondaryIndexes[0]: "WriteCapacityUnits", must be one of: IndexName, KeySchema, Projection, ProvisionedThroughput 
Invalid type for parameter GlobalSecondaryIndexes[0].ProvisionedThroughput, value: ReadCapacityUnits=1, type: <class 'str'>, valid types: <class 'dict'> 

因此,某種程度上AWS CLI無法識別ProvisionedThroughput的映射表達式。我嘗試了幾種方式來表達它,但無法使其工作。我也沒有找到任何網頁在谷歌描述如何做到這一點。請幫忙!謝謝!

回答

1

通過閱讀AWS CLI source code on Github,它可以解析雙引號內容。因此在腳本中添加雙引號可以解決問題。有新代碼 -

--global-secondary-indexes IndexName=requesterIndex,Projection={ProjectionType=ALL},ProvisionedThroughput="{ReadCapacityUnits=${CURRENT_READUNIT},WriteCapacityUnits=${CURRENT_WRITEUNIT}}" 
+1

是的。你的回答是正確的!我也在努力解決同樣的問題。令人遺憾的是,在AWS CLI的文檔中沒有全球二級索引的好例子,您不得不花時間調查報價問題。 –

3

這是我用來在命令行的aws文檔中創建答覆示例的cli調用。我最後使用的$ EP可以在EP="--endpoint-url http://localhost:8000"的環境中設置,以在您當地dynamodb而不是aws上創建表格。

aws dynamodb create-table --table-name Reply --attribute-definitions \ 
AttributeName=Id,AttributeType=S AttributeName=ReplyDateTime,AttributeType=S \ 
AttributeName=PostedBy,AttributeType=S AttributeName=Message,AttributeType=S \ 
--key-schema AttributeName=Id,KeyType=HASH \ 
AttributeName=ReplyDateTime,KeyType=RANGE --global-secondary-indexes \ 
IndexName=PostedBy-Message-Index,KeySchema=["\ 
{AttributeName=PostedBy,KeyType=HASH}","\ 
{AttributeName=Message,KeyType=RANGE}"],Projection="{ProjectionType=INCLUDE \ 
,NonKeyAttributes=["ReplyDateTime"]}",ProvisionedThroughput="\ 
{ReadCapacityUnits=10,WriteCapacityUnits=10}" --provisioned-throughput \ 
ReadCapacityUnits=5,WriteCapacityUnits=4 $EP 
+0

解釋爲什麼以及如何解決這個問題很有用。 – swa66

+0

請格式化您的代碼。 –

相關問題