この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
はじめに
リザーブドインスタンスをAWS マネジメントコンソールで購入する場合、
古いインスタンスタイプはAWS マネジメントコンソール上に表示されない場合があります。
例えばAmazon ElastiCache memcached の cache.t1.micro です。
しかしAWS CLIで購入可能な場合があります。
今回はリザーブドインスタンスをAWS CLIで購入する方法をご紹介します。
先ほどAmazon ElastiCache memcached の cache.t1.micro が
AWS マネジメントコンソールで購入できなかったのでこちらをAWS CLIで購入してみたいと思います。
AWS-CLIでRIを購入する
Offeringの一覧を表示し購入したいOfferingのIDを確認する。
AWS CLIに設定されているデフォルトのリージョンとは違うリージョンのRIを購入する場合は --regionのオプションにて指定します。
$ aws elasticache describe-reserved-cache-nodes-offerings --region ap-northeast-1
{
"ReservedCacheNodesOfferings": [
{
"OfferingType": "Medium Utilization",
"FixedPrice": 2467.0,
"ReservedCacheNodesOfferingId": "005f8a44-4a6c-42f5-a8f7-4a411dec4481",
"UsagePrice": 0.413,
"RecurringCharges": [],
"ProductDescription": "memcached",
"Duration": 94608000,
"CacheNodeType": "cache.m2.4xlarge"
},
{
"OfferingType": "Heavy Utilization",
"FixedPrice": 2726.0,
"ReservedCacheNodesOfferingId": "0092d8df-35c3-44f2-afc5-51d8799f569e",
"UsagePrice": 0.0,
"RecurringCharges": [
{
"RecurringChargeAmount": 0.245,
"RecurringChargeFrequency": "Hourly"
}
],
"ProductDescription": "memcached",
"Duration": 94608000,
"CacheNodeType": "cache.c1.xlarge"
},
~~~~~~
コマンドを実行すると様々なタイプのリザーブドキャッシュノードが表示されますので 購入するリザーブドキャッシュノードの「ReservedCacheNodesOfferingId」を見つけてメモします。
下記が、今回購入対象です。
{
"OfferingType": "Heavy Utilization",
"FixedPrice": 62.0,
"ReservedCacheNodesOfferingId": "7b135926-9c17-4403-a8a6-46710b8ec2cb",
"UsagePrice": 0.0,
"RecurringCharges": [
{
"RecurringChargeAmount": 0.01,
"RecurringChargeFrequency": "Hourly"
}
],
"ProductDescription": "memcached",
"Duration": 31536000,
"CacheNodeType": "cache.t1.micro"
},
また、期間は秒数で表示されています。
"Duration": 31536000 1年
"Duration": 94608000 3年
購入する
購入はoffering-idを指定して下記コマンドを実行します。
$ aws elasticache purchase-reserved-cache-nodes-offering --reserved-cache-nodes-offering-id 7b135926-9c17-4403-a8a6-46710b8ec2cb
{
"ReservedCacheNode": {
"OfferingType": "Heavy Utilization",
"FixedPrice": 62.0,
"ReservedCacheNodesOfferingId": "7b135926-9c17-4403-a8a6-46710b8ec2cb",
"CacheNodeCount": 1,
"UsagePrice": 0.0,
"RecurringCharges": [
{
"RecurringChargeAmount": 0.01,
"RecurringChargeFrequency": "Hourly"
}
],
"ReservedCacheNodeId": "ri-2015-10-**-**-**-**-***",
"State": "payment-pending",
"ProductDescription": "memcached",
"StartTime": "2015-10-**T0*:**:**.***Z",
"Duration": 31536000,
"CacheNodeType": "cache.t1.micro"
}
}
これでRIの購入ができました。実際に完了したかは下記コマンドにてStateがactiveになっているか確認します。
$ aws elasticache describe-reserved-cache-nodes --reserved-cache-nodes-offering-id 7b135926-9c17-4403-a8a6-46710b8ec2cb
{
"ReservedCacheNodes": [
{
"OfferingType": "Heavy Utilization",
"FixedPrice": 62.0,
"ReservedCacheNodesOfferingId": "7b135926-9c17-4403-a8a6-46710b8ec2cb",
"CacheNodeCount": 1,
"UsagePrice": 0.0,
"RecurringCharges": [
{
"RecurringChargeAmount": 0.01,
"RecurringChargeFrequency": "Hourly"
}
],
"ReservedCacheNodeId": "ri-2015-10-**-**-**-**-***",
"State": "active",
"ProductDescription": "memcached",
"StartTime": "2015-10-**T**:**:**.***Z",
"Duration": 31536000,
"CacheNodeType": "cache.t1.micro"
}
]
}
今回はElastiCacheでの購入方法をご紹介しましたが他のプロダクトも同様にAWS CLIで購入可能です。
そのほかプロダクトのRI購入コマンド
EC2
$ aws ec2 describe-reserved-instances-offerings
$ aws ec2 purchase-reserved-instances-offering --reserved-instances-offering-id <value> --instance-count <value>
参考URL AWS CLI Command Reference | aws ec2 purchase-reserved-instances-offering
RDS
$ aws rds describe-reserved-db-instances-offerings
$ aws rds purchase-reserved-db-instances-offering --reserved-db-instances-offering-id <value>
参考URL AWS CLI Command Reference | aws rds purchase-reserved-db-instances-offering
Redsift
$ aws redshift describe-reserved-node-offerings
$ aws redshift purchase-reserved-node-offering --reserved-node-offering-id <value>
参考URL AWS CLI Command Reference | aws redshift purchase-reserved-node-offering
ElastiCache
$ aws elasticache describe-reserved-cache-nodes-offerings
$ aws elasticache purchase-reserved-cache-nodes-offering --reserved-cache-nodes-offering-id <value>
参考URL AWS CLI Command Reference | aws elasticache purchase-reserved-cache-nodes-offering
まとめ
AWS CLIでリザーブドインスタンスの購入方法をご紹介しました。
AWS マネジメントコンソールで購入できないものがあったらAWS CLIでは購入できる場合もあるので今回ご紹介した方法で試してみてください。