Nodejs Class Notes-fourth lesson what Dynamodb is

Source: Internet
Author: User
Tags dynamodb amazon dynamodb

This article by Vikings (http://www.cnblogs.com/vikings-blog/) original, reprint please indicate. Thank you!

I like to learn new knowledge with goals. So learn Nodejs process, do not like to see only boring grammar and concepts, like to do some practical application of things. This writing out of the code more ground gas, while writing edge learning can avoid learning fatigue, is considered entertaining.

 

So in the fourth session, I started trying to use Dynamodb in Nodejs. Why Choose Dynamodb? On the one hand it is currently the most representative NoSQL database in the cloud environment, on the other hand it is very hot abroad, it is estimated that the domestic will slowly warming up. As a result, it is better to start first, now contact with Dynamodb, lest later passive.

  

Before using Dynamodb, let's take a look at Dynamodb.

  

Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that require consistency and latency of less than 10 milliseconds. It is a fully managed cloud database that supports document and key-value storage models. Its flexible data model and reliable performance make it the perfect choice for mobile, Web, gaming, advertising technology, the Internet of things, and many other applications.

  

If you're using DYNAMODB, you'll need to create a Dynamodb instance in Amazon. Hey, it's all money. Although the study is to cost, but this cost is a bit high. Amazon also comes up with this problem, so it provides a DYNAMODB local version for development and testing. Amazon is also the industry conscience ~

  

OK, let's use the Dynamodb local version. For the introduction of Dynamodb Local in Amazon, see below:

  

The Dynamodb local version is a free download that can be run on the local computer by the DYNAMODB Service tool. With Dynamodb Local, developers can use the Dynamodb API locally to develop applications out of real DYNAMODB Web services. But you can get the same effect almost as you would with a real dynamodb Web service. Developers can create tables locally and modify the data. These changes will be recorded and tracked by Dynamodb Local. With Dynamodb, developers can get out of the DYNAMODB Web service completely, and even network connections are not needed.

  

DynamoDB Local is so good, but it can only be used for local development and testing purposes. When an app is released online, you still need to switch the database to the real Dynamodb Web service. But just the need to switch the database service, the code in the application does not need to make any changes.

  

Dynamodb Local is done, let's see how to download and use Dynamodb Local.

  

Click here to download Dynamodb Local. Please note: currently DYNAMODB local only supports jre6.x and above. If the reader current machine JRE version is too low, hehe, execute upgrade bar.

  

The downloaded Dynamodb Local is a compressed package. You can put it in any directory after decompression (say so, but it is recommended to put in a relatively easy to find the directory as well. Lest the time be long, cannot find. )

  

Open a terminal, or CMD window. Switch to the extracted directory. Perform the following command to simply test if it is normal:

Java-djava.library.path=./dynamodblocal_lib-jar DYNAMODBLOCAL.JAR-SHAREDDB

  

Under normal circumstances, the DYNAMODB service is already bound to a local 8000 port. Such as:

{dynamodb_local_2013- A- A}»java-djava.library.path=./dynamodblocal_lib-jar Dynamodblocal.jar-shareddb/d/workspaces/workspaces-nodej s/dynamodb_local_2013- A- A -- the- One  the: -:27.416: Info:oejs. server:jetty-8.1. A. v20130726 -- the- One  the: -:27.549: Info:oejs. abstractconnector:started [email protected]0.0.0.0:8000
Or the following output:

Initializing DynamoDB Local with the following configuration:
port:8000
Inmemory:false
Dbpath:null
Shareddb:true
Shoulddelaytransientstatuses:false
Corsparams: *

This depends on the JDK version.

  

Dynamodb can accept other command parameters, mainly in the following:

-cors Value-dbPath value-delaytransientstatuses-Help-inMemory-  -Port value

  

If you want to see the usage instructions for DYNAMODB, you can do Java-jar dynamodblocal.jar-help to see as shown in:

[Email protected]:~/team/andy/nodejs/src/dynamodb$ java-jar Dynamodblocal.jar-Helpusage:java-djava.library.path=./dynamodblocal_lib-jar Dynamodblocal.jar [-port <port-no.>] [-inmemory] [-Delaytransientstatuses] [-dbpath &LT;PATH&GT;][-SHAREDDB] [-cors <allow-list>] -cors <arg> Enable cors Support forJavaScript against a specific allow-List List The domains separated by, use'*'  forPublic access (the default is'*') -dbpath <path> Specify the location of your databasefile. Default is the current directory. -delaytransientstatuses when specified, DynamoDB Local would introduce delays to hold Vari ous transient table and index statuses so it simulates actual s Ervice MoreClosely. Currently works only forCREATING and DELETING Online index statuses.-Help Display DynamoDB Local usage and options.-inmemory when specified, DynamoDB Local would runinchmemory.-Optimizedbbeforestartup Optimize The underlying backing store database tables before star Ting up the server-port <port-no.> Specify a port number. Default is8000-SHAREDDB when specified, DynamoDB Local would use a single database instead of separate databases forEach credential and region . As a result, all clients would interact with the same set of tables, Regardless of their region and credential configuration. (Useful forinteracting with Local through the JS Shellinchaddition to other SDKs)

  

However, it is found in the JDK1.8 that the Execute Help command is not displayed. In other JDK versions, it can be displayed normally. It is unclear if it has anything to do with the JDK, but it does not affect the use of dynamodb.

  

Each parameter is explained below:

  

-cors <arg> 用于运行javascript的跨域访问。如果启动用了这个参数,那么就必须提供allow参数。 默认情况下是*,即允许所有请求。

-dbpath <path> Set the path where the database data files are stored. If not specified, the current directory is used to hold the data. Please note: This option is not available in conjunction with--inmemory conflicts .

-delaytransientstatuses Enable DYNAMODB delay operation. When DynamoDB local executes locally, almost all operations are done in real time with no delay. However, there is a certain delay in the actual Dynamodb Web service. Therefore, it is recommended to use this parameter if you need to be closer to the actual dynamodb scenario. However, please note that this parameter can only be as close as possible to the actual situation, but will not be the simulation of the actual situation.

-help Nothing to say, output help information. Please see above for details.

-inmemory DynamoDB Local can save the data locally or save the data to memory. The above-dbpath is saved to the local, this is saved to memory. As for the difference, one can be persistent and one cannot be sustained. Oh, besides, no difference.

-optimizedbbeforestartup If this parameter is enabled, it is preferred to initialize the underlying database when Dynamodb local starts. The thing behind this is to load the persisted data into the service. Therefore, when you use this parameter, you must use the-dbpath parameter synchronously.

-port <port-no.> default port is 8000. If 8000 is occupied, you can bind other ports with this parameter.

-SHAREDDB Dynamodb identifies a set of database files for each user by default. The user is isolated and inaccessible. But with this parameter, you can allow other users to access the user's database.

  

Well, with the use of parameters, developers can happily use Dynamodb.

  

For the rest of your time, simply say the difference between dynamodb local and the actual Dynamodb Web service:

  • DynamoDB Local does not discriminate user registration area and AWS account validity
  • DynamoDB Local does not have a throughput limit. The relevant parameters in the API are ignored. For example, users can use CreateTable Unlimited, unlimited updatetable within a day. All throughput limits will be ignored in local mode.
  • Dynamodb's execution speed is only related to the local machine configuration. Even with the delay parameter, some operations are much faster than the actual Dynamodb Web service. For example, CreateTable and deletetable are almost instantaneous, and the tables in the database are almost all active states. Only when updatetable affects the global level two index, there will be a brief creating and deleting state that will soon revert to the active state. In the actual Dynamodb service, these will consume a lot of time.
  • In Dynamodb local mode, there is strong read consistency. This is because all local operations are done locally and can almost ignore the effects of dirty data. Unless the user's machine performance is a bit low ....
  • The local mode does not record the occupied capacity. If the API requires this value to be returned, then it is nulls
  • The local mode also does not log project record information. If the API requires a return, it is also nulls
  • In the actual Dynamodb Web service, only 1MB of data is returned at a time. In local mode, this restriction is also present. However, there are some differences when querying indexes, and DynamoDB Web service calculates only the amount of data that key and value represent, and local calculates all the project data.
  • There are also differences when using DYNAMODB data streams: The shards created by Dynamodb Web Service are affected by the partitioning of the table. In local mode, the table partition does not exist. All shards are temporary, so in local mode, the program should not be overly dependent on the Shard results.

  

Well. Well, the basics of dynamodb local have been explained, and the next lesson is to try using Dynamodb in Nodejs.

OK, class. Up ~

Nodejs Class Notes-fourth lesson what Dynamodb is

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.