Created
June 24, 2014 06:35
-
-
Save futoase/641f9091e1792d2cd7f7 to your computer and use it in GitHub Desktop.
example for crowdmob/goamz
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 ( | |
| "github.com/crowdmob/goamz/aws" | |
| "github.com/crowdmob/goamz/ec2" | |
| "text/template" | |
| "os" | |
| "fmt" | |
| ) | |
| func main() { | |
| auth, err := aws.EnvAuth() | |
| if err != nil { | |
| panic(err) | |
| } | |
| e := ec2.New(auth, aws.APNortheast) | |
| const TableHeader = ` | |
| <table> | |
| <thead> | |
| <tr> | |
| <th> | |
| Instance id | |
| </th> | |
| <th> | |
| Instance Type | |
| </th> | |
| <th> | |
| Availabilty Zone | |
| </th> | |
| <th> | |
| State | |
| </th> | |
| <th> | |
| IP Address | |
| </th> | |
| <th> | |
| DNS Name | |
| </th> | |
| <th> | |
| LaunchTime | |
| </th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| ` | |
| const TableFooter = ` | |
| </tbody> | |
| </table> | |
| ` | |
| const InstanceLists = ` | |
| {{range .}} | |
| <tr> | |
| <td> | |
| {{.InstanceId}} | |
| </td> | |
| <td> | |
| {{.InstanceType}} | |
| </td> | |
| <td> | |
| {{.AvailabilityZone}} | |
| </td> | |
| <td> | |
| {{.State.Name}} | |
| </td> | |
| <td> | |
| {{.IPAddress}} | |
| </td> | |
| <td> | |
| {{.DNSName}} | |
| </td> | |
| <td> | |
| {{.LaunchTime}} | |
| </td> | |
| </tr> | |
| {{end}} | |
| ` | |
| t := template.Must(template.New("InstanceList").Parse(InstanceLists)) | |
| fmt.Printf(TableHeader) | |
| result, _ := e.DescribeInstances(nil, nil) | |
| for _, reservation := range result.Reservations { | |
| t.Execute(os.Stdout, reservation.Instances) | |
| } | |
| fmt.Printf(TableFooterr) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment