use of software.amazon.awssdk.services.ec2.model.CreateTagsRequest in project aws-doc-sdk-examples by awsdocs.
the class CreateInstance method createEC2Instance.
// snippet-start:[ec2.java2.create_instance.main]
public static String createEC2Instance(Ec2Client ec2, String name, String amiId) {
RunInstancesRequest runRequest = RunInstancesRequest.builder().imageId(amiId).instanceType(InstanceType.T1_MICRO).maxCount(1).minCount(1).build();
RunInstancesResponse response = ec2.runInstances(runRequest);
String instanceId = response.instances().get(0).instanceId();
Tag tag = Tag.builder().key("Name").value(name).build();
CreateTagsRequest tagRequest = CreateTagsRequest.builder().resources(instanceId).tags(tag).build();
try {
ec2.createTags(tagRequest);
System.out.printf("Successfully started EC2 Instance %s based on AMI %s", instanceId, amiId);
return instanceId;
} catch (Ec2Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.ec2.model.CreateTagsRequest in project GNS by MobilityFirst.
the class AWSEC2 method addInstanceTag.
/**
* Adds the key and value as a 'tag' for the instance.
*
* @param ec2
* @param createdInstanceId
* @param key
* @param value
*/
public static void addInstanceTag(AmazonEC2 ec2, String createdInstanceId, String key, String value) {
List<String> resources = new LinkedList<>();
resources.add(createdInstanceId);
List<Tag> tags = new LinkedList<>();
Tag nameTag = new Tag(key, value);
tags.add(nameTag);
CreateTagsRequest ctr = new CreateTagsRequest(resources, tags);
ec2.createTags(ctr);
}
use of software.amazon.awssdk.services.ec2.model.CreateTagsRequest in project photon-model by vmware.
the class AWSUtils method tagResources.
/**
* Synchronous Tagging of one or many AWS resources with the provided tags.
*/
public static void tagResources(AmazonEC2AsyncClient client, Collection<Tag> tags, String... resourceIds) {
if (isAwsClientMock()) {
return;
}
CreateTagsRequest req = new CreateTagsRequest().withResources(resourceIds).withTags(tags);
client.createTags(req);
}
use of software.amazon.awssdk.services.ec2.model.CreateTagsRequest in project cloudbreak by hortonworks.
the class AwsMetadataCollector method addTag.
private void addTag(AmazonEC2 amazonEC2Client, CloudInstance cloudInstance, Instance instance) {
String tagName = awsClient.getCbName(cloudInstance.getTemplate().getGroupName(), cloudInstance.getTemplate().getPrivateId());
Tag t = new Tag();
t.setKey(TAG_NAME);
t.setValue(tagName);
CreateTagsRequest ctr = new CreateTagsRequest();
ctr.setTags(Collections.singletonList(t));
ctr.withResources(instance.getInstanceId());
amazonEC2Client.createTags(ctr);
}
Aggregations