0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AWS CLI EC2 Reserved Instance を一覧(CSV)にする

Last updated at Posted at 2021-04-12

AWS CLI を使って EC2 リザーブドインスタンスを一覧にします。

aws ec2 describe-reserved-instances --filter Name=state,Values=active | \
jq -r ".ReservedInstances[] | [.Duration, .End, .InstanceCount, .InstanceType, .ProductDescription, .State, .InstanceTenancy, .RecurringCharges[0].Amount, .OfferingClass, .OfferingType, .Scope] | @csv"

解説

2つのコマンドをパイプで繋いでいます。

JSON 取得

aws ec2 describe-reserved-instances --filter Name=state,Values=active

これでアクティブな EC2 Reserved Instance が JSON で取得できます。

結果は次のようになります。

{
    "ReservedInstances": [
        {
            "Duration": 31536000,
            "End": "2020-04-30T07:17:45+00:00",
            "FixedPrice": 0.0,
            "InstanceCount": 1,
            "InstanceType": "t2.micro",
            "ProductDescription": "Linux/UNIX (Amazon VPC)",
            "ReservedInstancesId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            "Start": "2019-04-30T07:17:46+00:00",
            "State": "active",
            "UsagePrice": 0.0,
            "CurrencyCode": "USD",
            "InstanceTenancy": "default",
            "OfferingClass": "standard",
            "OfferingType": "No Upfront",
            "RecurringCharges": [
                {
                    "Amount": 0.01000,
                    "Frequency": "Hourly"
                }
            ],
            "Scope": "Region"
        },

アクティブでないものも取得したい場合は --filter を削除します。

JSON を CSV に変換

jq コマンド を使ってCSVに変換します。 AWS CloudShell でも使えます。

jq -r ".ReservedInstances[] | [.Duration, .End, .InstanceCount, .InstanceCount, .ProductDescription, .State, .InstanceTenancy, .RecurringCharges[0].Amount, .OfferingClass, .OfferingType, .Scope] | @csv"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?