def get_eip_allocation_id_by_address(client, eip_address, check_mode=False):
 params = {'PublicIps': [eip_address]}
 allocation_id = None
 err_msg = ''
 try:
  if (not check_mode):
   allocations = client.describe_addresses(**params)['Addresses']
   if (len(allocations) == 1):
    allocation = allocations[0]
   else:
    allocation = None
  else:
   dry_run_eip = DRY_RUN_ALLOCATION_UNCONVERTED['Addresses'][0]['PublicIp']
   if (dry_run_eip == eip_address):
    allocation = DRY_RUN_ALLOCATION_UNCONVERTED['Addresses'][0]
   else:
    allocation = None
  if allocation:
   if (allocation.get('Domain') != 'vpc'):
    err_msg = 'EIP {0} is a non-VPC EIP, please allocate a VPC scoped EIP'.format(eip_address)
   else:
    allocation_id = allocation.get('AllocationId')
  else:
   err_msg = 'EIP {0} does not exist'.format(eip_address)
 except botocore.exceptions.ClientError as e:
  err_msg = str(e)
 return (allocation_id, err_msg)

def get_eip_allocation_id_by_address ( client , eip_address , check_mode = False ) : params = { 'PublicIps' : [ eip_address ] } allocation_id = None err_msg = '' try : if ( not check_mode ) : allocations = client . describe_addresses ( ** params ) [ 'Addresses' ] if ( len ( allocations ) == 1 ) : allocation = allocations [ 0 ] else : allocation = None else : dry_run_eip = DRY_RUN_ALLOCATION_UNCONVERTED [ 'Addresses' ] [ 0 ] [ 'PublicIp' ] if ( dry_run_eip == eip_address ) : allocation = DRY_RUN_ALLOCATION_UNCONVERTED [ 'Addresses' ] [ 0 ] else : allocation = None if allocation : if ( allocation . get ( 'Domain' ) != 'vpc' ) : err_msg = 'EIP {0} is a non-VPC EIP, please allocate a VPC scoped EIP' . format ( eip_address ) else : allocation_id = allocation . get ( 'AllocationId' ) else : err_msg = 'EIP {0} does not exist' . format ( eip_address ) except botocore . exceptions . ClientError as e : err_msg = str ( e ) return ( allocation_id , err_msg )
release an eip from your eip pool args: client : boto3 client eip_address : the elastic ip address of the eip .