Created
February 10, 2017 00:06
-
-
Save reedobrien/292c613fd7218f5e777a2ca6f494cf3d to your computer and use it in GitHub Desktop.
Quickie to see spot instance types in an AWS Region
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" | |
"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