Using SimpleDB database With AWS Lambda In NodeJS
Posted By : Ankit Uniyal | 25-Dec-2017
In this blog, we will give you a brief description of the SimpleDB database and how to connect with SimpleDB database in NodeJS under AWS Lambda environment.
SimpleDB database is a highly available NoSQL database which stores data in key-value pairs.
Some of the limitations on SimpleDB database :
1.Maximum domain size allowed is to be 10 GB per domain.
2.We can delete maximum 25 attributes in a single operation of the batchDeleteAttributes method of SimpleDB.
3.Maximum 1 billion attributes allowed per domain.
4.Truncate or deleting all attributes operation doesn't provide by SimpleDB domain.
Below are the various methods to query SimpleDB database in NodeJS :
var AWS = require('aws-sdk');
var simpledb = new AWS.SimpleDB({
endpoint: 'your_endpoint',
region: 'your_region',
keyid: 'your_keyid',
secret: 'your_secret_key'
});
1.To list all the domains in SimpleDB database :
var params = {
DomainName: 'your_domain_name'
};
simpledb.listDomains(function(error, result, data) {
if (error) {
console.log("Error on domain listing is", error);
} else {
console.log("Listed domains", result);
}
});
2.To create a domain in SimpleDB database :
var params = {
DomainName: 'your_domain_name'
};
simpledb.createDomain(params, function(err, data) {
if (err) {
console.log("Error on domain creation is", err);
} else {
console.log("Domain created", data);
}
});
3.Delete SimpleDB domain database :
var params = {
DomainName: 'your_domain_name'
};
simpledb.deleteDomain(params, function(err, response) {
if (err) {
console.log("Error on getting attributes", err);
} else {
console.log("response for deleting domain is", response);
}
})
4.Select Query in SimpleDB database :
var params = {
SelectExpression: "select * from 'your_domain_name' where attributeField = 'attributeValue',
ConsistentRead: true
};
simpledb.select(params, function(err,response) {
if (err) {
console.log("Error on getting attributes",err);
} else {
console.log("response is",response);
}
});
var params = {
Attributes: attributesArray,
DomainName: 'your_domain_name',
ItemName: 'item_name'
};
params['Expected'] = {
Exists: true,
Name: 'existing_attribute_field',
Value: 'previous_attribute_field_value'
}
simpledb.putAttributes(params, function(err, data) {
if (err) {
console.log("Error on adding attributes", err);
} else {
console.log("Attributes added successfully", data);
}
});
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Ankit Uniyal
Ankit has knowledge in Javascript, NodeJS, AngularJS and MongoDB also have experience in using AWS Services.