Skip to content

Instantly share code, notes, and snippets.

@kevit
Created May 18, 2020 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevit/04c1df9cee5405e11e478d395aad549a to your computer and use it in GitHub Desktop.
Save kevit/04c1df9cee5405e11e478d395aad549a to your computer and use it in GitHub Desktop.
def create_elb(self,subnets,name,type='app',region='us-east-1',sg=['sg-c5556eb1']):
if type == 'app':
type = 'application'
else:
type = 'network'
elb_creation = self.elbv2_client.create_load_balancer(
Name=name,
Subnets=subnets,
SecurityGroups=sg,
Scheme='internet-facing',
Tags=[
{
'Key': 'Name',
'Value': 'tomcat_elb_elb'
},
],
Type=type,
IpAddressType='ipv4'
)
def create_elb_target_grp(self,name):
target_grp = self.elbv2_client.create_target_group(
Name=name,
Protocol='HTTP',
Port=80,
VpcId='vpc-935058eb',
HealthCheckProtocol='HTTP',
HealthCheckPort='80',
HealthCheckPath='/var/www/html/index.html',
HealthCheckIntervalSeconds=10,
HealthCheckTimeoutSeconds=5,
HealthyThresholdCount=3,
UnhealthyThresholdCount=3,
Matcher={
'HttpCode': '200'
},
TargetType='instance'
)
def register_target(target_group_arn, instance_id, region_name):
return aws('elbv2', region_name=region_name).register_targets(
TargetGroupArn=target_group_arn,
Targets=[{'Id': instance_id}]
)
def create_elb_listener(self,target_name,elb_name):
target_grp_arn=self.desc_elb_target_grps([target_name])
elb_arn = self.desc_elb([elb_name])
listener = self.elbv2_client.create_listener(
LoadBalancerArn=elb_arn,
Protocol='HTTP',
Port=80,
DefaultActions=[
{
'Type': 'forward',
'TargetGroupArn': target_grp_arn
},
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment