/** * Describe a set of specific launch configurations. * * @param names the launch configuration names * @return the launch configurations */ public List<LaunchConfiguration> describeLaunchConfigurations(String... names) { if (names == null || names.length == 0) { LOGGER.info("Getting all launch configurations."); } else { LOGGER.info(String.format("Getting launch configurations for %d names.", names.length)); } List<LaunchConfiguration> lcs = new LinkedList<LaunchConfiguration>(); AmazonAutoScalingClient asgClient = asgClient(); DescribeLaunchConfigurationsRequest request = new DescribeLaunchConfigurationsRequest().withLaunchConfigurationNames(names); DescribeLaunchConfigurationsResult result = asgClient.describeLaunchConfigurations(request); lcs.addAll(result.getLaunchConfigurations()); while (result.getNextToken() != null) { request.setNextToken(result.getNextToken()); result = asgClient.describeLaunchConfigurations(request); lcs.addAll(result.getLaunchConfigurations()); } LOGGER.info(String.format("Got %d launch configurations.", lcs.size())); return lcs; }
private static void setupAutoScale( AmazonAutoScalingClient autoScale, AmazonCloudWatchClient cloudWatch, String keyName, String zone, String securityGroup, String imageId) { List<LaunchConfiguration> launchList = autoScale.describeLaunchConfigurations().getLaunchConfigurations(); for (LaunchConfiguration ll : launchList) if (ll.getLaunchConfigurationName().equalsIgnoreCase("On DemandAWS")) { System.out.println("Using Launch Configuration " + ll.getLaunchConfigurationName()); return; } CreateLaunchConfigurationRequest launchConfig = new CreateLaunchConfigurationRequest(); launchConfig.setImageId(imageId); launchConfig.setKeyName(keyName); launchConfig.setInstanceType("t1.micro"); List<String> securityGroups = new ArrayList<String>(); securityGroups.add(securityGroup); launchConfig.setSecurityGroups(securityGroups); launchConfig.setLaunchConfigurationName("On DemandAWS"); autoScale.createLaunchConfiguration(launchConfig); CreateAutoScalingGroupRequest autoReq = new CreateAutoScalingGroupRequest(); autoReq.setLaunchConfigurationName("On DemandAWS"); List<String> availabilityZones = new ArrayList<String>(); availabilityZones.add(zone); autoReq.setAvailabilityZones(availabilityZones); autoReq.setMinSize(1); autoReq.setMaxSize(1); autoReq.setAutoScalingGroupName("OnDemand ASGroup"); autoScale.createAutoScalingGroup(autoReq); System.out.println("Using Launch Configuration On DemandAWS created"); }