Skip to content

Commit 338d9e8

Browse files
authored
Revert "updated readme" and "Refactoring of Filter functions" (#139)
* Revert "updated readme (#136)" This reverts commit 8d513bc. * Revert "Refactoring of Filter functions (#134)" This reverts commit fd78895.
1 parent 8d513bc commit 338d9e8

File tree

8 files changed

+410
-551
lines changed

8 files changed

+410
-551
lines changed

README.md

Lines changed: 4 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ $ ec2-instance-selector --help
153153
```
154154

155155
```bash#help
156-
ec2-instance-selector is a CLI tool to filter EC2 instance types based on resource criteria.
156+
ec2-instance-selector is a CLI tool to filter EC2 instance types based on resource criteria.
157157
Filtering allows you to select all the instance types that match your application requirements.
158158
Full docs can be found at github.com/aws/amazon-ec2-instance-selector
159159
@@ -245,7 +245,7 @@ Global Flags:
245245
--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)
246246
-h, --help Help
247247
--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, simple) (default "simple")
248+
-o, --output string Specify the output format (table, table-wide, one-line)
249249
--profile string AWS CLI profile to use for credentials and config
250250
-r, --region string AWS Region to use for API requests (NOTE: if not passed in, uses AWS SDK default precedence)
251251
-v, --verbose Verbose - will print out full instance specs
@@ -257,11 +257,8 @@ Global Flags:
257257

258258
This is a minimal example of using the instance selector go package directly:
259259

260-
**NOTE:** The example below is intended for `v3+`. For versions `v2.3.1` and earlier, refer to the following dropdown:
261-
<details>
262-
<summary>Example for v2.3.1</summary>
263-
264-
```go
260+
**cmd/examples/example1.go**
261+
```go#cmd/examples/example1.go
265262
package main
266263

267264
import (
@@ -318,81 +315,6 @@ func main() {
318315
}
319316
// Print the returned instance types slice
320317
fmt.Println(instanceTypesSlice)
321-
}
322-
```
323-
</details>
324-
325-
**cmd/examples/example1.go**
326-
```go#cmd/examples/example1.go
327-
package main
328-
329-
import (
330-
"fmt"
331-
332-
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/bytequantity"
333-
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector"
334-
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector/outputs"
335-
"github.com/aws/aws-sdk-go/aws"
336-
"github.com/aws/aws-sdk-go/aws/session"
337-
)
338-
339-
func main() {
340-
// Load an AWS session by looking at shared credentials or environment variables
341-
// https://docs.aws.amazon.com/sdk-for-go/api/aws/session/
342-
sess, err := session.NewSession(&aws.Config{
343-
Region: aws.String("us-east-2"),
344-
})
345-
if err != nil {
346-
fmt.Printf("Oh no, AWS session credentials cannot be found: %v", err)
347-
return
348-
}
349-
350-
// Instantiate a new instance of a selector with the AWS session
351-
instanceSelector := selector.New(sess)
352-
353-
// Instantiate an int range filter to specify min and max vcpus
354-
vcpusRange := selector.IntRangeFilter{
355-
LowerBound: 2,
356-
UpperBound: 4,
357-
}
358-
// Instantiate a byte quantity range filter to specify min and max memory in GiB
359-
memoryRange := selector.ByteQuantityRangeFilter{
360-
LowerBound: bytequantity.FromGiB(2),
361-
UpperBound: bytequantity.FromGiB(4),
362-
}
363-
// Create a string for the CPU Architecture so that it can be passed as a pointer
364-
// when creating the Filter struct
365-
cpuArch := "x86_64"
366-
367-
// Create a Filter struct with criteria you would like to filter
368-
// The full struct definition can be found here for all of the supported filters:
369-
// https://github.com/aws/amazon-ec2-instance-selector/blob/main/pkg/selector/types.go
370-
filters := selector.Filters{
371-
VCpusRange: &vcpusRange,
372-
MemoryRange: &memoryRange,
373-
CPUArchitecture: &cpuArch,
374-
}
375-
376-
// Pass the Filter struct to the FilteredInstanceTypes function of your
377-
// selector instance to get a list of filtered instance types and their details
378-
instanceTypesSlice, err := instanceSelector.FilterInstanceTypes(filters)
379-
if err != nil {
380-
fmt.Printf("Oh no, there was an error getting instance types: %v", err)
381-
return
382-
}
383-
384-
// Pass in your list of instance type details to the appropriate output function
385-
// in order to format the instance types as printable strings.
386-
maxResults := 100
387-
instanceTypesSlice, _, err = outputs.TruncateResults(&maxResults, instanceTypesSlice)
388-
if err != nil {
389-
fmt.Printf("Oh no, there was an error truncating instnace types: %v", err)
390-
return
391-
}
392-
instanceTypes := outputs.SimpleInstanceTypeOutput(instanceTypesSlice)
393-
394-
// Print the returned instance types slice
395-
fmt.Println(instanceTypes)
396318
}
397319
```
398320

cmd/examples/example1.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/bytequantity"
77
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector"
8-
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector/outputs"
98
"github.com/aws/aws-sdk-go/aws"
109
"github.com/aws/aws-sdk-go/aws/session"
1110
)
@@ -47,24 +46,12 @@ func main() {
4746
CPUArchitecture: &cpuArch,
4847
}
4948

50-
// Pass the Filter struct to the FilteredInstanceTypes function of your
51-
// selector instance to get a list of filtered instance types and their details
52-
instanceTypesSlice, err := instanceSelector.FilterInstanceTypes(filters)
49+
// Pass the Filter struct to the Filter function of your selector instance
50+
instanceTypesSlice, err := instanceSelector.Filter(filters)
5351
if err != nil {
54-
fmt.Printf("Oh no, there was an error getting instance types: %v", err)
52+
fmt.Printf("Oh no, there was an error :( %v", err)
5553
return
5654
}
57-
58-
// Pass in your list of instance type details to the appropriate output function
59-
// in order to format the instance types as printable strings.
60-
maxResults := 100
61-
instanceTypesSlice, _, err = outputs.TruncateResults(&maxResults, instanceTypesSlice)
62-
if err != nil {
63-
fmt.Printf("Oh no, there was an error truncating instnace types: %v", err)
64-
return
65-
}
66-
instanceTypes := outputs.SimpleInstanceTypeOutput(instanceTypesSlice)
67-
6855
// Print the returned instance types slice
69-
fmt.Println(instanceTypes)
56+
fmt.Println(instanceTypesSlice)
7057
}

0 commit comments

Comments
 (0)