Get vCPU count for a given AWS instance type in Go using AWS client

huangapple go评论87阅读模式
英文:

Get vCPU count for a given AWS instance type in Go using AWS client

问题

我可以帮你翻译以下内容:

我在我的配置文件中有AWS实例类型(例如c5.18xlarge等)。在运行时,我想从这里获取vCPUs的数量(例如72):https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/cpu-options-supported-instances-values.html,并根据vCPUs的数量进行一些计算并启动实例。
我可以将来自网页的数据存储在一个映射中并引用该映射,但是否有一种方法可以使用AWS Go客户端从AWS获取此信息?

英文:

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?

答案1

得分: 1

你可以使用DescribeInstanceTypes

例如:

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)
	}

}
英文:

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)
	}

}


huangapple
  • 本文由 发表于 2022年7月7日 16:16:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/72894440.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定