create account

安装并配置DynamoDB本地版 by aafeng

View this thread on: hive.blogpeakd.comecency.com
· @aafeng ·
$10.47
安装并配置DynamoDB本地版
在学习和使用DynamoDB的时候,常常是先需要做一些尝试,等到一切都准备就绪后,才会在生产环境中创建数据库并导入数据。那么,能够在开发/实验阶段不使用AWS中的DynamoDB呢,毕竟要交费的?答案是肯定的。其实,AWS早就提供好了DynamoDB的本地版。一旦安装,配置好之后,所有的操作都可以针对本地的DynamoDB,这样就不会产生任何的费用了。下面总结一下如何进行安装和配置。

![image](https://user-images.githubusercontent.com/63479035/104036611-82d2dc00-51cb-11eb-8abb-96f1b4962407.png)

首先下载DynamoDB本地版压缩包:

    curl -O https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.zip

解开压缩:

    unzip dynamodb_local_latest.zip

可以看到,在dynamodb_local_latest目录下有这些文件:

    DynamoDBLocal.jar
    DynamoDBLocal_lib
    LICENSE.txt
    README.txt
    shared-local-instance.db
    third_party_licenses

原来,DynamoDB使用Java实现的。运行如下的命令启动本地的DynamoDB:

    java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

默认方式下,DynamoDB占用端口8000。可以进行一下测试,比如:列出所有的表来,当然,刚开始的时候没有任何的表:

    aws dynamodb list-tables --endpoint-url http://localhost:8000

尝试着创建一个表:

    aws dynamodb create-table \
      --table-name Accounts \
      --attribute-definitions '[
        {
            "AttributeName": "AccountName",
            "AttributeType": "S"
        }
      ]' \
      --key-schema '[
        {
            "AttributeName": "AccountName",
            "KeyType": "HASH"
        }
      ]' \
      --provisioned-throughput '{
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
      }' \
    --endpoint-url http://localhost:8000

查看一下表的结构:

    aws dynamodb describe-table \
      --table-name Accounts \
      --endpoint-url http://localhost:8000

至此,就可以在本地愉快的和DynamoDB玩耍了。。。
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 156 others
properties (23)
authoraafeng
permlink5vxaw7-dynamodb
categoryhive-105017
json_metadata{"tags":["cn","cn-reader","aws","dynamodb"],"image":["https://user-images.githubusercontent.com/63479035/104036611-82d2dc00-51cb-11eb-8abb-96f1b4962407.png"],"app":"hiveblog/0.1","format":"markdown"}
created2021-01-09 16:03:09
last_update2021-01-09 16:03:09
depth0
children0
last_payout2021-01-16 16:03:09
cashout_time1969-12-31 23:59:59
total_payout_value5.526 HBD
curator_payout_value4.943 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,523
author_reputation554,723,599,569,926
root_title安装并配置DynamoDB本地版
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id101,293,566
net_rshares49,024,865,675,056
author_curate_reward""
vote details (220)