Skip to content

Instantly share code, notes, and snippets.

Last active July 23, 2020 07:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stuart-warren/b666059e0c9f0eae6f21fef7d361802e to your computer and use it in GitHub Desktop.
Ensure you have quota to create Elastic IPs in CI to avoid failing test randomly
import boto
import time
ec2 = boto3.Session(region_name="eu-west-1").client('ec2')
eips_to_create = 9
def get_eip_quota():
# get limit of ElasticIps for account
quota = 0
for acc_attr in ec2.describe_account_attributes().get('AccountAttributes'):
if acc_attr.get('AttributeName') == 'vpc-max-elastic-ips':
quota = int(acc_attr.get('AttributeValues')[0].get('AttributeValue'))
return quota
def get_eip_usage():
# get number of ElasticIps in use
return len(ec2.describe_addresses().get('Addresses'))
limit = get_eip_quota()
while True:
current = get_eip_usage()
if current + eips_to_create <= limit:
print(f'not enough quota (total: {limit}, used: {current}) to create required number of eips, sleeping...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment