【问题标题】:Ruby aws-sdk describe-instance-status only for instances with eventsRuby aws-sdk describe-instance-status 仅适用于具有事件的实例
【发布时间】:2017-01-21 10:15:01
【问题描述】:

我想使用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。

【问题讨论】:

  • 它说events无效。

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


【解决方案1】:

您在代码中混淆了 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 - 实例的系统状态(正常 | 受损 | 初始化 | 数据不足 | 不适用)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-04
    • 2019-02-25
    • 2022-01-16
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    相关资源
    最近更新 更多