github.com/openshift/installer@v1.4.17/pkg/asset/installconfig/aws/instancetypes.go (about) 1 package aws 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/aws/session" 9 "github.com/aws/aws-sdk-go/service/ec2" 10 ) 11 12 // InstanceType holds metadata for an instance type. 13 type InstanceType struct { 14 DefaultVCpus int64 15 MemInMiB int64 16 Arches []string 17 } 18 19 // instanceTypes retrieves a list of instance types for the given region. 20 func instanceTypes(ctx context.Context, session *session.Session, region string) (map[string]InstanceType, error) { 21 types := map[string]InstanceType{} 22 23 client := ec2.New(session, aws.NewConfig().WithRegion(region)) 24 if err := client.DescribeInstanceTypesPagesWithContext(ctx, 25 &ec2.DescribeInstanceTypesInput{}, 26 func(page *ec2.DescribeInstanceTypesOutput, lastPage bool) bool { 27 for _, info := range page.InstanceTypes { 28 types[*info.InstanceType] = InstanceType{ 29 DefaultVCpus: aws.Int64Value(info.VCpuInfo.DefaultVCpus), 30 MemInMiB: aws.Int64Value(info.MemoryInfo.SizeInMiB), 31 Arches: aws.StringValueSlice(info.ProcessorInfo.SupportedArchitectures), 32 } 33 } 34 return !lastPage 35 }); err != nil { 36 return nil, fmt.Errorf("fetching instance types: %w", err) 37 } 38 39 return types, nil 40 }