in python/gwlb/create_gwlb_tg_listener_sample.py [0:0]
def create_gwlb(gwlb_name, subnet_id_list):
"""
Creates a Gateway Load Balancer and resturns response and ARN
Accepts:
- gwlb_name: Gateway Load Balancer name.
- subnet_id_list: List of subnet id to be assigned to GWLB
Usage:
- create_gwlb('gwlb123', ['subnet-123'])
"""
logging.info(f"Creating gateway load balancer: {gwlb_name}")
waiter = elbv2.get_waiter('load_balancer_available')
try:
response = elbv2.create_load_balancer(
Name=gwlb_name,
Subnets=subnet_id_list,
Tags=[{'Key': 'Name', 'Value': gwlb_name}],
Type='gateway'
)
gwlb_arn = response['LoadBalancers'][0]['LoadBalancerArn']
logging.info("Waiting for GWLB's state to change to available")
waiter.wait(
LoadBalancerArns=[gwlb_arn],
WaiterConfig={
'Delay': 15,
'MaxAttempts': 40
}
)
return response, gwlb_arn
except ClientError as e:
logging.error(e)
return None