Skip to content

Commit 74e721c

Browse files
wilsongecjerad
andcommitted
migrate to aws-sdk-go-v2 (#158)
Co-authored-by: Jerad C <jeradc@amazon.com>
1 parent 992e279 commit 74e721c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1142
-2745
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,30 +405,32 @@ This is a minimal example of using the instance selector go package directly:
405405
package main
406406

407407
import (
408+
"context"
408409
"fmt"
409410

410411
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/bytequantity"
411412
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector"
412-
"github.com/aws/aws-sdk-go/aws"
413-
"github.com/aws/aws-sdk-go/aws/session"
413+
"github.com/aws/aws-sdk-go-v2/config"
414+
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
414415
)
415416

416417
func main() {
418+
// Initialize a context for the application
419+
ctx := context.Background()
420+
417421
// Load an AWS session by looking at shared credentials or environment variables
418-
// https://docs.aws.amazon.com/sdk-for-go/api/aws/session/
419-
sess, err := session.NewSession(&aws.Config{
420-
Region: aws.String("us-east-2"),
421-
})
422+
// https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk
423+
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion("us-east-2"))
422424
if err != nil {
423425
fmt.Printf("Oh no, AWS session credentials cannot be found: %v", err)
424426
return
425427
}
426428

427429
// Instantiate a new instance of a selector with the AWS session
428-
instanceSelector := selector.New(sess)
430+
instanceSelector := selector.New(ctx, cfg)
429431

430432
// Instantiate an int range filter to specify min and max vcpus
431-
vcpusRange := selector.IntRangeFilter{
433+
vcpusRange := selector.Int32RangeFilter{
432434
LowerBound: 2,
433435
UpperBound: 4,
434436
}
@@ -437,9 +439,9 @@ func main() {
437439
LowerBound: bytequantity.FromGiB(2),
438440
UpperBound: bytequantity.FromGiB(4),
439441
}
440-
// Create a string for the CPU Architecture so that it can be passed as a pointer
442+
// Create a variable for the CPU Architecture so that it can be passed as a pointer
441443
// when creating the Filter struct
442-
cpuArch := "x86_64"
444+
cpuArch := ec2types.ArchitectureTypeX8664
443445

444446
// Create a Filter struct with criteria you would like to filter
445447
// The full struct definition can be found here for all of the supported filters:
@@ -451,7 +453,7 @@ func main() {
451453
}
452454

453455
// Pass the Filter struct to the Filter function of your selector instance
454-
instanceTypesSlice, err := instanceSelector.Filter(filters)
456+
instanceTypesSlice, err := instanceSelector.Filter(ctx, filters)
455457
if err != nil {
456458
fmt.Printf("Oh no, there was an error :( %v", err)
457459
return

THIRD_PARTY_LICENSES

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ github.com/aws/amazon-ec2-instance-selector (Apache-2.0) Third Party Licenses:
55
AWS SDK for Go
66
Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
77
Copyright 2014-2015 Stripe, Inc.
8+
** aws-sdk-go-v2; version v1.29.33 -- https://github.com/aws/aws-sdk-go-v2
9+
AWS SDK for Go
10+
Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
11+
Copyright 2014-2015 Stripe, Inc.
12+
** smithy-go; version v1.13.3 -- https://github.com/aws/smithy-go
13+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
14+
** configsources; version v1.1.22 -- https://github.com/aws/aws-sdk-go-v2/internal/configsources
15+
** ini; version v1.13.23 -- https://github.com/aws/aws-sdk-go-v2/internal/ini
16+
** endpoints; version v2.4.16 -- https://github.com/aws/aws-sdk-go-v2/internal/endpoints
17+
** config; version v1.17.6 -- https://github.com/aws/aws-sdk-go-v2/config
18+
** ec2; version v1.57.0 -- https://github.com/aws/aws-sdk-go-v2/service/ec2
19+
** presigned-url; version v1.9.16 -- https://github.com/aws/aws-sdk-go-v2/service/internal/presigned-url
20+
** ssooidc; version v1.13.4 -- https://github.com/aws/aws-sdk-go-v2/service/ssooidc
21+
** credentials; version v1.12.19 -- https://github.com/aws/aws-sdk-go-v2/credentials
22+
** imds; version v1.12.16 -- https://github.com/aws/aws-sdk-go-v2/feature/ec2/imds
23+
** pricing; version v1.17.0 -- https://github.com/aws/aws-sdk-go-v2/service/pricing
24+
** sso; version v1.11.22 -- https://github.com/aws/aws-sdk-go-v2/service/sso
25+
** sts; version v1.16.18 -- https://github.com/aws/aws-sdk-go-v2/service/sts
826
** cobra; version 0.0.6 -- https://github.com/spf13/cobra
927
Copyright © 2015 Steve Francia <spf@spf13.com>
1028
** go-yaml/yaml; version v2.2.2 -- https://github.com/go-yaml/yaml
@@ -1483,4 +1501,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14831501
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14841502
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14851503
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1486-
SOFTWARE.
1504+
SOFTWARE.

cmd/examples/example1.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/bytequantity"
78
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector"
8-
"github.com/aws/aws-sdk-go/aws"
9-
"github.com/aws/aws-sdk-go/aws/session"
9+
"github.com/aws/aws-sdk-go-v2/config"
10+
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
1011
)
1112

1213
func main() {
14+
// Initialize a context for the application
15+
ctx := context.Background()
16+
1317
// Load an AWS session by looking at shared credentials or environment variables
14-
// https://docs.aws.amazon.com/sdk-for-go/api/aws/session/
15-
sess, err := session.NewSession(&aws.Config{
16-
Region: aws.String("us-east-2"),
17-
})
18+
// https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk
19+
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion("us-east-2"))
1820
if err != nil {
1921
fmt.Printf("Oh no, AWS session credentials cannot be found: %v", err)
2022
return
2123
}
2224

2325
// Instantiate a new instance of a selector with the AWS session
24-
instanceSelector := selector.New(sess)
26+
instanceSelector, err := selector.New(ctx, cfg)
27+
if err != nil {
28+
fmt.Printf("Oh no, there was an error :( %v", err)
29+
return
30+
}
2531

2632
// Instantiate an int range filter to specify min and max vcpus
27-
vcpusRange := selector.IntRangeFilter{
33+
vcpusRange := selector.Int32RangeFilter{
2834
LowerBound: 2,
2935
UpperBound: 4,
3036
}
@@ -33,9 +39,9 @@ func main() {
3339
LowerBound: bytequantity.FromGiB(2),
3440
UpperBound: bytequantity.FromGiB(4),
3541
}
36-
// Create a string for the CPU Architecture so that it can be passed as a pointer
42+
// Create a variable for the CPU Architecture so that it can be passed as a pointer
3743
// when creating the Filter struct
38-
cpuArch := "x86_64"
44+
cpuArch := ec2types.ArchitectureTypeX8664
3945

4046
// Create a Filter struct with criteria you would like to filter
4147
// The full struct definition can be found here for all of the supported filters:
@@ -47,7 +53,7 @@ func main() {
4753
}
4854

4955
// Pass the Filter struct to the Filter function of your selector instance
50-
instanceTypesSlice, err := instanceSelector.Filter(filters)
56+
instanceTypesSlice, err := instanceSelector.Filter(ctx, filters)
5157
if err != nil {
5258
fmt.Printf("Oh no, there was an error :( %v", err)
5359
return

0 commit comments

Comments
 (0)