AWS EC2 BOTO3:Lanuch EC2实例时创建实例标签

时间:2019-09-26 10:53:34

标签: amazon-web-services boto3

我正在使用以下脚本作为启动实例,但是仍然可以提供标签(实例名称)

<form action="">
  <div class="row">
    <div class="col-md-11">
      <input type='text' class="form-control" rows="5" id="comment" placeholder="Type your Message" data-emojiable="true" data-emoji-input="unicode"></textarea>
    </div>
    <div class="col-md-1">
      <button type="submit" class="btn btn-primary " id="btn1">Submit</button>
    </div>
  </div>
</form>

2 个答案:

答案 0 :(得分:1)

是的,通过为TagSpecifications方法提供transform matrix中详细介绍的create_instances选项。

答案 1 :(得分:0)

请参见documentation。有一个示例请求格式。

instance = ec2.create_instances(
    ...
    TagSpecifications=[
        {
            'ResourceType': 'client-vpn-endpoint'|'customer-gateway'|'dedicated-host'|'dhcp-options'|'elastic-ip'|'fleet'|'fpga-image'|'host-reservation'|'image'|'instance'|'internet-gateway'|'launch-template'|'natgateway'|'network-acl'|'network-interface'|'reserved-instances'|'route-table'|'security-group'|'snapshot'|'spot-instances-request'|'subnet'|'traffic-mirror-filter'|'traffic-mirror-session'|'traffic-mirror-target'|'transit-gateway'|'transit-gateway-attachment'|'transit-gateway-route-table'|'volume'|'vpc'|'vpc-peering-connection'|'vpn-connection'|'vpn-gateway',
            'Tags': [
                {
                    'Key': 'string',
                    'Value': 'string'
                },
            ]
        },
    ],
    ...
)

您可以选择资源类型并根据需要设置标签。