Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ec2gaming.bat
scripts/ec2gaming-permissionpolicy.json
scripts/ec2gaming.ovpn
scripts/ec2gaming.rdp
ec2gaming

8 changes: 8 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

var (
ProductDescriptionWindows = "Windows"
InstanceType = "g2.2xlarge"
UsWest1 = "us-west-1"
UsWest2 = "us-west-2"
)
36 changes: 36 additions & 0 deletions ec2gaming.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"fmt"
"github.com/urfave/cli"
"os"
)

func main() {
app := cli.NewApp()
app.Name = "ec2gaming"
app.Usage = "macOS EC2 Gaming with Steam In-Home Streaming"
app.Commands = []cli.Command{
{
Name: "start",
Usage: "starts instance, VPN and Steam",
Action: func(*cli.Context) error {
spotPrice, err := fmt.Println(SpotPrice())
fmt.Println(spotPrice)
return err
},
},
{
Name: "stop",
Usage: "stops instance & vpn",
Action: func(*cli.Context) error {
fmt.Println("stop")
return nil

},
},
}

app.Run(os.Args)

}
60 changes: 60 additions & 0 deletions spot_price.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"sort"
"strconv"
"time"
)

type SpotPriceHistory []*ec2.SpotPrice

func (spotPriceHistory SpotPriceHistory) Len() int {
return len(spotPriceHistory)
}

func (spotPriceHistory SpotPriceHistory) Less(i, j int) bool {
price1, err := strconv.ParseFloat(*spotPriceHistory[i].SpotPrice, 32)
if err != nil {
panic(err)
}
price2, err := strconv.ParseFloat(*spotPriceHistory[j].SpotPrice, 32)
if err != nil {
panic(err)
}
return price1 < price2
}

func (spotPriceHistory SpotPriceHistory) Swap(i, j int) {
spotPriceHistory[i], spotPriceHistory[j] = spotPriceHistory[j], spotPriceHistory[i]
}

func SpotPrice() (string, error) {
now := time.Now()
then := time.Now().Add(time.Duration(-1) * time.Hour)
instanceTypes := []*string{&InstanceType}
productDescriptions := []*string{&ProductDescriptionWindows}
session, err := session.NewSession()
if err != nil {
fmt.Println(err)
return "", err
}

svc := ec2.New(session, &aws.Config{Region: aws.String(UsWest1)})

result, err := svc.DescribeSpotPriceHistory(&ec2.DescribeSpotPriceHistoryInput{
StartTime: &then,
EndTime: &now,
InstanceTypes: instanceTypes,
ProductDescriptions: productDescriptions,
})
if err != nil {
fmt.Println(err)
return "", err
}
sort.Sort(SpotPriceHistory(result.SpotPriceHistory))
return *result.SpotPriceHistory[0].SpotPrice, nil
}
11 changes: 11 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/.godoc_config

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/.yardopts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/Gemfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading