24小时在线 - 古典小说 - 文学小说 - 关于我们
您的当前位置:首页 > 数据库 > 其它 >

AMAZON DynamoDB(二)Local DB

来源:比特技术 编辑:比特技术网 时间:2018-04-03点击:
导读:AMAZON DynamoDB(2)Local DB AMAZON DynamoDB(2)Local
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
来源:比特技术在线(www.byte.online),欢迎分享本文,转载请保留出处!
http://www.byte.online/a/shujuku/qita/2018/399680.html
责任编辑:比特技术网

    打赏

    取消

    感谢您的支持,我会继续努力的!

    扫码支持
    扫码打赏,你说多少就多少

    打开支付宝扫一扫,即可进行扫码打赏哦

    网友评论:

    Copyright © www.byte.online 比特技术在线 版权所有 粤ICP备15038486号-3
    本站所有资料来源于网络,由个人收集整理,仅限于个人学习和研究,如果侵犯您的权益请联系我们删除!
    Top