use of com.amazonaws.services.ec2.model.CreateTagsResult in project camel by apache.
the class EC2Producer method createTags.
private void createTags(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
Collection tags;
CreateTagsRequest request = new CreateTagsRequest();
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
request.withResources(instanceIds);
} else {
throw new IllegalArgumentException("Instances Ids must be specified");
}
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_TAGS))) {
tags = exchange.getIn().getHeader(EC2Constants.INSTANCES_TAGS, Collection.class);
request.withTags(tags);
} else {
throw new IllegalArgumentException("Tags must be specified");
}
CreateTagsResult result = new CreateTagsResult();
try {
result = ec2Client.createTags(request);
} catch (AmazonServiceException ase) {
LOG.trace("Create tags command returned the error code {}", ase.getErrorCode());
throw ase;
}
LOG.trace("Created tags [{}] on resources with Ids [{}] ", Arrays.toString(tags.toArray()), Arrays.toString(instanceIds.toArray()));
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
use of com.amazonaws.services.ec2.model.CreateTagsResult in project aws-doc-sdk-examples by awsdocs.
the class CreateInstance method main.
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 instance_id = run_response.getReservation().getReservationId();
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", instance_id, ami_id);
}
use of com.amazonaws.services.ec2.model.CreateTagsResult in project camel by apache.
the class EC2ProducerTest method ec2CreateTagsTest.
@Test
public void ec2CreateTagsTest() throws Exception {
mock.expectedMessageCount(1);
Exchange exchange = template.request("direct:createTags", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Collection l = new ArrayList();
l.add("test-1");
exchange.getIn().setHeader(EC2Constants.INSTANCES_IDS, l);
Collection tags = new ArrayList();
tags.add("pacific");
exchange.getIn().setHeader(EC2Constants.INSTANCES_TAGS, tags);
}
});
assertMockEndpointsSatisfied();
CreateTagsResult resultGet = (CreateTagsResult) exchange.getIn().getBody();
assertNotNull(resultGet);
}
Aggregations