そのインスタンスタイプ、スポットインスタンス起動に対応していますか?

そのインスタンスタイプ、スポットインスタンス起動に対応していますか?

Clock Icon2022.01.15

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

本記事では「使いたいインスタンスタイプをスポットインスタンスで起動できるのか?」という疑問に対して、空きキャパシティがあるない以前にスポットインスタンス起動がサポートされているのかを AWS CLI から確認する方法を紹介します。

空きキャパシティによる中断率を確認したい方は以下のリンクをご確認ください。

調べ方まとめ

aws ec2 describe-instance-typesコマンドから確認できます。

m6i.largeを調べた実行例

オンデマンドと、スポットインスタンスが提供されていることが確認できます。

$ aws ec2 describe-instance-types --instance-types m6i.large | jq '.InstanceTypes[].SupportedUsageClasses[]'
"on-demand"
"spot"

確認するときはリージョンの指定に気をつけましょう。

リージョン指定する実行例

ついでにこの例の場合はオンデマンドのみで、スポットインスタンスは提供されていないことが確認できます。

$ aws ec2 describe-instance-types --instance-types hpc6a.48xlarge --region us-east-2 | jq '.InstanceTypes[].SupportedUsageClasses[]'
"on-demand"

スポットインスタンスとは

スポットインスタンスはAWSの余剰リソースを活用して最大90%割引でEC2を利用できる購入体系です。

各リージョンのAZごとの空きキャパシティ(スポットフリート)の需要と供給によってスポット価格(割引率)は変動します。 スポットインスタンスの特徴はEC2の中断(停止)が発生することです。空きキャパシティを利用して大幅割引を受けているため仕方がないと割り切って活用しましょう。

事の始まり

2022年1月10日に Hpc6a インスタンスが登場し、早速スポットインスタンスで起動しようと試みたところ「空きキャパシティがありません」ではなく、「スポットインスタンスに対応していません」とエラーが返ってきました。

クラウドHPCはスポットインスタンスを如何に活用できるかで計算リソースのコストが大きく変わってきます。計算中の間だけハイスペックなインスタンスタイプを複数台要求するためスポットインスタンスと相性が良いです。

なので、hpc6a.48xlarge をスポットインスタンスで起動したかったという経緯です。

スポットインスタンス対応有無の調べ方

InstanceTypeInfo の中に supportedUsageClasses があります。該当のインスタンスタイプがオンデマンド、スポットインスタンスで提供されているのかを確認できます。

AWS CLI で確認してみる

aws ec2 describe-instance-typesで調べることができます。

m6i.large インスタンスタイプで試してみます。SupportedUsageClassesの箇所でon-demandspotの文字列を確認できます。つまり、オンデマンドと、スポットインスタンスどちらも提供されているということがわかります。

