Amazon EC2 预留实例是一种预购虚拟机实例的方式,可以获得更低的使用费用。根据 Amazon 的政策,预留实例是不可退款的,一旦购买后就无法取消并获得退款。
以下是使用 AWS SDK for Python(Boto3)取消预留实例的代码示例:
import boto3
def cancel_reserved_instances(reserved_instance_ids):
# 创建 EC2 客户端
ec2_client = boto3.client('ec2')
# 取消预留实例
response = ec2_client.cancel_reserved_instances(
ReservedInstanceIds=reserverd_instance_ids
)
return response
# 取消预留实例的 ID 列表
reserved_instance_ids = ['your-reserved-instance-id']
# 调用取消预留实例函数
response = cancel_reserved_instances(reserved_instance_ids)
print(response)
请注意,上述代码仅用于取消预留实例,并不会触发退款。