ruby:你如何标记ec2实例

时间:2017-06-07 19:33:26

标签: amazon-ec2 tags cloud aws-sdk

如何使用aws ruby​​ sdk v2 run_instances方法标记ec2实例创建?

我试过了ec2.tags.create'但这只是猜测。

更新:对github的深度搜索找到了这个片段:     ec2.create_tags(resources: [@launched_instance_id], tags: [ { key: 'Name', value: "#{@config[:service]}-ami"}])

1 个答案:

答案 0 :(得分:1)

run_instances() documentation显示:

resp = client.run_instances({
...
  tag_specifications: [
    {
      resource_type: "customer-gateway", # accepts customer-gateway, dhcp-options, image, instance, internet-gateway, network-acl, network-interface, reserved-instances, route-table, snapshot, spot-instances-request, subnet, security-group, volume, vpc, vpn-connection, vpn-gateway
      tags: [
        {
          key: "String",
          value: "String",
        },
      ],
    },
  ],
...

您还可以使用create_tags()启动实例标记后的实例:

resp = client.create_tags({
  resources: [
    "i-abcd1234", 
  ], 
  tags: [
    {
      key: "Stack", 
      value: "production", 
    }, 
  ], 
})