Pythonbotoを使用してAmazonEc2インスタンスを作成できると思われるサンプルコードをいくつか見つけました。しかし、私の人生では、インスタンスを削除する関数を作成する方法を理解することはできません。
Pythonとbotoについてもう少し知っている人は、このインスタンスを削除するために私が何をすべきかを教えてもらえますか?
# Delete EC2 instance
def delete_server():
print(_yellow("Deleting EC2 instance"))
# Create EC2 instance
def create_server():
print(_yellow("Creating EC2 instance"))
image = conn.get_all_images(ec2_amis)
reservation = image[0].run(1, 1, key_name=ec2_key_pair, security_groups=ec2_security,
instance_type=ec2_instancetype)
instance = reservation.instances[0]
conn.create_tags([instance.id], {"Name":config['INSTANCE_NAME_TAG']})
while instance.state == u'pending':
print(_yellow("Instance state: %s" % instance.state))
time.sleep(10)
instance.update()
print(_green("Instance state: %s" % instance.state))
print(_green("Public dns: %s" % instance.public_dns_name))
return instance.public_dns_name