A modelling tool for Amazon's DynamoDB.
Inspired by Mongoose.
npm install dynamoose --save
Here's how it works, set your AWS configurations in either:
export AWS_ACCESS_KEY_ID = "Your AWS Access Key ID"
export AWS_SECRET_ACCESS_KEY = "Your AWS Secret Access Key"
export AWS_REGION = "us-east-1"
dynamoose.AWS.config.update({
accessKeyId: 'AKID',
secretAccessKey: 'SECRET',
region: 'us-east-1'
});
This simple example creates a Cat model and gets it's name after saving and re-fetching it.
const startUpAndReturnDynamo = async () => { const dynaliteServer = dynalite(); await dynaliteServer.listen(8000); return dynaliteServer; };
const createDynamooseInstance = () => { dynamoose.AWS.config.update({ accessKeyId: 'AKID', secretAccessKey: 'SECRET', region: 'us-east-1' }); dynamoose.local(); // This defaults to "http://localhost:8000" }
const createAndGetCat = async () => { const Cat = dynamoose.model('Cat', {id: Number, name: String}); const garfield = new Cat({id: 666, name: 'Garfield'}); await garfield.save(); const badCat = await Cat.get(666); return badCat; }
const bootStrap = async () => { await startUpAndReturnDynamo(); createDynamooseInstance(); const badCat = await createAndGetCat(); console.log('Never trust a smiling cat. - ' + badCat.name); }
bootStrap();