$ aws ec2 describe-instance-types --instance-types m6i.large
{
    "InstanceTypes": [
        {
            "InstanceType": "m6i.large",
            "CurrentGeneration": true,
            "FreeTierEligible": false,
            "SupportedUsageClasses": [
                "on-demand",
                "spot"
            ],
            "SupportedRootDeviceTypes": [
                "ebs"
            ],
            "SupportedVirtualizationTypes": [
                "hvm"
            ],
            "BareMetal": false,
            "Hypervisor": "nitro",
            "ProcessorInfo": {
                "SupportedArchitectures": [
                    "x86_64"
                ],
                "SustainedClockSpeedInGhz": 3.5
            },
            "VCpuInfo": {
                "DefaultVCpus": 2,
                "DefaultCores": 1,
                "DefaultThreadsPerCore": 2,
                "ValidCores": [
                    1
                ],
                "ValidThreadsPerCore": [
                    1,
                    2
                ]
            },
            "MemoryInfo": {
                "SizeInMiB": 8192
            },
            "InstanceStorageSupported": false,
            "EbsInfo": {
                "EbsOptimizedSupport": "default",
                "EncryptionSupport": "supported",
                "EbsOptimizedInfo": {
                    "BaselineBandwidthInMbps": 650,
                    "BaselineThroughputInMBps": 81.25,
                    "BaselineIops": 3600,
                    "MaximumBandwidthInMbps": 10000,
                    "MaximumThroughputInMBps": 1250.0,
                    "MaximumIops": 40000
                },
                "NvmeSupport": "required"
            },
            "NetworkInfo": {
                "NetworkPerformance": "Up to 12.5 Gigabit",
                "MaximumNetworkInterfaces": 3,
                "MaximumNetworkCards": 1,
                "DefaultNetworkCardIndex": 0,
                "NetworkCards": [
                    {
                        "NetworkCardIndex": 0,
                        "NetworkPerformance": "Up to 12.5 Gigabit",
                        "MaximumNetworkInterfaces": 3
                    }
                ],
                "Ipv4AddressesPerInterface": 10,
                "Ipv6AddressesPerInterface": 10,
                "Ipv6Supported": true,
                "EnaSupport": "required",
                "EfaSupported": false,
                "EncryptionInTransitSupported": true
            },
            "PlacementGroupInfo": {
                "SupportedStrategies": [
                    "cluster",
                    "partition",
                    "spread"
                ]
            },
            "HibernationSupported": false,
            "BurstablePerformanceSupported": false,
            "DedicatedHostsSupported": true,
            "AutoRecoverySupported": true,
            "SupportedBootModes": [
                "legacy-bios",
                "uefi"
            ]
        }
    ]
}

以降は実行結果が長いためjqで必要箇所のみ表示します。

$ aws ec2 describe-instance-types --instance-types m6i.large | jq '.InstanceTypes[].SupportedUsageClasses[]'
"on-demand"
"spot"

インスタンスタイプが提供されていないケース

hpc6a.48xlarge インスタンスタイプを調べてみます。エラーが返ってきました。リージョンはap-northeast-1を指定しており、2022年1月14日現在東京では提供されていないインスタンスタイプです。

$ aws ec2 describe-instance-types --instance-types hpc6a.48xlarge | jq '.InstanceTypes[].SupportedUsageClasses[]'

An error occurred (InvalidInstanceType) when calling the DescribeInstanceTypes operation: The following supplied instance types do not exist: [hpc6a.48xlarge]

スポットインスタンスが提供されていないケース

hpc6a.48xlarge が提供されているus-east-2リージョン指定で調べてみます。on-demandのみ結果が返ってきました。スポットインスタンスが提供されていないかはここで判断できます。新インスタンスタイプはすべてリージョンに提供されているとも限りませんし、使う予定のあるリージョンで調べないと意味がないかもしれません。リージョンの指定には気をつけてください。

$ aws ec2 describe-instance-types --instance-types hpc6a.48xlarge --region us-east-2 | jq '.InstanceTypes[].SupportedUsageClasses[]'
"on-demand"

架空のインスタンスタイプを指定したケース

存在しないインスタンスタイプ c6g.ultralarge を指定してみました。インスタンスタイプが提供されていないケースと同じエラーメッセージが返ってきました。エラーメッセージからインスタンスタイプが未提供リージョンなのか、インスタンスタイプ名をタイポしたのか判断できないです。

$ aws ec2 describe-instance-types --instance-types c6g.ultralarge | jq '.InstanceTypes[].SupportedUsageClasses[]'

An error occurred (InvalidInstanceType) when calling the DescribeInstanceTypes operation: The following supplied instance types do not exist: [c6g.ultralarge]

旧世代のインスタンスタイプを指定したケース

旧世代の m1.large を指定してみました。廃止されたわけではないのでオンデマンドと、スポットインスタンスが提供されています。

$ aws ec2 describe-instance-types --instance-types m1.large | jq '.InstanceTypes[].SupportedUsageClasses[]'
"on-demand"
"spot"

AWS CLI を使った確認方法の紹介は以上です。

おわりに

空きキャパシティさえあればスポットインスタンスを使えると思っていたですが、それ以前にスポットインスタンスとして提供があるかないかの確認ポイントがあることを知りました。新インスタンス登場してすぐにスポットインスタンスで使いたい場合は、コマンドでサッと確認してみるとよいのではないでしょうか。

この記事をシェアする

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.