Skip to content

Instantly share code, notes, and snippets.

@reedobrien
Created February 10, 2017 00:06
Show Gist options
  • Save reedobrien/292c613fd7218f5e777a2ca6f494cf3d to your computer and use it in GitHub Desktop.
Save reedobrien/292c613fd7218f5e777a2ca6f494cf3d to your computer and use it in GitHub Desktop.
Quickie to see spot instance types in an AWS Region
package main
import (
"fmt"
"log"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
)
func main() {
sess, err := session.NewSession()
apne2 := sess.Copy(&aws.Config{Region: aws.String("ap-northeast-2")})
use1Svc := ec2.New(sess)
seoulSvc := ec2.New(apne2)
use1Insts := map[string]bool{}
seoulInsts := map[string]bool{}
startTime := time.Now().AddDate(0, 0, -2)
params := &ec2.DescribeSpotPriceHistoryInput{
StartTime: &startTime,
}
out, err := seoulSvc.DescribeSpotPriceHistory(params)
if err != nil {
log.Fatal(err)
}
for _, spot := range out.SpotPriceHistory {
seoulInsts[*spot.InstanceType] = true
}
out, err = use1Svc.DescribeSpotPriceHistory(params)
if err != nil {
log.Fatal(err)
}
for _, spot := range out.SpotPriceHistory {
use1Insts[*spot.InstanceType] = true
}
fmt.Printf("%d: %#v\n", len(seoulInsts), seoulInsts)
fmt.Printf("%d: %#v\n", len(use1Insts), use1Insts)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment