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_ec2_from_ami():

    ec2 = get_ec2_connection_obj()

    # TODO!!!  need to check for existence of this key before blindly creating it...
    print 'creating ec2 ssh key pair with name %s' % cfg['ec2_ssh_key_name']
    key = ec2.create_key_pair(cfg['ec2_ssh_key_name'])
    key.save(cfg['ec2_ssh_key_local_path'])
    print 'just saved private key pem file to %s' % cfg['ec2_ssh_key_local_path']


    security_group = get_security_group(cfg['webapp_sg_name'])
    print 'utilizing security group: %s' % security_group
    print 'security group id: %s' % security_group.id
    subnet_list = get_vpc_subnets()

    ec2.run_instances(cfg['ec2_ami'],
                      key_name=cfg['ec2_ssh_key_name'],
                      security_group_ids=[security_group.id],
                      subnet_id=subnet_list[0],
                      instance_type=cfg['ec2_instance_type'])
예제 #3
0
def create_new_db_instance():
    # boto.set_stream_logger('boto')  # get obnoxious amount of debug info...

    print 'creating new mysql database RDS instance in region: ', cfg['aws_region']
    vpc_conn = aws_api_connections.get_vpc_connection_obj()
    rds_conn = aws_api_connections.get_rds_connection_obj()


    # get the existing list of subnets (typically 2)
    subnet_ids = get_vpc_subnets()

    # build the subnet group for this db instance, deleting any existing group first if it exists
    subnet_group_list = rds_conn.get_all_db_subnet_groups()
    for subnet_group in subnet_group_list:
        if subnet_group.name == cfg['db_subnet_name']:
            print "existing db subnet group will be deleted: " + subnet_group.name
            rds_conn.delete_db_subnet_group(cfg['db_subnet_name'])

    rds_conn.create_db_subnet_group(cfg['db_subnet_name'], 'group of private subnets in vpc', subnet_ids)


    # find the db security group we defined as part of the creating the vpc security groups
    db_security_group = get_db_security_group(vpc_conn)
    print "utilizing db security group: " + str(db_security_group)


    # with subnet group and db security group collected, issue the call to create the rds instance
    rds_conn.create_dbinstance(cfg['db_instance_id'], 10, 'db.t2.micro', cfg['db_user'], cfg['db_pwd'],
                               engine='MySQL',
                               port=3306,
                               db_name=cfg['db_name'],
                               availability_zone=None,
                               multi_az=False,
                               engine_version='5.6',
                               auto_minor_version_upgrade=False,
                               vpc_security_groups=[db_security_group.id],
                               db_subnet_group_name = cfg['db_subnet_name'])