Skip to content
橡树上 edited this page May 3, 2018 · 13 revisions

DynamoDB 创建命令

--endpoint-url 是用于指定所操作的数据库地址,若去掉则直接操作线上数据,下面命令是面向本地数据库调试。

安装

详情见AWS文档:设置 DynamoDB Local (可下载版本)

启动本地数据库进行调试

在dynamoDB安装目录下,通过CMD输入java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb,启动本地数据库。

本项目用到的命令

  1. 显示所有表

aws dynamodb list-tables --endpoint-url http://localhost:8000

  1. 删除表

aws dynamodb delete-table --table-name <value> --endpoint-url http://localhost:8000

  1. 创建Article表
aws dynamodb create-table --table-name Article
  --attribute-definitions AttributeName=articleId,AttributeType=S AttributeName=author,AttributeType=S AttributeName=archive,AttributeType=S
  --key-schema AttributeName=articleId,KeyType=HASH
  --global-secondary-indexes IndexName=authorIndex,KeySchema=[{AttributeName=author,KeyType=HASH}],Projection={ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=5,WriteCapacityUnits=5}
  IndexName=archiveIndex,KeySchema=[{AttributeName=archive,KeyType=HASH}],Projection={ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=5,WriteCapacityUnits=5}
  --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
  --endpoint-url http://localhost:8000
  1. 创建Author表(信息合并到User表中)
aws dynamodb create-table --table-name Author
  --attribute-definitions AttributeName=authorId,AttributeType=S
  --key-schema AttributeName=authorId,KeyType=HASH
  --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
  --endpoint-url http://localhost:8000
  1. 创建Archive表
aws dynamodb create-table --table-name Archive
  --attribute-definitions AttributeName=archiveId,AttributeType=S AttributeName=attachId,AttributeType=S
  --key-schema AttributeName=archiveId,KeyType=HASH
  --global-secondary-indexes IndexName=attachIndex,KeySchema=[{AttributeName=attachId,KeyType=HASH}],Projection={ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=5,WriteCapacityUnits=5}
  --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
  --endpoint-url http://localhost:8000
  1. 创建User表
aws dynamodb create-table --table-name User
  --attribute-definitions AttributeName=userId,AttributeType=S AttributeName=username,AttributeType=S
  --key-schema AttributeName=userId,KeyType=HASH
  --global-secondary-indexes IndexName=usernameIndex,KeySchema=[{AttributeName=username,KeyType=HASH}],Projection={ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=5,WriteCapacityUnits=5}
  --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
  --endpoint-url http://localhost:8000
  1. 创建Assets表
aws dynamodb create-table --table-name Assets
  --attribute-definitions AttributeName=assetKey,AttributeType=S AttributeName=attachKey,AttributeType=S
  --key-schema AttributeName=assetKey,KeyType=HASH
  --global-secondary-indexes IndexName=attachIndex,KeySchema=[{AttributeName=attachKey,KeyType=HASH}],Projection={ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=5,WriteCapacityUnits=5}
  --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
  --endpoint-url http://localhost:8000

Clone this wiki locally