AMAZON DynamoDB(2)Local DB

AMAZON DynamoDB(2)Local DB

Download the latest DynamoDB on Local
>wget https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz

Put the directory to a location, command to start the DB
>java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
Initializing DynamoDB Local with the following configuration:
Port:8000
InMemory:false
DbPath:null
SharedDb:true
shouldDelayTransientStatuses:false
CorsParams:*

Some parameters
-cors               CORS for javascript
-dbPath         
-delayTransientStatuses
-help
-inMemory
-optimizeDbBeforeStartup
-port
-sharedDb     //all clients with the same set of tables

List the tables
> aws dynamodb list-tables --endpoint-url http://localhost:8000
{
    "TableNames": []
}

Command Line from Client
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.CLI.html
Create table Music, Partition Key is Artist, Sort Key is SongTitle
> aws dynamodb create-table \
>     --table-name Music \
>     --attribute-definitions \
>         AttributeName=Artist,AttributeType=S \
>         AttributeName=SongTitle,AttributeType=S \
>     --key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE \
>     --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 \
>     --endpoint-url http://localhost:8000
{
    "TableDescription": {
        "TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/Music",
        "AttributeDefinitions": [
            {
                "AttributeName": "Artist",
                "AttributeType": "S"
            },
            {
                "AttributeName": "SongTitle",
                "AttributeType": "S"
            }
        ],
        "ProvisionedThroughput": {
            "NumberOfDecreasesToday": 0,
            "WriteCapacityUnits": 1,
            "LastIncreaseDateTime": 0.0,
            "ReadCapacityUnits": 1,
            "LastDecreaseDateTime": 0.0
        },
        "TableSizeBytes": 0,
        "TableName": "Music",
        "TableStatus": "ACTIVE",
        "KeySchema": [
            {
                "KeyType": "HASH",
                "AttributeName": "Artist"
            },
            {
                "KeyType": "RANGE",
                "AttributeName": "SongTitle"
            }
        ],
        "ItemCount": 0,
        "CreationDateTime": 1520271161.651
    }
}

Put Some Data into The Table
> aws dynamodb put-item \
> --table-name Music  \
> --item \
>     '{"Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"}, "AlbumTitle": {"S": "Somewhat Famous"}}' \
> --return-consumed-capacity TOTAL \
> --endpoint-url http://localhost:8000

> aws dynamodb put-item   --table-name Music   --item '{ "Artist": {"S":"Carl Luo"}, "SongTitle": {"S": "Fly in the sky"}, "AlbumTitle":{"S": "Songs About Life"} }'   --return-consumed-capacity TOTAL   --endpoint-url http://localhost:8000

Query the data
> aws dynamodb query --table-name Music --key-conditions file:///opt/dynamodb/condition.json --endpoint-url http://localhost:8000
{
    "Count": 1,
    "Items": [
        {
            "Artist": {
                "S": "No One You Know"
            },
            "SongTitle": {
                "S": "Call Me Today"
            },
            "AlbumTitle": {
                "S": "Somewhat Famous"
            }
        }
    ],
    "ScannedCount": 1,
    "ConsumedCapacity": null
}

The condition.json file is as follow:
cat condition.json
{
    "Artist": {
        "AttributeValueList": [
            {  
                "S": "No One You Know"
            }  
        ], 
        "ComparisonOperator": "EQ"
    }, 
    "SongTitle": {
        "AttributeValueList": [
            {  
                "S": "Call Me Today"
            }  
        ], 
        "ComparisonOperator": "EQ"
    }
}

Here is one JavaScript Shell
http://localhost:8000/shell/#

Create tables and loading sample Data
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SampleData.html


References:
http://sillycat.iteye.com/blog/2410028

猜你喜欢

转载自sillycat.iteye.com/blog/2413260