2016-09-13 80 views
0

我想使用ruby aws-sdk client函數Aws::EC2::Client.describe-instance-status僅返回Scheduled Events的實例列表。這是我在這個當前的嘗試:Ruby aws-sdk只爲具有事件的實例描述實例狀態

ec2 = Aws::EC2::Client.new(
    region: ENV['REGION'], 
    access_key_id: ENV['AWS_ACCESS_KEY_ID'], 
    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], 
) 

ec2_events = ec2.describe_instance_status({ 
    dry_run: false, 
    filters: [ 
    { 
     name: "events", 
     values: ["event.description"], 
    }, 
    ], 
}) 

這是我得到的錯誤信息:

/Users/myusername/.gems/gems/aws-sdk-core-2.5.11/lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call': The filter 'events' is invalid (Aws::EC2::Errors::InvalidParameterValue) 
    from /Users/myusername/.gems/gems/aws-sdk-core-2.5.11/lib/aws-sdk-core/plugins/param_converter.rb:20:in `call' 
    from /Users/myusername/.gems/gems/aws-sdk-core-2.5.11/lib/aws-sdk-core/plugins/response_paging.rb:26:in `call' 
    from /Users/myusername/.gems/gems/aws-sdk-core-2.5.11/lib/seahorse/client/plugins/response_target.rb:21:in `call' 
    from /Users/myusername/.gems/gems/aws-sdk-core-2.5.11/lib/seahorse/client/request.rb:70:in `send_request' 
    from /Users/myusername/.gems/gems/aws-sdk-core-2.5.11/lib/seahorse/client/base.rb:207:in `block (2 levels) in define_operation_methods' 
    from test.rb:30:in `<main>'  

有一個簡單的辦法有AWS-SDK稱讚了只有預定活動的實例?我知道常規的aws cli工具有這個option,但我真的想用aws-sdk gem代替。

+0

它說事件無效。 – Abhinay

回答

0

您已經混淆在代碼NameValues - 它應該被理解爲

ec2_events = ec2.describe_instance_status({ 
    dry_run: false, 
    filters: [ 
    { 
     name: "event.description", 
     values: ["events"], 
    }, 
    ], 
}) 

您可以查看完整的文檔http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstanceStatus.html

過濾器(Name)可能的值是

  • availability-zone - 實例的可用區域。
  • event.code - 計劃事件的代碼(instance-reboot | system-reboot | system-maintenance | instance-retirement | instance-stop)。
  • event.description - 事件描述。
  • event.not-after - 預定事件的最晚結束時間(例如,2014-09-15T17:15:20.000Z)。
  • event.not-before - 預定事件的最早開始時間(例如,2014-09-15T17:15:20.000Z)。
  • instance-state-code - 實例狀態的代碼,作爲16位無符號整數。高字節是一個不透明的內部值,應該忽略。低字節根據所表示的狀態設置。有效值爲0(待定),16(運行),32(關閉),48(終止),64(停止)和80(停止)。
  • instance-state-name - 實例的狀態(正在停止)。
  • instance-status.reachability - 過濾名稱爲可達性的實例狀態(通過|失敗|初始化|不足數據)。
  • instance-status.status - 實例的狀態(ok | impaired | initializing | insufficient-data | not-applicable)。
  • system-status.reachability - 名稱爲可達性的系統狀態過濾(通過|失敗|初始化|不足數據)。
  • system-status.status - 實例的系統狀態(ok | impaired | initializing | insufficient-data | not-applicable)。