使用 boto 分配 EC2-VPC ip 地址的 AuthFailure

AuthFailure for allocating EC2-VPC ip address using boto

我在 python 中写了一个脚本,用于每天轮换 Amazon EC2 实例的 ip 地址,我也释放了旧的 ip 地址,该命令运行良好,但有时脚本失败并出现以下错误响应:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
   <Errors>
      <Error>
         <Code>AuthFailure</Code>
         <Message>The address '52.87.82.238' does not belong to you.</Message>
      </Error>
   </Errors>
   <RequestID>0484b5ed-3ad9-4f86-82e6-652e6b09e072</RequestID>
</Response>

当我检查 AWS 控制台时,我发现旧的 ip 地址与实例解除关联,但仍然出现在 Elastic ips 部分。

注意:当我在 52.87.82.238 中检查该 ip 地址并手动释放它并再次重新 运行 代码时,一切正常。 故障每月发生

有什么帮助吗?

嘿,我刚刚解决了这个问题,似乎我需要在列出如下实例的 IP 地址时进行过滤:

过滤器={'instance-id': instance_id, 'domain': 'vpc', }