com.amazonaws.services.ec2.model.CreateTagsResult Java Examples

The following examples show how to use com.amazonaws.services.ec2.model.CreateTagsResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsInstanceCloudConnector.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
/**
 * Internal method used for testing.
 */
Completable addTagToResource(String resourceId, String tag, String value) {
    List<String> resources = singletonList(resourceId);
    List<Tag> tags = singletonList(new Tag(tag, value));
    Observable<CreateTagsResult> observable = toObservable(new CreateTagsRequest(resources, tags), ec2Client::createTagsAsync);
    return observable.toCompletable();
}
 
Example #2
Source File: AwsInstanceCloudConnector.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private Completable doTag(List<String> instanceIds) {
    CreateTagsRequest request = new CreateTagsRequest(
            instanceIds,
            singletonList(new Tag(TAG_TERMINATE, Long.toString(System.currentTimeMillis())))
    );
    Observable<CreateTagsResult> observable = toObservable(request, ec2Client::createTagsAsync);
    return observable
            .doOnCompleted(() -> logger.info("Tagged instances: {}", instanceIds))
            .doOnError(e -> logger.warn("Failed to tag instances: {}, due to {}", instanceIds, e.getMessage()))
            .toCompletable();
}
 
Example #3
Source File: CreateInstance.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
{
    final String USAGE =
        "To run this example, supply an instance name and AMI image id\n" +
        "Ex: CreateInstance <instance-name> <ami-image-id>\n";

    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String name = args[0];
    String ami_id = args[1];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    RunInstancesRequest run_request = new RunInstancesRequest()
        .withImageId(ami_id)
        .withInstanceType(InstanceType.T1Micro)
        .withMaxCount(1)
        .withMinCount(1);

    RunInstancesResult run_response = ec2.runInstances(run_request);

    String reservation_id = run_response.getReservation().getInstances().get(0).getInstanceId();

    Tag tag = new Tag()
        .withKey("Name")
        .withValue(name);

    CreateTagsRequest tag_request = new CreateTagsRequest()
        .withTags(tag);

    CreateTagsResult tag_response = ec2.createTags(tag_request);

    System.out.printf(
        "Successfully started EC2 instance %s based on AMI %s",
        reservation_id, ami_id);
}
 
Example #4
Source File: BaseTest.java    From aws-mock with MIT License 5 votes vote down vote up
/**
 * Create Tags.
 *
 * @param availabilityZone the availability zone
 * @param iops the iops
 * @param size the size
 * @param snapshotId the snapshot id
 * @param volumeType the volume type
 * @return Volume
 */
protected final boolean createTags(final Collection<String> resources, final Collection<Tag> tags) {
    CreateTagsRequest req = new CreateTagsRequest();
    req.setResources(resources);
    req.setTags(tags);
    
    CreateTagsResult result = amazonEC2Client.createTags(req);
    if (result != null) {
        return true;
    }

    return false;
}