Skip to content

Instantly share code, notes, and snippets.

@futoase
Created June 24, 2014 06:35
Show Gist options
  • Select an option

  • Save futoase/641f9091e1792d2cd7f7 to your computer and use it in GitHub Desktop.

Select an option

Save futoase/641f9091e1792d2cd7f7 to your computer and use it in GitHub Desktop.
example for crowdmob/goamz
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