【问题标题】:How to get memory/cpu values for instance types programatically?如何以编程方式获取实例类型的内存/cpu 值?
【发布时间】:2020-11-07 23:55:49
【问题描述】:

我想以编程方式从 AWS 实例类型中找出内存/cpu 信息。假设我知道我的实例类型是 t2.medium。从此实例类型信息中,我如何获取内存和 cpu。此特定实例类型具有 4 GB RAM 和 2 个 vCPU。

【问题讨论】:

    标签: amazon-web-services amazon-ec2 boto3 aws-cli


    【解决方案1】:

    你可以调用describe-instance-types函数。

    通过调用它,您将能够获取每种实例类型的所有元数据。

    下面是一个示例输出。

    {
        "InstanceTypes": [
            {
                "InstanceType": "t2.micro",
                "CurrentGeneration": true,
                "FreeTierEligible": true,
                "SupportedUsageClasses": [
                    "on-demand",
                    "spot"
                ],
                "SupportedRootDeviceTypes": [
                    "ebs"
                ],
                "BareMetal": false,
                "Hypervisor": "xen",
                "ProcessorInfo": {
                    "SupportedArchitectures": [
                        "i386",
                        "x86_64"
                    ],
                    "SustainedClockSpeedInGhz": 2.5
                },
                "VCpuInfo": {
                    "DefaultVCpus": 1,
                    "DefaultCores": 1,
                    "DefaultThreadsPerCore": 1,
                    "ValidCores": [
                        1
                    ],
                    "ValidThreadsPerCore": [
                        1
                    ]
                },
                "MemoryInfo": {
                    "SizeInMiB": 1024
                },
                "InstanceStorageSupported": false,
                "EbsInfo": {
                    "EbsOptimizedSupport": "unsupported",
                    "EncryptionSupport": "supported"
                },
                "NetworkInfo": {
                    "NetworkPerformance": "Low to Moderate",
                    "MaximumNetworkInterfaces": 2,
                    "Ipv4AddressesPerInterface": 2,
                    "Ipv6AddressesPerInterface": 2,
                    "Ipv6Supported": true,
                    "EnaSupport": "unsupported"
                },
                "PlacementGroupInfo": {
                    "SupportedStrategies": [
                        "partition",
                        "spread"
                    ]
                },
                "HibernationSupported": false,
                "BurstablePerformanceSupported": true,
                "DedicatedHostsSupported": false,
                "AutoRecoverySupported": true
            }
        ]
    }
    

    这在 SDK 中也是可能的:

    【讨论】:

    • 太棒了。这就是我一直在寻找的。我可以从中获得更多关于网络/cpu/ram 等的信息。我知道 describe-instances 但不知道 describe-instance-types。谢谢
    • 没问题很高兴我能帮上忙 :)
    猜你喜欢
    • 1970-01-01
    • 2011-01-17
    • 2012-04-29
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 2022-08-13
    相关资源
    最近更新 更多