Skip to content

Commit 8ff1b10

Browse files
committed
fetch spot current price to speed up loading data without caching
1 parent 14d4dfc commit 8ff1b10

20 files changed

+327
-309
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h4>A CLI tool and go library which recommends instance types based on resource criteria like vcpus and memory.</h4>
44

55
<p>
6-
<a href="https://golang.org/doc/go1.17">
6+
<a href="https://golang.org/doc/go1.23">
77
<img src="https://img.shields.io/github/go-mod/go-version/aws/amazon-ec2-instance-selector?color=blueviolet" alt="go-version">
88
</a>
99
<a href="https://opensource.org/licenses/Apache-2.0">
@@ -25,7 +25,7 @@
2525

2626
## Summary
2727

28-
There are over 270 different instance types available on EC2 which can make the process of selecting appropriate instance types difficult. Instance Selector helps you select compatible instance types for your application to run on. The command line interface can be passed resource criteria like vcpus, memory, network performance, and much more and then return the available, matching instance types.
28+
There are over 800 different instance types available on EC2 which can make the process of selecting appropriate instance types difficult. Instance Selector helps you select compatible instance types for your application to run on. The command line interface can be passed resource criteria like vcpus, memory, network performance, and much more and then return the available, matching instance types.
2929

3030
If you are using spot instances to save on costs, it is a best practice to use multiple instances types within your auto-scaling group (ASG) to ensure your application doesn't experience downtime due to one instance type being interrupted. Instance Selector will help to find a set of instance types that your application can run on.
3131

@@ -334,6 +334,9 @@ Filter Flags:
334334
-e, --ena-support Instance types where ENA is supported or required
335335
-f, --fpga-support FPGA instance types
336336
--free-tier Free Tier supported
337+
--generation int Generation of the instance type (i.e. c7i.xlarge is 7) (sets --generation-min and -max to the same value)
338+
--generation-max int Maximum Generation of the instance type (i.e. c7i.xlarge is 7) If --generation-min is not specified, the lower bound will be 0
339+
--generation-min int Minimum Generation of the instance type (i.e. c7i.xlarge is 7) If --generation-max is not specified, the upper bound will be infinity
337340
--gpu-manufacturer string GPU Manufacturer name (Example: NVIDIA)
338341
--gpu-memory-total string Number of GPUs' total memory (Example: 4 GiB) (sets --gpu-memory-total-min and -max to the same value)
339342
--gpu-memory-total-max string Maximum Number of GPUs' total memory (Example: 4 GiB) If --gpu-memory-total-min is not specified, the lower bound will be 0
@@ -385,7 +388,8 @@ Suite Flags:
385388
386389
Global Flags:
387390
--cache-dir string Directory to save the # and instance type caches (default "~/.ec2-instance-selector/")
388-
--cache-ttl int Cache TTLs in hours for # and instance type caches. Setting the cache to 0 will turn off caching and cleanup any on-disk caches. (default 168)
391+
--cache-ttl int Cache TTLs in hours for # and instance type caches. Setting the cache to 0 will turn off caching and cleanup any on-disk caches.
392+
--debug Debug - prints debug log messages
389393
-h, --help Help
390394
--max-results int The maximum number of instance types that match your criteria to return (default 20)
391395
-o, --output string Specify the output format (table, table-wide, one-line, interactive)

THIRD_PARTY_LICENSES

+2-2
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,8 @@ THE SOFTWARE.
818818

819819
------
820820

821-
** github.com/imdario/mergo; version v0.3.11 --
822-
https://github.com/imdario/mergo
821+
** dario.cat/mergo; version v1.0.1 --
822+
dario.cat/mergo
823823

824824
Copyright (c) 2013 Dario Castañé. All rights reserved.
825825
Copyright (c) 2012 The Go Authors. All rights reserved.

