"billingProducts"の確認方法
課金コード(billingProduct)をどうやって取得するのかという話ですが、そのものズバリの記載が下記にあり、下記コマンドで取得できます。
curl http://169.254.169.254/latest/meta-data/product-codes
RHEL8での確認
OSに課金が発生するRHEL8の場合、"billingProducts"に"bp-6fa54006" というのが見えます。
$ curl http://169.254.169.254/latest/dynamic/instance-identity/document/ { "accountId" : "270025184181", "availabilityZone" : "ap-northeast-1a", "kernelId" : null, "ramdiskId" : null, "pendingTime" : "2019-06-02T14:03:10Z", "architecture" : "x86_64", "privateIp" : "172.31.32.137", "version" : "2017-09-30", "region" : "ap-northeast-1", "devpayProductCodes" : null, "marketplaceProductCodes" : null, "imageId" : "ami-03c6a4362c5fb8c61", "billingProducts" : [ "bp-6fa54006" ], "instanceId" : "i-0abf28d14a86f3c6c", "instanceType" : "m5a.large" }
Amazon Linux2
無料のAmazon Linux2の場合、"billingProducts"がnullですね。
$ curl http://169.254.169.254/latest/dynamic/instance-identity/document/ { "devpayProductCodes" : null, "marketplaceProductCodes" : null, "accountId" : "270025184181", "availabilityZone" : "ap-northeast-1a", "kernelId" : null, "ramdiskId" : null, "pendingTime" : "2019-06-02T14:03:47Z", "architecture" : "x86_64", "privateIp" : "172.31.37.11", "version" : "2017-09-30", "region" : "ap-northeast-1", "imageId" : "ami-0f9ae750e8274075b", "billingProducts" : null, "instanceId" : "i-0d1ca8d3b54832823", "instanceType" : "m5a.2xlarge" }
調べるに至った経緯
AMI作成手順のドキュメントにこんな記載があるのですが、「 billingProduct コード」をどうやったら確認できるのか書いてなかったので調べたものです。
Red Hat Enterprise Linux (RHEL) や SUSE Linux Enterprise Server (SLES) などの一部の Linux ディストリビューションは、AMI に関連付けられた Amazon EC2 の billingProduct コードを使用して、パッケージの更新に関するサブスクリプションのステータスを確認します