def launch_instance(connect): """ Launch EC2 instance. Thread-safe. connect - whether to perform connection test (up to 1 min usually) """ launch = aws_ec2.launch_instance(connect) l = threading.Lock() l.acquire() instances.append(launch[0].id) l.release()
def scale_up_with_new_instance(config): """Scale up with a new instance that first gets configured""" logger = logging.getLogger(__name__) logger.info("Upscaling with the new instance started.") # Launch instance logger.info("Launching an instance.") instance, _ = aws_ec2.launch_instance() # Start app logger.info("Performing deployment operations.") aws_ec2.app_predeployment(config) aws_ec2.deploy_app_at_instance(config, instance) aws_ec2.app_postdeployment(config) # Register instance at load balancer logger.info("Registering an instance at the load balancer") elb = aws_ec2_elb.get_load_balancer(config.get("region"), config.get("elb_name")) elb.register_instances([instance.id]) # Update config instances = config.get_list("instances") instances.append(instance.id) config.set_list("instances", instances)