Skip to content

Instantly share code, notes, and snippets.

@rjsamson
Last active August 29, 2015 14:24
Show Gist options
  • Save rjsamson/a1ba235ac109c9d6be0b to your computer and use it in GitHub Desktop.
Save rjsamson/a1ba235ac109c9d6be0b to your computer and use it in GitHub Desktop.
AWS Example
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
)
func main() {
var err error
svc := ec2.New(&aws.Config{Region: "us-east-1"})
vols, err := svc.DescribeVolumes(nil)
if err != nil {
panic(err)
}
fmt.Println("Available Volumes:\n")
for idx, vol := range vols.Volumes {
fmt.Printf("%v:\n", idx)
fmt.Println(" Volume ID: ", *vol.VolumeID)
fmt.Println(" Size: ", *vol.Size)
fmt.Println(" Tags: ")
for _, tag := range vol.Tags {
fmt.Printf(" %v: %v\n", *tag.Key, *tag.Value)
}
}
var volNum int
fmt.Println("\n\nEnter a volume #")
_, err = fmt.Scanln(&volNum)
if err != nil {
panic(err)
}
if volNum >= len(vols.Volumes) {
println("Invalid selection")
return
}
selectedVolume := vols.Volumes[volNum]
fmt.Println("\n")
fmt.Println(" Volume ID: ", *selectedVolume.VolumeID)
fmt.Println(" Size: ", *selectedVolume.Size)
fmt.Println(" Tags: ")
for _, tag := range selectedVolume.Tags {
fmt.Printf(" %v: %v\n", *tag.Key, *tag.Value)
}
description := "Snapshot from Go"
params := &ec2.CreateSnapshotInput{
VolumeID: selectedVolume.VolumeID,
Description: &description,
DryRun: nil,
}
resp, err := svc.CreateSnapshot(params)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(resp)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment