I'm new to Amazon's Boto3
API. I created a basic diagram of my sample architecture shown below, with an ELB, 4 instances, 2 subnets and and 2 target groups in 2 different Availability Zones (2 instances in each target group).
I know how to create an EC2 instance, a target group, subnets, and an ELB. But what ELB functions to use, is not clear to me.
How I can attach the ELB to other components? Basically, how to add instances to the ELB? I'm not sure what next steps and functions are needed now.
Here is my simple code so far:
def create_load_balancer(load_balancer_name, vpcid, subnets, security_group):
command = "aws elbv2 create-load-balancer --name " + load_balancer_name + " --subnets " + subnets + " --security-groups " + security_group+" --scheme internet-facing --type application"
response = os.popen(command).read()
// ....created 4 instances, subnets, and security groups ...
//now ELB:
#Load Balancer
elb = boto3.client('elbv2')
elb.create_target_group( Name='boto3-target-a', Protocol='HTTP', Port=80, VpcId=vpc.id)
elb.create_target_group( Name='boto3-target-b', Protocol='HTTP', Port=80, VpcId=vpc.id)
response = elb.create_load_balancer(Name="elb_boto3", Listeners=[ { 'Protocol': 'tcp', 'LoadBalancerPort': 80, 'InstanceProtocol': 'tcp', 'InstancePort': 80, 'SSLCertificateId': 'string'}, ], Subnets=[subnet1,subnet2], SecurityGroups=[sec_group], Scheme='internet-facing', Type='application')