【问题标题】:How to find all ELB name that are using specific VPC in AWS via boto3?如何通过 boto3 查找在 AWS 中使用特定 VPC 的所有 ELB 名称?
【发布时间】:2019-01-07 11:46:17
【问题描述】:

我想使用 boto3 过滤并列出具有特定 vpcid 的 ELB。使用该 ELB 名称,我想使用 boto3 删除该 ELB

【问题讨论】:

    标签: python-3.x amazon-web-services boto3 vpc aws-load-balancer


    【解决方案1】:

    应该是这样的:

    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'])
    

    【讨论】:

      【解决方案2】:
      import boto3
      
      elb_client = boto3.client('elbv2', region="us-west-2")
      
      elbs = elb_client.describe_load_balancers()['LoadBalancers']
      
      elbs = [elb['LoadBalancerArn'] for elb in elbs if elb['VpcId'] == 'vpc-xxxxxxxx']
      
      for elb in elbs:
          elb_client.delete_load_balancer(LoadBalancerArn=elb)
      

      【讨论】:

        猜你喜欢
        • 2018-10-11
        • 2018-08-31
        • 2019-11-07
        • 2021-05-09
        • 1970-01-01
        • 1970-01-01
        • 2020-11-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多