Search code examples
python-3.xamazon-web-servicesboto3vpcamazon-elb

How to find all ELB name that are using specific VPC in AWS via boto3?


I want to filter and list ELBs with specific vpcid using boto3. Using that ELB name I want to delete that ELB using boto3


Solution

  • It would be something like:

    import boto3
    
    client = boto3.client('elbv2', region="ap_southeast_2")
    
    response = client.describe_load_balancers()
    
    # Get ELBs
    for elb in response['LoadBalancers']:
        if elb['VpcId'] == 'vpc-xxx':
            # Delete ELB
            client.delete_load_balancer(LoadBalancerArn=elb['LoadBalancerArn'])