AWS DynamoDB SampleData: создание локальных таблиц - PullRequest
0 голосов
/ 17 июня 2019

AWS Create Example Tables

Вот ссылка на 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

1 Ответ

0 голосов
/ 22 июня 2019

Вот код, который работал.

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
...