Skip to content

Commit 0256428

Browse files
digocorbelliniRodrigo Okamotohakmanbwagner5
authored
CLI Instance Sorting (#146)
* created sorting system based on json pathing * incorporated sorting system into CLI * added shorthand sorting fields * Revert "Handle pricing api change in aws-sdk-go 1.44.46 (#145) * Revert "Handle pricing api change in aws-sdk-go 1.44.46 (#140)" This reverts commit cec208c. * Update aws-sdk-go to v1.44.59 * added sorting example and new help printout to readme * added jsonpath library license to third party licenses * changed sorting to use sort.Slice() * removed need for $ in json path * shortened sort-by flag description and updated readme * early sort return for empty and 1 element lists * added sorter tests * fixed typos * reduced scope of if statement in main Co-authored-by: Brandon Wagner <bmwagner10@gmail.com> * simplified call to sort instances * modified tests for new sorting interface * fixed comment typo * refactored sorting keys map Co-authored-by: Rodrigo Okamoto <rodocp@amazon.com> Co-authored-by: Ciprian Hacman <ciprian@hakman.dev> Co-authored-by: Brandon Wagner <bmwagner10@gmail.com>
1 parent 5bffbf2 commit 0256428

File tree

10 files changed

+1799
-37
lines changed

10 files changed

+1799
-37
lines changed

README.md

Lines changed: 146 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,148 @@ t3.medium 2 4 nitro true true
146146
t3a.medium 2 4 nitro true true x86_64 Up to 5 Gigabit 3 0 0 $0.0376 $0.01431
147147
```
148148

149+
**Sort by memory in ascending order using shorthand**
150+
```
151+
$ ec2-instance-selector -r us-east-1 -o table-wide --max-results 10 --sort-by memory --sort-direction asc
152+
Instance Type VCPUs Mem (GiB) Hypervisor Current Gen Hibernation Support CPU Arch Network Performance ENIs GPUs GPU Mem (GiB) GPU Info On-Demand Price/Hr Spot Price/Hr (30d avg)
153+
------------- ----- --------- ---------- ----------- ------------------- -------- ------------------- ---- ---- ------------- -------- ------------------ -----------------------
154+
t2.nano 1 0.5 xen true true i386, x86_64 Low to Moderate 2 0 0 $0.0058 -Not Fetched-
155+
t4g.nano 2 0.5 nitro true false arm64 Up to 5 Gigabit 2 0 0 $0.0042 $0.0013
156+
t3a.nano 2 0.5 nitro true true x86_64 Up to 5 Gigabit 2 0 0 $0.0047 $0.00178
157+
t3.nano 2 0.5 nitro true true x86_64 Up to 5 Gigabit 2 0 0 $0.0052 $0.0016
158+
t1.micro 1 0.6123 xen false false i386, x86_64 Very Low 2 0 0 $0.02 $0.00213
159+
t3a.micro 2 1 nitro true true x86_64 Up to 5 Gigabit 2 0 0 $0.0094 $0.00332
160+
t3.micro 2 1 nitro true true x86_64 Up to 5 Gigabit 2 0 0 $0.0104 $0.0031
161+
t2.micro 1 1 xen true true i386, x86_64 Low to Moderate 2 0 0 $0.0116 $0.0035
162+
t4g.micro 2 1 nitro true false arm64 Up to 5 Gigabit 2 0 0 $0.0084 $0.0025
163+
m1.small 1 1.69922 xen false false i386, x86_64 Low 2 0 0 $0.044 $0.00865
164+
NOTE: 547 entries were truncated, increase --max-results to see more
165+
```
166+
Available shorthand flags: vcpus, memory, gpu-memory-total, network-interfaces, spot-price, on-demand-price, instance-storage, ebs-optimized-baseline-bandwidth, ebs-optimized-baseline-throughput, ebs-optimized-baseline-iops, gpus, inference-accelerators
167+
168+
**Sort by memory in descending order using JSON path**
169+
```
170+
$ ec2-instance-selector -r us-east-1 -o table-wide --max-results 10 --sort-by .MemoryInfo.SizeInMiB --sort-direction desc
171+
Instance Type VCPUs Mem (GiB) Hypervisor Current Gen Hibernation Support CPU Arch Network Performance ENIs GPUs GPU Mem (GiB) GPU Info On-Demand Price/Hr Spot Price/Hr (30d avg)
172+
------------- ----- --------- ---------- ----------- ------------------- -------- ------------------- ---- ---- ------------- -------- ------------------ -----------------------
173+
u-12tb1.112xlarge 448 12,288 nitro true false x86_64 100 Gigabit 15 0 0 $109.2 -Not Fetched-
174+
u-9tb1.112xlarge 448 9,216 nitro true false x86_64 100 Gigabit 15 0 0 $81.9 -Not Fetched-
175+
u-6tb1.112xlarge 448 6,144 nitro true false x86_64 100 Gigabit 15 0 0 $54.6 -Not Fetched-
176+
u-6tb1.56xlarge 224 6,144 nitro true false x86_64 100 Gigabit 15 0 0 $46.40391 -Not Fetched-
177+
x2iedn.metal 128 4,096 none true false x86_64 100 Gigabit 15 0 0 $26.676 $8.0028
178+
x2iedn.32xlarge 128 4,096 nitro true false x86_64 100 Gigabit 15 0 0 $26.676 $8.0028
179+
x1e.32xlarge 128 3,904 xen true false x86_64 25 Gigabit 8 0 0 $26.688 $8.03461
180+
x2iedn.24xlarge 96 3,072 nitro true false x86_64 75 Gigabit 15 0 0 $20.007 $13.23032
181+
u-3tb1.56xlarge 224 3,072 nitro true false x86_64 50 Gigabit 8 0 0 $27.3 -Not Fetched-
182+
x2idn.metal 128 2,048 none true false x86_64 100 Gigabit 15 0 0 $13.338 $4.67017
183+
NOTE: 547 entries were truncated, increase --max-results to see more
184+
```
185+
JSON path must point to a field in the [instancetype.Details struct](https://github.com/aws/amazon-ec2-instance-selector/blob/5bffbf2750ee09f5f1308bdc8d4b635a2c6e2721/pkg/instancetypes/instancetypes.go#L37).
186+
187+
**Example output of instance type object using Verbose output**
188+
```
189+
$ ec2-instance-selector --max-results 1 -v
190+
[
191+
{
192+
"AutoRecoverySupported": true,
193+
"BareMetal": false,
194+
"BurstablePerformanceSupported": false,
195+
"CurrentGeneration": false,
196+
"DedicatedHostsSupported": true,
197+
"EbsInfo": {
198+
"EbsOptimizedInfo": {
199+
"BaselineBandwidthInMbps": 1750,
200+
"BaselineIops": 10000,
201+
"BaselineThroughputInMBps": 218.75,
202+
"MaximumBandwidthInMbps": 3500,
203+
"MaximumIops": 20000,
204+
"MaximumThroughputInMBps": 437.5
205+
},
206+
"EbsOptimizedSupport": "default",
207+
"EncryptionSupport": "supported",
208+
"NvmeSupport": "required"
209+
},
210+
"FpgaInfo": null,
211+
"FreeTierEligible": false,
212+
"GpuInfo": null,
213+
"HibernationSupported": false,
214+
"Hypervisor": "nitro",
215+
"InferenceAcceleratorInfo": null,
216+
"InstanceStorageInfo": null,
217+
"InstanceStorageSupported": false,
218+
"InstanceType": "a1.2xlarge",
219+
"MemoryInfo": {
220+
"SizeInMiB": 16384
221+
},
222+
"NetworkInfo": {
223+
"DefaultNetworkCardIndex": 0,
224+
"EfaInfo": null,
225+
"EfaSupported": false,
226+
"EnaSupport": "required",
227+
"EncryptionInTransitSupported": false,
228+
"Ipv4AddressesPerInterface": 15,
229+
"Ipv6AddressesPerInterface": 15,
230+
"Ipv6Supported": true,
231+
"MaximumNetworkCards": 1,
232+
"MaximumNetworkInterfaces": 4,
233+
"NetworkCards": [
234+
{
235+
"MaximumNetworkInterfaces": 4,
236+
"NetworkCardIndex": 0,
237+
"NetworkPerformance": "Up to 10 Gigabit"
238+
}
239+
],
240+
"NetworkPerformance": "Up to 10 Gigabit"
241+
},
242+
"PlacementGroupInfo": {
243+
"SupportedStrategies": [
244+
"cluster",
245+
"partition",
246+
"spread"
247+
]
248+
},
249+
"ProcessorInfo": {
250+
"SupportedArchitectures": [
251+
"arm64"
252+
],
253+
"SustainedClockSpeedInGhz": 2.3
254+
},
255+
"SupportedBootModes": [
256+
"uefi"
257+
],
258+
"SupportedRootDeviceTypes": [
259+
"ebs"
260+
],
261+
"SupportedUsageClasses": [
262+
"on-demand",
263+
"spot"
264+
],
265+
"SupportedVirtualizationTypes": [
266+
"hvm"
267+
],
268+
"VCpuInfo": {
269+
"DefaultCores": 8,
270+
"DefaultThreadsPerCore": 1,
271+
"DefaultVCpus": 8,
272+
"ValidCores": null,
273+
"ValidThreadsPerCore": null
274+
},
275+
"OndemandPricePerHour": 0.204,
276+
"SpotPrice": 0.03939999999999999
277+
}
278+
]
279+
NOTE: 497 entries were truncated, increase --max-results to see more
280+
```
281+
NOTE: Use this JSON format as reference when finding JSON paths for sorting
282+
149283
**All CLI Options**
150284

151285
```
152286
$ ec2-instance-selector --help
153287
```
154288

155289
```bash#help
156-
ec2-instance-selector is a CLI tool to filter EC2 instance types based on resource criteria.
290+
ec2-instance-selector is a CLI tool to filter EC2 instance types based on resource criteria.
157291
Filtering allows you to select all the instance types that match your application requirements.
158292
Full docs can be found at github.com/aws/amazon-ec2-instance-selector
159293
@@ -241,15 +375,17 @@ Suite Flags:
241375
242376
243377
Global Flags:
244-
--cache-dir string Directory to save the pricing and instance type caches (default "~/.ec2-instance-selector/")
245-
--cache-ttl int Cache TTLs in hours for pricing and instance type caches. Setting the cache to 0 will turn off caching and cleanup any on-disk caches. (default 168)
246-
-h, --help Help
247-
--max-results int The maximum number of instance types that match your criteria to return (default 20)
248-
-o, --output string Specify the output format (table, table-wide, one-line)
249-
--profile string AWS CLI profile to use for credentials and config
250-
-r, --region string AWS Region to use for API requests (NOTE: if not passed in, uses AWS SDK default precedence)
251-
-v, --verbose Verbose - will print out full instance specs
252-
--version Prints CLI version
378+
--cache-dir string Directory to save the pricing and instance type caches (default "~/.ec2-instance-selector/")
379+
--cache-ttl int Cache TTLs in hours for pricing and instance type caches. Setting the cache to 0 will turn off caching and cleanup any on-disk caches. (default 168)
380+
-h, --help Help
381+
--max-results int The maximum number of instance types that match your criteria to return (default 20)
382+
-o, --output string Specify the output format (table, table-wide, one-line)
383+
--profile string AWS CLI profile to use for credentials and config
384+
-r, --region string AWS Region to use for API requests (NOTE: if not passed in, uses AWS SDK default precedence)
385+
--sort-by string Specify the field to sort by. Quantity flags present in this CLI (memory, gpus, etc.) or a JSON path to the appropriate instance type field (Ex: ".MemoryInfo.SizeInMiB") is acceptable. (default ".InstanceType")
386+
--sort-direction string Specify the direction to sort in (ascending, asc, descending, desc) (default "ascending")
387+
-v, --verbose Verbose - will print out full instance specs
388+
--version Prints CLI version
253389
```
254390

255391

THIRD_PARTY_LICENSES

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,4 +853,31 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
853853
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
854854
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
855855
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
856-
THE SOFTWARE.
856+
THE SOFTWARE.
857+
858+
------
859+
860+
** github.com/oliveagle/jsonpath; version v0.0.0-20180606110733-2e52cf6e6852 --
861+
https://github.com/oliveagle/jsonpath
862+
863+
The MIT License (MIT)
864+
865+
Copyright (c) 2015 oliver
866+
867+
Permission is hereby granted, free of charge, to any person obtaining a copy
868+
of this software and associated documentation files (the "Software"), to deal
869+
in the Software without restriction, including without limitation the rights
870+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
871+
copies of the Software, and to permit persons to whom the Software is
872+
furnished to do so, subject to the following conditions:
873+
874+
The above copyright notice and this permission notice shall be included in all
875+
copies or substantial portions of the Software.
876+
877+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
878+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
879+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
880+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
881+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
882+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
883+
SOFTWARE.

0 commit comments

Comments
 (0)