Skip to content

Latest commit

 

History

History
95 lines (72 loc) · 1.88 KB

aws_container.md

File metadata and controls

95 lines (72 loc) · 1.88 KB

gocloud container - AWS

Configure AWS credentials.

Create amazoncloudconfig.json in your HOME/.gocloud directory as follows:

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

You can also set the credentials as environment variables:

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

Initialize library

import "github.com/cloudlibz/gocloud/gocloud"

amazoncloud, _ := gocloud.CloudProvider(gocloud.Amazonprovider)

Create cluster

  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"])

Delete cluster

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

  resp, err := ecscontainer.DeleteCluster(deletecluster)
  response := resp.(map[string]interface{})
  fmt.Println(response["body"])

Create service

 LoadBalancers := []map[string]interface{}{{
	"containerName":    "rootmonk",
	"loadBalancerName": "us-east-2",
	},
    {
	"containerName":    "rootmonk",
	"loadBalancerName": "us-east-2",
     },
  }

  createservice := map[string]interface{}{
		"serviceName":    "ecs-simple-service",
		"taskDefinition": "ecs-demo",
		"desiredCount":   1,
		"Region":         "us-east-1",
		"LoadBalancers":  LoadBalancers,
	}

  resp, err := ecscontainer.CreateService(createservice)

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

Delete service

  deleteservice := map[string]interface{}{
	"cluster": "cluster",
	"service": "service",
	"Region":  "us-east-1",
   }

  resp, err := ecscontainer.DeleteService(deleteservice)

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