def destroy_ec2(region, instance_id, access_key_id, secret_access_key):
conn = connect_to_ec2(region, access_key_id, secret_access_key)<EOL>data = get_ec2_info(instance_id=instance_id,<EOL>region=region,<EOL>access_key_id=access_key_id,<EOL>secret_access_key=secret_access_key,<EOL>username=None)<EOL>instance = conn.terminate_instances(instance_ids=[data['<STR_LIT:id>']])[<NUM_LIT:0>]<EOL>log_yellow('<STR_LIT>')<EOL>while instance.state != "<STR_LIT>":<EOL><INDENT>log_yellow("<STR_LIT>" % instance.state)<EOL>sleep(<NUM_LIT:10>)<EOL>instance.update()<EOL><DEDENT>volume_id = data['<STR_LIT>']<EOL>if volume_id:<EOL><INDENT>destroy_ebs_volume(region, volume_id, access_key_id,<EOL>secret_access_key)<EOL><DEDENT>os.unlink('<STR_LIT>')<EOL>
terminates the instance