Example usage for com.amazonaws.services.ec2 AmazonEC2 detachInternetGateway

List of usage examples for com.amazonaws.services.ec2 AmazonEC2 detachInternetGateway

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2 AmazonEC2 detachInternetGateway.

Prototype

DetachInternetGatewayResult detachInternetGateway(DetachInternetGatewayRequest detachInternetGatewayRequest);

Source Link

Document

Detaches an internet gateway from a VPC, disabling connectivity between the internet and the VPC.

Usage

From source file:com.urbancode.terraform.tasks.aws.helpers.AWSHelper.java

License:Apache License

/**
 * Detaches the given internet gateway from the given vpc
 *
 * @param gatewayId/*from  w  ww.  j  a  v  a2  s. co m*/
 * @param vpcId
 * @param ec2Client
 */
public void detachGateway(String gatewayId, String vpcId, AmazonEC2 ec2Client) {
    try {
        DetachInternetGatewayRequest request = new DetachInternetGatewayRequest()
                .withInternetGatewayId(gatewayId).withVpcId(vpcId);
        ec2Client.detachInternetGateway(request);
    } catch (AmazonServiceException e) {
        log.error("Failed to detach Internet Gateway", e);
        if (!"InvalidInternetGatewayID.NotFound".equalsIgnoreCase(e.getErrorCode())) {
            // only swallow the exception if the gateway id was not found
            throw e;
        }
    }
}