0

AWS 创建示例表

这是AWS Create Example Tables https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SampleData.CreateTables.html的链接。我想为 localhost 创建一个脚本,如下所示。我不知道该怎么做create the Reply Table。有人可以帮忙吗?

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

数据加载

这部分应该没问题,因为它是从Step 2: Load Data into Tables链接https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SampleData.LoadData.html复制的

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
4

1 回答 1

0

这是有效的代码。

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
于 2019-06-22T05:50:20.200 回答