Skip to content

Latest commit

 

History

History
112 lines (86 loc) · 2.31 KB

aws_storage.md

File metadata and controls

112 lines (86 loc) · 2.31 KB

gocloud storage - 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 disk

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

Delete disk

  deletedisk := map[string]string{
		"VolumeId": "vol-0996a16ff8f032760",
		"Region":   "us-east-1",
	}

  resp, err := amazonstorage.DeleteDisk(deletedisk)
  response := resp.(map[string]interface{})
  fmt.Println(response["body"])

Attach disk

  attachdisk := map[string]string{
		"VolumeId":   "vol-049426a70587418d7",
		"InstanceId": "i-0050d952f9b8d45d5",
		"Device":     "/dev/sdh",
		"Region":     "us-east-1",
	}

  resp, err := amazonstorage.AttachDisk(attachdisk)
  response := resp.(map[string]interface{})
  fmt.Println(response["body"])

Detach disk

 detachdisk := map[string]string{
		"VolumeId":   "vol-049426a70587418d7",
		"InstanceId": "i-0050d952f9b8d45d5",
		"Device":     "/dev/sdh",
		"Force":      "true",
		"Region":     "us-east-1",
	}

  resp, err := amazonstorage.DetachDisk(detachdisk)
  response := resp.(map[string]interface{})
  fmt.Println(response["body"])

Create snapshot

createsnapshot := map[string]string{
		"VolumeId":    "vol-047d011f7536d2b7c",
		"Description": "create snapshot for vol-047d011f7536d2b7c",
		"Region":      "us-east-1",
	}

  resp, err := amazonstorage.CreateSnapshot(createsnapshot)
  response := resp.(map[string]interface{})
  fmt.Println(response["body"])

Delete snapshot

  deletesnapshot := map[string]string{
		"SnapshotId": "snap-0f0839076356ce6cb",
		"Region":     "us-east-1",
	}

  resp, err := amazonstorage.DeleteSnapshot(deletesnapshot)
  response := resp.(map[string]interface{})
  fmt.Println(response["body"])