With boto, how can I name a newly spawned EC2 instance?

时光毁灭记忆、已成空白 提交于 2019-12-09 07:44:42

问题


I'm using boto to spawn a new EC2 instance based on an AMI.

The ami.run method has a number of parameters, but none for "name" - maybe it's called something different?


回答1:


import boto
c = boto.connect_ec2(ec2_key, ec2_secret)
image = c.get_image(ec2_ami)

reservation = image.run(key_name=ec2_keypair,
                        security_groups=ec2_secgroups,
                        instance_type=ec2_instancetype)

instance = reservation.instances[0]
c.create_tags([instance.id], {"Name": instance_name})



回答2:


In EC2 there's no api to change the actually name of the machine. You basically have two options.

  1. You can pass the desired name of the computer in the user-data and when the server starts run a script that will change the name of the computer.
  2. You can use an EC2 tag to name the server ec2-create-tags <instance-id> --tag:Name=<computer name>. Downside to this solution is the server wont actually update to this name. This tag is strictly for you or for when you're querying the list of servers in aws.

Generally speaking if you're at the point where you want your server to configure itself when starting up I've found that renaming your computer in EC2 just causes more trouble than it's worth. I suggest not using them if you don't have to. Using the tags or elb instances is the better way to go.



来源:https://stackoverflow.com/questions/9575148/with-boto-how-can-i-name-a-newly-spawned-ec2-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!