Java Code Examples for com.amazonaws.services.ec2.AmazonEC2#releaseAddress()

The following examples show how to use com.amazonaws.services.ec2.AmazonEC2#releaseAddress() . 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: UnusedElasticIPAutofix.java    From pacbot with Apache License 2.0 6 votes vote down vote up
@Override
public FixResult executeFix(Map<String, String> issue, Map<String, Object> clientMap,
		Map<String, String> ruleParams) {

	try {
		AmazonEC2 amazonEC2 = (AmazonEC2) clientMap.get(PacmanSdkConstants.CLIENT);

		ReleaseAddressRequest request = new ReleaseAddressRequest().withAllocationId(issue.get(PacmanSdkConstants.ALLOCATION_ID));
		amazonEC2.releaseAddress(request);
		if (LOGGER.isDebugEnabled())
			LOGGER.debug(String.format(ELASTIC_IP_ALLOCATION_ID_RELEASED, issue.get(PacmanSdkConstants.RESOURCE_ID),
					issue.get(PacmanSdkConstants.ALLOCATION_ID)));
		return new FixResult(PacmanSdkConstants.STATUS_SUCCESS_CODE,
				String.format(ELASTIC_IP_ALLOCATION_ID_RELEASED, issue.get(PacmanSdkConstants.RESOURCE_ID),
						issue.get(PacmanSdkConstants.ALLOCATION_ID)));
	} catch (Exception e) {
		LOGGER.error(String.format(ELASTIC_IP_ALLOCATION_ID_RELEASE_FAILED,
				issue.get(PacmanSdkConstants.RESOURCE_ID), issue.get(PacmanSdkConstants.ALLOCATION_ID)), e.getMessage());
		return new FixResult(PacmanSdkConstants.STATUS_FAILURE_CODE,
				String.format(ELASTIC_IP_ALLOCATION_ID_RELEASE_FAILED, issue.get(PacmanSdkConstants.RESOURCE_ID),
						issue.get(PacmanSdkConstants.ALLOCATION_ID), e.getMessage()));
	}

}
 
Example 2
Source File: ReleaseAddress.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args)
{
    final String USAGE =
        "To run this example, supply an allocation ID.\n" +
        "Ex: ReleaseAddress <allocation_id>\n";

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

    String alloc_id = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    ReleaseAddressRequest request = new ReleaseAddressRequest()
        .withAllocationId(alloc_id);

    ReleaseAddressResult response = ec2.releaseAddress(request);

    System.out.printf(
        "Successfully released elastic IP address %s", alloc_id);
}