cmd/main.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ const (
4444
defaultRegionEnvVar = "AWS_DEFAULT_REGION"
4545
defaultProfile = "default"
4646
awsConfigFile = "~/.aws/config"
47-
spot#DaysBack = 30
47+
// 0 means the last price
48+
// increasing this results in a lot more API calls to EC2 which can slow things down
49+
spot#DaysBack = 0
4850

4951
tableOutput = "table"
5052
tableWideOutput = "table-wide"
@@ -100,6 +102,8 @@ const (
100102
freeTier = "free-tier"
101103
autoRecovery = "auto-recovery"
102104
dedicatedHosts = "dedicated-hosts"
105+
debug = "debug"
106+
generation = "generation"
103107
)
104108

105109
// Aggregate Filter Flags
@@ -206,6 +210,7 @@ Full docs can be found at github.com/aws/amazon-` + binName
206210
cli.BoolFlag(freeTier, nil, nil, "Free Tier supported")
207211
cli.BoolFlag(autoRecovery, nil, nil, "EC2 Auto-Recovery supported")
208212
cli.BoolFlag(dedicatedHosts, nil, nil, "Dedicated Hosts supported")
213+
cli.IntMinMaxRangeFlags(generation, nil, nil, "Generation of the instance type (i.e. c7i.xlarge is 7)")
209214

210215
// Suite Flags - higher level aggregate filters that return opinionated result
211216

@@ -219,9 +224,10 @@ Full docs can be found at github.com/aws/amazon-` + binName
219224
cli.ConfigStringFlag(profile, nil, nil, "AWS CLI profile to use for credentials and config", nil)
220225
cli.ConfigStringFlag(region, cli.StringMe("r"), nil, "AWS Region to use for API requests (NOTE: if not passed in, uses AWS SDK default precedence)", nil)
221226
cli.ConfigStringFlag(output, cli.StringMe("o"), nil, fmt.Sprintf("Specify the output format (%s)", strings.Join(cliOutputTypes, ", ")), nil)
222-
cli.ConfigIntFlag(cacheTTL, nil, env.WithDefaultInt("EC2_INSTANCE_SELECTOR_CACHE_TTL", 168), "Cache TTLs in hours for # and instance type caches. Setting the cache to 0 will turn off caching and cleanup any on-disk caches.")
227+
cli.ConfigIntFlag(cacheTTL, nil, env.WithDefaultInt("EC2_INSTANCE_SELECTOR_CACHE_TTL", 0), "Cache TTLs in hours for # and instance type caches. Setting the cache to 0 will turn off caching and cleanup any on-disk caches.")
223228
cli.ConfigPathFlag(cacheDir, nil, env.WithDefaultString("EC2_INSTANCE_SELECTOR_CACHE_DIR", "~/.ec2-instance-selector/"), "Directory to save the # and instance type caches")
224229
cli.ConfigBoolFlag(verbose, cli.StringMe("v"), nil, "Verbose - will print out full instance specs")
230+
cli.ConfigBoolFlag("debug", nil, nil, "Debug - prints debug log messages")
225231
cli.ConfigBoolFlag(help, cli.StringMe("h"), nil, "Help")
226232
cli.ConfigBoolFlag(version, nil, nil, "Prints CLI version")
227233
cli.ConfigStringOptionsFlag(sortDirection, nil, cli.StringMe(sorter.SortAscending), fmt.Sprintf("Specify the direction to sort in (%s)", strings.Join(cliSortDirections, ", ")), cliSortDirections)
@@ -273,6 +279,10 @@ Full docs can be found at github.com/aws/amazon-` + binName
273279
fmt.Printf("An error occurred when initialising the ec2 selector: %v", err)
274280
os.Exit(1)
275281
}
282+
if flags[debug] != nil {
283+
debugLogger := log.New(os.Stdout, time.Now().UTC().Format(time.RFC3339)+" DEBUG ", 0)
284+
instanceSelector.SetLogger(debugLogger)
285+
}
276286
shutdown := func() {
277287
if err := instanceSelector.Save(); err != nil {
278288
log.Printf("There was an error saving # caches: %v", err)
@@ -417,6 +427,7 @@ Full docs can be found at github.com/aws/amazon-` + binName
417427
FreeTier: cli.BoolMe(flags[freeTier]),
418428
AutoRecovery: cli.BoolMe(flags[autoRecovery]),
419429
DedicatedHosts: cli.BoolMe(flags[dedicatedHosts]),
430+
Generation: cli.IntRangeMe(flags[generation]),
420431
}
421432

