Ejemplo n.º 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 ");
 }
  public static void setUpLaunchConfiguration() {

    scaleClient = new AmazonAutoScalingClient(awsCredentials());

    CreateLaunchConfigurationRequest launchConfiguration = new CreateLaunchConfigurationRequest();
    launchConfiguration.setImageId("ami-349fbb5e");
    launchConfiguration.setInstanceType("m3.medium");
    launchConfiguration.setLaunchConfigurationName("ProjectTwoLaunchConfiguration");

    ArrayList<String> securityGroups = new ArrayList<String>();
    securityGroups.add("SecurityGroupForELBAndAutoscale");
    launchConfiguration.setSecurityGroups(securityGroups);

    launchConfiguration.setSpotPrice("0.03");

    scaleClient.createLaunchConfiguration(launchConfiguration);

    System.out.println("Launch configuration successful..");
  }
Ejemplo n.º 3
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");
  }