如何获取AWS boto python EC2实例中的vCPU数量?

如何获取AWS boto python EC2实例中的vCPU数量?,python,amazon-web-services,amazon-ec2,aws-sdk,boto,Python,Amazon Web Services,Amazon Ec2,Aws Sdk,Boto,有没有办法通过boto python api获取EC2实例中的vCPU(核心)数量 到目前为止,我的代码是: 在boto3中找到它: import boto3 ec2 = boto3.resource('ec2', region_name=REGION_NAME) instance = ec2.Instance(id) instance.cpu_options.get(u'CoreCount','1') 返回的是内核的物理数量,但通过htop,我可以看到我的VCPU是VCPU的两倍,

有没有办法通过boto python api获取EC2实例中的vCPU(核心)数量

到目前为止,我的代码是:

在boto3中找到它:

import boto3     
ec2 = boto3.resource('ec2', region_name=REGION_NAME)
instance = ec2.Instance(id)
instance.cpu_options.get(u'CoreCount','1')

返回的是内核的物理数量,但通过htop,我可以看到我的VCPU是VCPU的两倍,总是这样吗?可能与ThreadsPerCore的数量有关?

我是这样做的,需要最新版本的boto3:

import boto3
# You may have to update boto3 to get this to work, describe_instance_types is quite new:
# pip install boto3 --upgrade
ec2 = boto3.client('ec2')

reservations = ec2.describe_instances()['Reservations']
vcpus = 0
for reservation in reservations:
    for instance in reservation['Instances']:
        instance_id = instance['InstanceId']
        instance_type_name = instance['InstanceType']
        instance_type = ec2.describe_instance_types(InstanceTypes=[instance_type_name])
        current_vcpu_count = instance_type['InstanceTypes'][0]['VCpuInfo']['DefaultVCpus']
        print(f'{instance_id} - {instance_type_name} - {current_vcpu_count}')
        vcpus += current_vcpu_count

print(vcpus)


我是这样做的,需要最新版本的boto3:

import boto3
# You may have to update boto3 to get this to work, describe_instance_types is quite new:
# pip install boto3 --upgrade
ec2 = boto3.client('ec2')

reservations = ec2.describe_instances()['Reservations']
vcpus = 0
for reservation in reservations:
    for instance in reservation['Instances']:
        instance_id = instance['InstanceId']
        instance_type_name = instance['InstanceType']
        instance_type = ec2.describe_instance_types(InstanceTypes=[instance_type_name])
        current_vcpu_count = instance_type['InstanceTypes'][0]['VCpuInfo']['DefaultVCpus']
        print(f'{instance_id} - {instance_type_name} - {current_vcpu_count}')
        vcpus += current_vcpu_count

print(vcpus)


获取实例类型,然后按照以下步骤操作,您只能获取实例类型。类型是一些可以用来识别vcpu信息等的东西。如果你是对的,在boto3中它是可能的。注意:现在,你应该使用
boto3
,而不是原始的
boto
。旧版本无法访问最新的服务。请获取实例类型,然后按以下步骤操作,您只能获取实例类型。类型是一些可以用来识别vcpu信息等的东西。如果你是对的,在boto3中它是可能的。注意:现在,你应该使用
boto3
,而不是原始的
boto
。旧版本无法访问最新的服务。