Пример #1
0
 public void createLaunchConfiguration(
     String imageId, String name, String keyName, String securityGroup) {
   log.info("Creating new launch config ");
   CreateLaunchConfigurationRequest launchConfigurationRequest =
       new CreateLaunchConfigurationRequest();
   launchConfigurationRequest.setImageId(imageId);
   launchConfigurationRequest.setLaunchConfigurationName(name);
   launchConfigurationRequest.setKeyName(keyName);
   launchConfigurationRequest.setInstanceType("t1.micro");
   launchConfigurationRequest.setSecurityGroups(Arrays.asList(securityGroup));
   scalingClient.createLaunchConfiguration(launchConfigurationRequest);
   log.info("Launch Configuration created ");
 }
Пример #2
0
  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");
  }