How to query local dynamoDB using dynamoose?

半世苍凉 提交于 2019-12-11 02:43:51

问题


As a developer, i don't want to connect all the time to Amazon web services, and I installed DynamoDB in my local computer referring the AWS Docs. I am using node.js in the backend.

I am using dynamoose as the modeling tool for Amazon's DynamoDB in my production, How can I use the same dynamoose for querying my local DynamoDB tables for development?


回答1:


You just use this in your code:

dynamoose.local();

Assuming you have a properties file in your application, you probably want a property flag to indicate whether you are in Development or Production. Then in your code, get the property, if you are in Development, run the dynamoose.local() line.

EDIT: I don't code in javascript but it will be something like:

String environment = getSystemProperty('environment');
if (environment.valueOf() == "DEV") {
    dynamoose.local();
}

This assume you have a properties file in your application where you set a system property called "environment" to have a value of say "DEV" or "PROD".




回答2:


The code below should allow you to setup Dynamoose for use locally.

var dynamoose = require('dynamoose');
dynamoose.local('http://localhost:8000');

This assumes DynamoDB is running locally on port 8000. If you are not running DynamoDB Local on port 8000 you will have to update the second line above to reflect the correct port.

Edit

As mentioned in the comments you don't need to specify 'http://localhost:8000' as those are the defaults. You can of course change the port or host to be what you want if you are not using the default options of port being 8000 and host being localhost.



来源:https://stackoverflow.com/questions/48224061/how-to-query-local-dynamodb-using-dynamoose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!