Example usage for com.amazonaws.services.ec2.model RunInstancesRequest withIamInstanceProfile

List of usage examples for com.amazonaws.services.ec2.model RunInstancesRequest withIamInstanceProfile

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model RunInstancesRequest withIamInstanceProfile.

Prototype


public RunInstancesRequest withIamInstanceProfile(IamInstanceProfileSpecification iamInstanceProfile) 

Source Link

Document

The IAM instance profile.

Usage

From source file:com.cloudera.director.aws.ec2.EC2Provider.java

License:Apache License

/**
 * Builds a {@code RunInstancesRequest} starting from a template and a set of
 * virtual IDs./*from  w  ww.  j  a v  a  2s  .c o m*/
 *
 * @param template           the instance template
 * @param virtualInstanceIds the virtual instance IDs
 */
@SuppressWarnings("ConstantConditions")
private RunInstancesRequest newRunInstancesRequest(EC2InstanceTemplate template,
        Collection<String> virtualInstanceIds, int minCount) {

    LOG.info(">> Building instance requests");

    int groupSize = virtualInstanceIds.size();
    String image = template.getImage();
    String type = template.getType();

    InstanceNetworkInterfaceSpecification network = getInstanceNetworkInterfaceSpecification(template);

    List<BlockDeviceMapping> deviceMappings = getBlockDeviceMappings(template);

    LOG.info(">> Instance request type: {}, image: {}, group size: {}", type, image, groupSize);

    RunInstancesRequest request = new RunInstancesRequest().withImageId(image).withInstanceType(type)
            .withMaxCount(groupSize).withMinCount(minCount)
            .withClientToken(
                    getHashOfVirtualInstanceIdsForClientToken(virtualInstanceIds, Optional.<Long>absent()))
            .withNetworkInterfaces(network).withBlockDeviceMappings(deviceMappings);

    if (template.getIamProfileName().isPresent()) {
        request.withIamInstanceProfile(
                new IamInstanceProfileSpecification().withName(template.getIamProfileName().get()));
    }

    if (template.getKeyName().isPresent()) {
        request.withKeyName(template.getKeyName().get());
    }

    Placement placement = null;
    if (template.getAvailabilityZone().isPresent()) {
        placement = new Placement().withAvailabilityZone(template.getAvailabilityZone().get());
    }
    if (template.getPlacementGroup().isPresent()) {
        placement = (placement == null) ? new Placement().withGroupName(template.getPlacementGroup().get())
                : placement.withGroupName(template.getPlacementGroup().get());
    }
    placement = (placement == null) ? new Placement().withTenancy(template.getTenancy())
            : placement.withTenancy(template.getTenancy());

    request.withPlacement(placement);

    return request;
}