首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >亚马逊网络服务DynamoDB SampleData:创建本地表

亚马逊网络服务DynamoDB SampleData:创建本地表
EN

Stack Overflow用户
提问于 2019-06-17 22:13:12
回答 1查看 48关注 0票数 0

AWS创建示例表

这是指向AWS Create Example Tables https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SampleData.CreateTables.html的链接。我想为本地主机创建一个脚本,如下所示。我不知道如何使用create the Reply Table。有人能帮帮忙吗?

代码语言:javascript
复制
export LOCAL="--endpoint-url http://localhost:8000"

aws dynamodb create-table \
    $LOCAL \
    --table-name ProductCatalog \
    --attribute-definitions \
        AttributeName=Id,AttributeType=N
    --key-schema \
        AttributeName=Id,KeyType=HASH \
    --provisioned-throughput \
        ReadCapacityUnits=10,WriteCapacityUnits=5

aws dynamodb create-table \
    $LOCAL \
    --table-name Forum \
    --attribute-definitions \
        AttributeName=Name,AttributeType=S
    --key-schema \
        AttributeName=Name,KeyType=HASH \
    --provisioned-throughput \
        ReadCapacityUnits=10,WriteCapacityUnits=5


aws dynamodb create-table \
    $LOCAL \
    --table-name Thread \
    --attribute-definitions \
        AttributeName=ForumName,AttributeType=S \
        AttributeName=Subject,AttributeType=S \
    --key-schema \
        AttributeName=ForumName,KeyType=HASH \
        AttributeName=Subject,KeyType=HASH \
    --provisioned-throughput \
        ReadCapacityUnits=10,WriteCapacityUnits=5


aws dynamodb create-table \
    $LOCAL \
    --table-name Reply \
    --attribute-definitions \
        AttributeName=Id,AttributeType=S
        AttributeName=ReplyDateTime,AttributeType=S
    --key-schema \
        AttributeName=Id,KeyType=HASH \
        AttributeName=ReplyDateTime,KeyType=HASH \
    --provisioned-throughput \
        ReadCapacityUnits=10,WriteCapacityUnits=5

数据加载

对于从链接https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SampleData.LoadData.html处的Step 2: Load Data into Tables复制过来的内容,这部分应该没问题

代码语言:javascript
复制
aws dynamodb batch-write-item --request-items file://ProductCatalog.json
aws dynamodb batch-write-item --request-items file://Forum.json
aws dynamodb batch-write-item --request-items file://Thread.json
aws dynamodb batch-write-item --request-items file://Reply.json
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-22 13:50:20

以下是运行正常的代码。

代码语言:javascript
复制
export LOCAL="--endpoint-url http://localhost:8000"

aws dynamodb delete-table $LOCAL \
    --table-name ProductCatalog

aws dynamodb create-table \
    $LOCAL \
    --table-name ProductCatalog \
    --attribute-definitions \
        AttributeName=Id,AttributeType=N \
    --key-schema \
        AttributeName=Id,KeyType=HASH \
    --provisioned-throughput \
        ReadCapacityUnits=10,WriteCapacityUnits=5

aws dynamodb delete-table $LOCAL \
    --table-name Forum

aws dynamodb create-table \
    $LOCAL \
    --table-name Forum \
    --attribute-definitions \
        AttributeName=Name,AttributeType=S \
    --key-schema \
        AttributeName=Name,KeyType=HASH \
    --provisioned-throughput \
        ReadCapacityUnits=10,WriteCapacityUnits=5

aws dynamodb delete-table $LOCAL \
    --table-name Thread

# https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_CreateTable.html
aws dynamodb create-table \
    $LOCAL \
    --table-name Thread \
    --attribute-definitions \
        AttributeName=ForumName,AttributeType=S \
        AttributeName=Subject,AttributeType=S \
        AttributeName=LastPostDateTime,AttributeType=S \
    --key-schema \
        AttributeName=ForumName,KeyType=HASH \
        AttributeName=Subject,KeyType=RANGE \
    --global-secondary-indexes \
       IndexName=LastPostIndex,KeySchema=["\
       {AttributeName=ForumName,KeyType=HASH}","\
       {AttributeName=LastPostDateTime,KeyType=RANGE}"],Projection="\
       {ProjectionType=ALL}",ProvisionedThroughput="\
       {ReadCapacityUnits=5,WriteCapacityUnits=5}" \
    --provisioned-throughput \
        ReadCapacityUnits=5,WriteCapacityUnits=5 \
    --tags \
        Key=Owner,Value=BlueTeam

aws dynamodb delete-table $LOCAL \
            --table-name Reply

aws dynamodb create-table $LOCAL \
    --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


# data loading

aws dynamodb batch-write-item $LOCAL --request-items file://ProductCatalog.json
aws dynamodb batch-write-item $LOCAL --request-items file://Forum.json
aws dynamodb batch-write-item $LOCAL --request-items file://Thread.json
aws dynamodb batch-write-item $LOCAL --request-items file://Reply.json
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56633135

复制
相关文章

相似问题

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