简体   繁体   中英

How to query local dynamoDB using dynamoose?

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?

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:

const { NODE_ENV } = process.env
if (NODE_ENV == "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".

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.

There may be a version thing, but I had to do

var dynamoose = require('dynamoose');
dynamoose.aws.ddb.local();

If you are looking for newer versions of dynamoose the correct syntax is.

dynamoose.aws.ddb.local(http://localhost:8000)

https://dynamoosejs.com/guide/Dynamoose/#dynamooseawsddblocalendpoint

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM