Reputation: 339
I've the AWS instance type(e.g. c5.18xlarge
etc.) in my config files. During runtime, I would like to fetch the number of vCPUs(e.g. 72
) from here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/cpu-options-supported-instances-values.html and do some computations and launch instances based on the number of vCPUs.
I can store this data from the webpage in a map and refer the map, but is there a way to fetch this information from AWS using AWS go client?
Upvotes: 1
Views: 396
Reputation: 1056
You can use DescribeInstanceTypes
For example:
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
)
func main() {
sess, _ := session.NewSession(&aws.Config{
Region: aws.String("eu-west-1")},
)
svc := ec2.New(sess)
resp, _ := svc.DescribeInstanceTypes(&ec2.DescribeInstanceTypesInput{})
for _, v := range resp.InstanceTypes {
fmt.Println(*v.InstanceType, v.VCpuInfo)
}
}
Upvotes: 1