Friday 5 January 2018

All about NodeCloud

NodeCloud provides a unified API for all cloud providers, which supports Amazon Web Services and Google Cloud Platform.

1. Let's start off with the compute APIs and use Amazon Web Services to test.

First step is to install the NodeCloud package, either by NPM or include the package which is present in the local directory. We specify what cloud provider we are going to use, by using the getProvider API from NodeCloud. The credentials can be provided using the environment variable.

We need to specify different options to pass to the AWS SDK. We need to import the compute package from AWS SDK(EC2) before using the APIs provided by AWS. We can use the list API to check out the list of AWS instances which are present.

We can also perform actions like, stopping the instances, reboot the instance and start/stop instance. Following is the sample code.


const params = {
  DryRun: false
};

ec2.
  list(params)
  .then(res => {
    console.log(res);
  })
  .catch(err => {
    console.log(err);
  });

2. Storage APIs

The prerequisites are the same, we need to just import the S3 instances from AWS to access the storage APIs, in order to check for the storage of each instance or even create a new instance.

Here we use the bucket API and pass parameters specifying the configurations of the new instance which we want to create. Following is the sample config taken from the NodeCloud repo sample.

We can also access APIs to delete the buckets, upload blobs and data, list the buckets present.

const params = {
  Bucket: "ncbucketcr",
  CreateBucketConfiguration: {
    LocationConstraint: "us-west-2",
  },
};

s3
  .create(params)
  .then(res => {
    console.log(`Bucket created ! ${res}`);
  })
  .catch(err => {
    console.error(`Oops something happened ${err}`);
  });


3. Database APIs

Lets consider Amazon DynamoDB which is a NoSQL database. Using the NoSQL APIs, we can do create an item, Delete an item and Update an item. Following is the example to define the parameter with the object which we need to insert and the table name.

const params = {
  Item: {
    artist: {
      S: 'GG',
    },
  },
  ReturnConsumedCapacity: 'TOTAL',
  TableName: 'Test',
};

dynamoDB.createItem(params)
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.error(err);
  });

4. Network APIs

Lets see how we can interact with the DNS services inside AWS using NodeCloud network APIs.  We use Amazon Route 53 which is a Domain Name Space web service.

Let's use the DNS APIs to perform various action such as creating zones, deleting zones and displaying list of zones.

Following is the sample params object for creating a zone which contains the callerReference and Virtual Private Cloud region.

const params = {
  CallerReference: 'STRING_VALUE',
  Name: 'STRING_VALUE',
  DelegationSetId: 'STRING_VALUE',
  VPC: {
    VPCRegion: 'us-east-1',
  },
};

route53
  .createZone(params)
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.error(err);
  });


No comments:

Post a Comment