Ruby aws-sdk只对具有事件的实例描述实例状态

时间:2016-09-13 18:01:15

标签: ruby amazon-web-services amazon-ec2 aws-sdk

我想使用ruby aws-sdk client函数Aws::EC2::Client.describe-instance-status仅返回Scheduled Events的实例列表。以下是我目前的尝试:

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。

1 个答案:

答案 0 :(得分: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 - 实例的状态(确定|初始化|数据不足|不适用)。
  • system-status.reachability - 过滤名称可达性的系统状态(传递|失败|初始化|数据不足)。
  • system-status.status - 实例的系统状态(确定|初始化|不足 - 数据|不适用)。