英文:
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)
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论