def create_elastic_load_balancer(): elb_conn = get_elb_connection_obj() # setup availability zones to which this lb forwards requests ports = [(80, cfg['webapp_instance_port'], 'http'), (443, cfg['webapp_instance_port'], 'http')] subnets = get_vpc_subnets() elb_sg = get_security_group(cfg['webapp_elb_sg_name']) # create the load balancer. NB: zones must be None when associating elb to non-default vpc elb = elb_conn.create_load_balancer(name=cfg['elb_name'], zones=None, listeners=ports, subnets=subnets, security_groups=[elb_sg.id]) # Add the health check configuration to the ELB. hc = HealthCheck( interval=10, healthy_threshold=2, unhealthy_threshold=3, target='HTTP:' + str(cfg['webapp_instance_port']) + cfg['health_check_url'] ) elb.configure_health_check(hc) print 'elastic load balancer created: ', elb print 'elastic load balancer dns: ', elb.dns_name return elb
def create_cname_to_elb(cname, elb_name=None, app_domain=None): cname = formatDomain(cname) if not elb_name: print 'elastic load balancer name not passed to script. querying aws based on configuration file' elb_name = cfg['elb_name'] if not elb_name: raise Exception("ERROR! elastic load balancer name not specified on cmd line or in configuration file") elb_conn = get_elb_connection_obj() elb = elb_conn.get_all_load_balancers(load_balancer_names=[elb_name])[0] print 'elb: %s' % elb elb_dns_name = elb.dns_name if not app_domain: app_domain = formatDomain(cfg['app_domain_name']) print 'adding cname to domain: %s' % app_domain route53 = get_route53_connection_obj() hosted_zone = route53.get_zone(app_domain) print 'hosted zone discovered: %s' % hosted_zone print 'zone id: %s' % hosted_zone.id zone_id = hosted_zone.id changes = ResourceRecordSets(route53, zone_id) change = changes.add_change("CREATE", cname, "CNAME", ttl=60) change.add_value(elb_dns_name) # try: changes.commit() # except Exception, e: # logging.error(e) # elb_id = # if not elb_id: # raise Exception("ERROR! domain name not specified on cmd line or in configuration file") # ok we have a domain name. it must end with a period before setting it up as a hosted zone print 'creating route53 hosted zone from domain name %s' % cname