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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值