在上一节课中,我们在nodejs中通过代码访问了DynamoDB Local服务器,并且创建了一张表。但那段代码只能用来做demo,因为里面有很多参数并没有讲解应该如何使用。(这个不能怪我啦~~ amazon官网上面资料太多,一时半会没找到应该算是正常情况吧~~)
这节课,我们补上那段缺失的历史,讲解一下create table api中各项参数的使用。
OK,话不多说,看代码:
{
"AttributeDefinitions": [
{
"AttributeName": "string",
"AttributeType": "string"
}
],
"GlobalSecondaryIndexes": [
{
"IndexName": "string",
"KeySchema": [
{
"AttributeName": "string",
"KeyType": "string"
}
],
"Projection": {
"NonKeyAttributes": [
"string"
],
"ProjectionType": "string"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": number,
"WriteCapacityUnits": number
}
}
],
"KeySchema": [
{
"AttributeName": "string",
"KeyType": "string"
}
],
"LocalSecondaryIndexes": [
{
"IndexName": "string",
"KeySchema": [
{
"AttributeName": "string",
"KeyType": "string"
}
],
"Projection": {
"NonKeyAttributes": [
"string"
],
"ProjectionType": "string"
}
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": number,
"WriteCapacityUnits": number
},
"StreamSpecification": {
"StreamEnabled": boolean,
"StreamViewType": "string"
},
"TableName": "string"
}
这是DynamoDB中创建表的API参数。待会,我们需要讲解的就是其中各项应该如何赋值。
在DynamoDB之中,同一个用户可以在不同地区创建多张同名表。只要在一个地区中保持表名唯一即可。在DynamoDB执行createTable是一个异步操作,当接收到CreateTable请