2017-06-07 32 views
0

你如何標記一個ec2實例使用aws ruby​​ sdk v2 run_instances方法創建?ruby​​:你如何標記一個ec2實例

我試過'ec2.tags.create',但那只是一個猜測。

更新:深搜索github上發現這段代碼: ec2.create_tags(resources: [@launched_instance_id], tags: [ { key: 'Name', value: "#{@config[:service]}-ami"}])

回答

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", 
    }, 
    ], 
})