Open cjbern opened 10 years ago
So this is happening because the function release_address()
of the connection class requires an allocation ID if the elastic IP is a VPC EIP. the reason eip.release()
works is because that method gets the allocation id from itself, it is stored in the instance of the address object (eip
) and attempts to use the allocation id if available. See https://github.com/boto/boto/blob/develop/boto/ec2/connection.py#L2069-L2075 versus https://github.com/boto/boto/blob/develop/boto/ec2/address.py#L80-L88
You would need to do this instead in order to get around and provide the release_address()
function the information it needs:
>>> import boto, boto.ec2
>>> conn = boto.ec2.connect_to_region('us-west-1')
>>> eip = conn.allocate_address()
>>> eip
Address:54.183.213.100
>>> conn.release_address(allocation_id=eip.allocation_id)
True
>>> boto.__version__
'2.34.0'
So I've done a little bit more reading, and discovered the difference between EC2-Classic and EC2-VPC. AIUI, the public_ip keywords only apply to EC2-Classic, which is only available if you have an AWS account dating from before the introduction of EC2-VPC. Newer accounts do not have access to EC2-Classic, only EC2-VPC, so basically can only use the allocation_id keywords for the Elastic IP related methods.
So I guess I'm saying that the Boto documentation should be made to more accurately reflect what AWS currently calls objects, to avoid confusing newer users. Basically change: 'EC2 Elastic IPs' and 'VPC Elastic IPs' To: 'EC2-Classic Elastic IPs' and 'EC2-VPC Elastic IPs'.
So I withdraw stating that this is a code bug, but do state that it is currently a documentation bug.
python 3.4.0 The method fails with a 400 Bad Request error, and seems to want an allocation id, despite the fact that the EC2 public elastic IP was never assigned to a VPC allocation directly.
Omitting the keyword doesn't work either:
On the other hand, boto.ec2.address.release() does release a public Elastic IP properly: