private CreateLaunchConfigurationRequest createLaunchConfigurationRequest(Formation formation) { Machine machine = formation.getMachine(); Scaling scaling = machine.getScaling(); Properties generalProperties = getMetaInformationProperties(formation); CloudInitScript initScript = getParallelCloudInitScript(machine, generalProperties); IamInstanceProfileSpecification profil = this.ec2Client.getIamInstanceProfileSpecification(getUserProperty(REPO_PROFILE)); return new CreateLaunchConfigurationRequest().withLaunchConfigurationName(scaling.getName()) .withInstanceType(machine.getInstanceType()).withImageId(machine.getImageId()) .withUserData(initScript.renderAsBase64()).withSecurityGroups(machine.getSecurityGroup()) .withIamInstanceProfile(profil.getName()) // the name NOT the ARN! .withKeyName(getUserProperty(EC2_INSTANCE_KEY)) .withInstanceMonitoring(new InstanceMonitoring().withEnabled(false)); }
public LaunchConfiguration createLaunchConfig(CreateLaunchConfigurationRequest request) throws Exception { return new Runner<LaunchConfiguration>() .retryInterval(Duration.ofSeconds(5)) .maxAttempts(3) .retryOn(e -> e instanceof AmazonServiceException) .run(() -> { logger.info("create launch config, request={}", request); autoScaling.createLaunchConfiguration(request); return describeLaunchConfig(request.getLaunchConfigurationName()); }); }
public void createLaunchConfig(ASGroup asGroup) throws Exception { String launchConfigName = env.name + "-" + asGroup.id + "-" + Randoms.alphaNumeric(6); LaunchConfig launchConfig = asGroup.launchConfig; CreateLaunchConfigurationRequest request = new CreateLaunchConfigurationRequest() .withLaunchConfigurationName(launchConfigName) .withKeyName(launchConfig.keyPair.remoteKeyPair.getKeyName()) .withInstanceType(launchConfig.instanceType) .withImageId(launchConfig.ami.imageId()) .withSecurityGroups(launchConfig.securityGroup.remoteSecurityGroup.getGroupId()) .withUserData(Encodings.base64(userData(asGroup))); if (EBS.enableEBSOptimized(launchConfig.instanceType)) { // this is not necessary since m4/c4 are EBS optimized enable by default, but there is bug in AWS console, we need to set this in order to display correct value request.withEbsOptimized(true); } if (asGroup.subnet.type == SubnetType.PUBLIC) { request.withAssociatePublicIpAddress(true); } if (launchConfig.instanceProfile != null) request.withIamInstanceProfile(launchConfig.instanceProfile.remoteInstanceProfile.getInstanceProfileName()); if (launchConfig.ebs.rootVolumeSize != null) { request.getBlockDeviceMappings().add(new BlockDeviceMapping() .withDeviceName("/dev/sda1") .withEbs(new Ebs().withVolumeSize(launchConfig.ebs.rootVolumeSize).withVolumeType(launchConfig.ebs.type))); } launchConfig.remoteLaunchConfig = AWS.as.createLaunchConfig(request); }
/*** * Create a launch configuration that can be later used to create {@link AmazonAutoScaling} groups * * @param launchConfigName Desired launch config name * @param imageId AMI image id to use * @param instanceType EC2 instance type to use * @param keyName Key name * @param securityGroups Security groups to apply * @param kernelId Optional kernel id * @param ramdiskId Optional ram disk id * @param blockDeviceMapping Optional EBS device mapping * @param iamInstanceProfile Optional IAM instance profile * @param instanceMonitoring Optional instance monitoring * @param userData User data (eg. shell script to execute at instance boot under this launch config) */ public void createLaunchConfig(String launchConfigName, String imageId, String instanceType, String keyName, String securityGroups, Optional<String> kernelId, Optional<String> ramdiskId, Optional<BlockDeviceMapping> blockDeviceMapping, Optional<String> iamInstanceProfile, Optional<InstanceMonitoring> instanceMonitoring, String userData) { final AmazonAutoScaling autoScaling = getAmazonAutoScalingClient(); CreateLaunchConfigurationRequest createLaunchConfigurationRequest = new CreateLaunchConfigurationRequest() .withLaunchConfigurationName(launchConfigName) .withImageId(imageId) .withInstanceType(instanceType) .withSecurityGroups(SPLITTER.splitToList(securityGroups)) .withKeyName(keyName) .withUserData(userData); if (kernelId.isPresent()) { createLaunchConfigurationRequest = createLaunchConfigurationRequest .withKernelId(kernelId.get()); } if (ramdiskId.isPresent()) { createLaunchConfigurationRequest = createLaunchConfigurationRequest .withRamdiskId(ramdiskId.get()); } if (blockDeviceMapping.isPresent()) { createLaunchConfigurationRequest = createLaunchConfigurationRequest .withBlockDeviceMappings(blockDeviceMapping.get()); } if (iamInstanceProfile.isPresent()) { createLaunchConfigurationRequest = createLaunchConfigurationRequest .withIamInstanceProfile(iamInstanceProfile.get()); } if (instanceMonitoring.isPresent()) { createLaunchConfigurationRequest = createLaunchConfigurationRequest .withInstanceMonitoring(instanceMonitoring.get()); } autoScaling.createLaunchConfiguration(createLaunchConfigurationRequest); LOGGER.info("Created Launch Configuration: " + launchConfigName); }