Builder<String, String> builder = ImmutableMap.builder();
builder.put("LaunchSpecification.ImageId", checkNotNull(launchSpec.getImageId(), "imageId"));
if (launchSpec.getAvailabilityZone() != null)
builder.put("LaunchSpecification.Placement.AvailabilityZone", launchSpec.getAvailabilityZone());
AWSRunInstancesOptions options = new AWSRunInstancesOptions();
if (launchSpec.getBlockDeviceMappings().size() > 0)
options.withBlockDeviceMappings(launchSpec.getBlockDeviceMappings());
if (launchSpec.getSecurityGroupNames().size() > 0)
options.withSecurityGroups(launchSpec.getSecurityGroupNames());
if (launchSpec.getSecurityGroupIds().size() > 0)
options.withSecurityGroupIds(launchSpec.getSecurityGroupIds());
options.asType(checkNotNull(launchSpec.getInstanceType(), "instanceType"));
if (launchSpec.getSubnetId() != null){
if (Boolean.TRUE.equals(launchSpec.isPublicIpAddressAssociated())) {
options.associatePublicIpAddressAndSubnetId(launchSpec.getSubnetId());
if (launchSpec.getSecurityGroupIds().size() > 0){
options.withSecurityGroupIdsForNetworkInterface(launchSpec.getSecurityGroupIds());
}
}
else{
options.withSubnetId(launchSpec.getSubnetId());
}
}
if (launchSpec.getKernelId() != null)
options.withKernelId(launchSpec.getKernelId());
if (launchSpec.getKeyName() != null)
options.withKeyName(launchSpec.getKeyName());
if (launchSpec.getRamdiskId() != null)
options.withRamdisk(launchSpec.getRamdiskId());
if (Boolean.TRUE.equals(launchSpec.isMonitoringEnabled()))
options.enableMonitoring();
if (launchSpec.getUserData() != null)
options.withUserData(launchSpec.getUserData());
if (launchSpec.getIAMInstanceProfile().isPresent()) {
IAMInstanceProfileRequest profile = launchSpec.getIAMInstanceProfile().get();
if (profile.getArn().isPresent())
options.withIAMInstanceProfileArn(profile.getArn().get());
if (profile.getName().isPresent())
options.withIAMInstanceProfileName(profile.getName().get());
}
for (Entry<String, String> entry : options.buildFormParameters().entries()) {
builder.put("LaunchSpecification." + entry.getKey(), entry.getValue());
}
return builder.build();
}