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);
      }
});
        
5.Putting Attributes in SimpleDB database :
var params = {
    Attributes: attributesArray,
    DomainName: 'your_domain_name',
    ItemName: 'item_name'
};
        
Note :
 
a. Atttributes field should be an array.
 
b. If we want to update an existing Attribute value then we can add the below field in params object.
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);
    }
});
        
Thanks

About Author

Author Image
Ankit Uniyal

Ankit has knowledge in Javascript, NodeJS, AngularJS and MongoDB also have experience in using AWS Services.

Request for Proposal

Name is required

Comment is required

Sending message..