Last active
August 29, 2015 14:24
-
-
Save rjsamson/a1ba235ac109c9d6be0b to your computer and use it in GitHub Desktop.
AWS Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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