use of com.amazonaws.services.ec2.AmazonEC2 in project SimianArmy by Netflix.
the class AWSClient method createTagsForResources.
@Override
public void createTagsForResources(Map<String, String> keyValueMap, String... resourceIds) {
Validate.notNull(keyValueMap);
Validate.notEmpty(keyValueMap);
Validate.notNull(resourceIds);
Validate.notEmpty(resourceIds);
AmazonEC2 ec2Client = ec2Client();
List<Tag> tags = new ArrayList<Tag>();
for (Map.Entry<String, String> entry : keyValueMap.entrySet()) {
tags.add(new Tag(entry.getKey(), entry.getValue()));
}
CreateTagsRequest req = new CreateTagsRequest(Arrays.asList(resourceIds), tags);
ec2Client.createTags(req);
}
use of com.amazonaws.services.ec2.AmazonEC2 in project SimianArmy by Netflix.
the class AWSClient method describeSecurityGroups.
/**
* Describe a set of security groups.
*
* @param groupNames the names of the groups to find
* @return a list of matching groups
*/
public List<SecurityGroup> describeSecurityGroups(String... groupNames) {
AmazonEC2 ec2Client = ec2Client();
DescribeSecurityGroupsRequest request = new DescribeSecurityGroupsRequest();
if (groupNames == null || groupNames.length == 0) {
LOGGER.info(String.format("Getting all EC2 security groups in region %s.", region));
} else {
LOGGER.info(String.format("Getting EC2 security groups for %d names in region %s.", groupNames.length, region));
request.withGroupNames(groupNames);
}
DescribeSecurityGroupsResult result;
try {
result = ec2Client.describeSecurityGroups(request);
} catch (AmazonServiceException e) {
if (e.getErrorCode().equals("InvalidGroup.NotFound")) {
LOGGER.info("Got InvalidGroup.NotFound error for security groups; returning empty list");
return Collections.emptyList();
}
throw e;
}
List<SecurityGroup> securityGroups = result.getSecurityGroups();
LOGGER.info(String.format("Got %d EC2 security groups in region %s.", securityGroups.size(), region));
return securityGroups;
}
use of com.amazonaws.services.ec2.AmazonEC2 in project SimianArmy by Netflix.
the class AWSClient method deleteSnapshot.
/**
* {@inheritDoc}
*/
@Override
public void deleteSnapshot(String snapshotId) {
Validate.notEmpty(snapshotId);
LOGGER.info(String.format("Deleting snapshot %s in region %s.", snapshotId, region));
AmazonEC2 ec2Client = ec2Client();
DeleteSnapshotRequest request = new DeleteSnapshotRequest().withSnapshotId(snapshotId);
ec2Client.deleteSnapshot(request);
}
use of com.amazonaws.services.ec2.AmazonEC2 in project aws-doc-sdk-examples by awsdocs.
the class AllocateAddress method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply an instance id\n" + "Ex: AllocateAddress <instance_id>\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String instance_id = args[0];
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
AllocateAddressRequest allocate_request = new AllocateAddressRequest().withDomain(DomainType.Vpc);
AllocateAddressResult allocate_response = ec2.allocateAddress(allocate_request);
String allocation_id = allocate_response.getAllocationId();
AssociateAddressRequest associate_request = new AssociateAddressRequest().withInstanceId(instance_id).withAllocationId(allocation_id);
AssociateAddressResult associate_response = ec2.associateAddress(associate_request);
System.out.printf("Successfully associated Elastic IP address %s " + "with instance %s", associate_response.getAssociationId(), instance_id);
}
use of com.amazonaws.services.ec2.AmazonEC2 in project aws-doc-sdk-examples by awsdocs.
the class DeleteKeyPair method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply a key pair name\n" + "Ex: DeleteKeyPair <key-pair-name>\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String key_name = args[0];
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
DeleteKeyPairRequest request = new DeleteKeyPairRequest().withKeyName(key_name);
DeleteKeyPairResult response = ec2.deleteKeyPair(request);
System.out.printf("Successfully deleted key pair named %s", key_name);
}
Aggregations