422433
if flags[verbose] != nil {

go.mod

+33-34
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
11
module github.com/aws/amazon-ec2-instance-selector/v2
22

3-
go 1.20
3+
go 1.23
44

55
require (
6-
github.com/aws/aws-sdk-go v1.46.6
7-
github.com/aws/aws-sdk-go-v2 v1.24.0
8-
github.com/aws/aws-sdk-go-v2/config v1.26.1
9-
github.com/aws/aws-sdk-go-v2/service/ec2 v1.128.0
10-
github.com/aws/aws-sdk-go-v2/service/# v1.21.6
6+
dario.cat/mergo v1.0.1
7+
github.com/aws/aws-sdk-go-v2 v1.32.2
8+
github.com/aws/aws-sdk-go-v2/config v1.27.43
9+
github.com/aws/aws-sdk-go-v2/service/ec2 v1.182.0
10+
github.com/aws/aws-sdk-go-v2/service/# v1.32.2
1111
github.com/blang/semver/v4 v4.0.0
12-
github.com/charmbracelet/bubbles v0.16.1
13-
github.com/charmbracelet/bubbletea v0.24.2
14-
github.com/charmbracelet/lipgloss v0.7.1
15-
github.com/evertras/bubble-table v0.15.2
16-
github.com/imdario/mergo v0.3.16
12+
github.com/charmbracelet/bubbles v0.20.0
13+
github.com/charmbracelet/bubbletea v1.1.1
14+
github.com/charmbracelet/lipgloss v0.13.0
15+
github.com/evertras/bubble-table v0.17.0
1716
github.com/mitchellh/go-homedir v1.1.0
1817
github.com/muesli/termenv v0.15.2
1918
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852
2019
github.com/patrickmn/go-cache v2.1.0+incompatible
21-
github.com/spf13/cobra v1.7.0
20+
github.com/spf13/cobra v1.8.1
2221
github.com/spf13/pflag v1.0.5
2322
go.uber.org/multierr v1.11.0
2423
)
2524

2625
require (
2726
github.com/atotto/clipboard v0.1.4 // indirect
28-
github.com/aws/aws-sdk-go-v2/credentials v1.16.12 // indirect
29-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 // indirect
30-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 // indirect
31-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 // indirect
32-
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 // indirect
33-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect
34-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9 // indirect
35-
github.com/aws/aws-sdk-go-v2/service/sso v1.18.5 // indirect
36-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 // indirect
37-
github.com/aws/aws-sdk-go-v2/service/sts v1.26.5 // indirect
38-
github.com/aws/smithy-go v1.19.0 // indirect
27+
github.com/aws/aws-sdk-go-v2/credentials v1.17.41 // indirect
28+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.17 // indirect
29+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 // indirect
30+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 // indirect
31+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
32+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect
33+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2 // indirect
34+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.2 // indirect
35+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.2 // indirect
36+
github.com/aws/aws-sdk-go-v2/service/sts v1.32.2 // indirect
37+
github.com/aws/smithy-go v1.22.0 // indirect
3938
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
40-
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
39+
github.com/charmbracelet/x/ansi v0.2.3 // indirect
40+
github.com/charmbracelet/x/term v0.2.0 // indirect
41+
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
4142
github.com/inconshreveable/mousetrap v1.1.0 // indirect
42-
github.com/jmespath/go-jmespath v0.4.0 // indirect
4343
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
44-
github.com/mattn/go-isatty v0.0.18 // indirect
44+
github.com/mattn/go-isatty v0.0.20 // indirect
4545
github.com/mattn/go-localereader v0.0.1 // indirect
46-
github.com/mattn/go-runewidth v0.0.14 // indirect
47-
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
46+
github.com/mattn/go-runewidth v0.0.16 // indirect
47+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
4848
github.com/muesli/cancelreader v0.2.2 // indirect
4949
github.com/muesli/reflow v0.3.0 // indirect
50-
github.com/rivo/uniseg v0.2.0 // indirect
51-
github.com/sahilm/fuzzy v0.1.0 // indirect
52-
golang.org/x/sync v0.1.0 // indirect
53-
golang.org/x/sys v0.7.0 // indirect
54-
golang.org/x/term v0.6.0 // indirect
55-
golang.org/x/text v0.4.0 // indirect
50+
github.com/rivo/uniseg v0.4.7 // indirect
51+
github.com/sahilm/fuzzy v0.1.1 // indirect
52+
golang.org/x/sync v0.8.0 // indirect
53+
golang.org/x/sys v0.24.0 // indirect
54+
golang.org/x/text v0.16.0 // indirect
5655
)

0 commit comments

Comments
 (0)