erasing aws api gateway (a bunch of them) based on their names

#402
Raw
Created
Oct. 27, 2021, 11:14 p.m.
Expires
Never
Size
629 bytes
Hits
92
Syntax
Python
import boto3
import re
import time

client = boto3.client('apigateway')

apis = client.get_rest_apis(limit=300)

# targets all Api Gateways named like 'dailybuild_{between 100 and 299}{anything}
regex = 'dailybuild_[1-2][0-9][0-9](.*)'

# ids of Api Gateway to delete
ids = []

# builds a list of api's ids
for api in apis['items']:
    if bool(re.search(regex, api['name'])):
        ids.append(api['id'])

# # simply deletes API Gateways that ma
for id in ids:
    client.delete_rest_api(restApiId=id)
    print(f'erasing API Gateway id: {id}')
    time.sleep(300)