mitchellh/goamz — pull request #41 by henrysher (2014-05-07 11:14:01+00:00)
Title: add the support for spot instances

Hi,

I have done the scripts to support these two APIs for spot instances also with some tests.
* RequestSpotInstances
* DescribeSpotInstanceRequests

Could you please help review the code?

Here are some __sample codes__.

For the API: **RequestSpotInstances**,
```go
package main
import (
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
)

func main() {
auth, err := aws.EnvAuth()
if err != nil {
fmt.Print(err)
return
}
e := ec2.New(auth, aws.USEast)
options := ec2.RequestSpotInstances{
SpotPrice: "0.01",
ImageId: "ami-ccf405a5", // Ubuntu Maverick, i386, EBS store
InstanceType: "m1.small",
}
resp, err := e.RequestSpotInstances(&options)
if err != nil {
fmt.Print(err)
return
}
for _, spot_request := range resp.SpotRequestResult {
fmt.Println("New Spot Request Id:", spot_request.SpotRequestId)
}
println("Make sure you terminate instances to stop the cash flow.")
}
```

For the API: **DescribeSpotInstanceRequests**,
```go
package main
import (
"fmt"
"time"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
)

func main() {
auth, err := aws.EnvAuth()
if err != nil {
fmt.Print(err)
return
}
e := ec2.New(auth, aws.USEast)
f := ec2.NewFilter()
spotId := []string{"sir-7448fe49"}
resp, err := e.DescribeSpotRequests(spotId, f)
if err != nil {
fmt.Print(err)
return
}
spotRequest := resp.SpotRequestResult[0]
fmt.Println("Spot Request Id", spotId, "with current state:", spotRequest.State)
fmt.Println("Spot Request Id", spotId, "with current instance Id:", spotRequest.InstanceId)
}

```