Friday 5 January 2018

All about GoCloud

GoCloud is a Golang library which provides unified APIs to access various cloud providers APIs. It mainly expose the following five APIs for various functionalities, which we will discuss using the Amazon Web Services.


  • Compute
  • Loadbalancer
  • DNS
  • Storage
  • Container

Prerequisites will be the following. We need to mention the AWS credential in gocloudconfig.json


{
  "AWSAccessKeyID": "xxxxxxxxxxxx",
  "AWSSecretKey": "xxxxxxxxxxxx",
}


and setup the environment variables to create an AWS object to access the APIs provided by it. 


export AWSAccessKeyID =  "xxxxxxxxxxxx"
export AWSSecretKey = "xxxxxxxxxxxx"


Later, we need to initialize the GoCloud library, either by NPM or providing path to the local dir

1. Compute APIs

Compute APIs allows us to manage the cloud provider instances and servers, which allows us to use APIs to create instances, stop, start, reboot and delete a server or instance of that particular provider.

We will use the Createnode API to create an instance. We pass the parameters providing the image(configuration), type of instance and region. (EC2)


  create := map[string]interface{}{
 "ImageId":      "ami-ccf405a5",
 "InstanceType": "t1.micro",
 "Region":       "us-east-1",
  }

 resp, err := amazoncloud.Createnode(create)
 response := resp.(map[string]interface{})
 fmt.Println(response["body"])


2. Container APIs

Container APIs allows us to spin up containers over virtualized platforms. This allows us to create clusters ( group of servers or instances together), delete cluster, create and delete services. Following example demonstrates creation of a cluster. We use the Createcluster API provided by the provider. Also pass the params such as the cluster name and at which region you want to spin up one.


  createcluster := map[string]interface{}{
  "clusterName": "gocloud-test",
  "Region":      "us-east-1",
 }

 resp, err := ecscontainer.Createcluster(createcluster)

 response := resp.(map[string]interface{})
 fmt.Println(response["body"])



3. DNS APIs

DNS APIs provides a way to manage the DNS services, where we use the Amazon Route 53 web service. Using the DNS APIs one can list, delete and create DNS. Following is an example on creating a DNS service.


  createdns := map[string]interface{}{
  "name":             "rootmonk.me",
  "hostedZoneConfig": "hostedZoneConfig",
 }

 resp, err := awsdns.Createdns(createdns)

 response := resp.(map[string]interface{})
 fmt.Println(response["body"])



4. Loadbalancer APIs

Loadbalancer APIs allows one to manage the loadbalancer services. For Amazon Web Services to create, delete, attach node with loadbalancer, detach node with loadbalancer, and list load balancer. Following example shows how to delete a loadbalancer service using the Deleteloadbalancer API

  deleteloadbalancer := map[string]string{
  "LoadBalancerName": "my-load-balancer",
 }
  
  resp, err := awsloadbalancer.Deleteloadbalancer(deleteloadbalancer)
  
  response := resp.(map[string]interface{})
  fmt.Println(response["body"])

5. Storage APIs

Storage APIs provides a way to create disk(Storage), delete, attach and detach disks. Following is the example to createdisk, using the Createdisk API, where we pass params such as Region, size and the zone. 

  createdisk := map[string]interface{}{
  "AvailZone":  "us-east-1a",
  "VolumeSize": 100,
  "Region":     "us-east-1",
 }
  
  resp, err := amazonstorage.Createdisk(createdisk)
  response := resp.(map[string]interface{})
  fmt.Println(response["body"])

No comments:

Post a Comment