Example usage for com.amazonaws.services.ec2.model CreateRouteRequest withGatewayId

List of usage examples for com.amazonaws.services.ec2.model CreateRouteRequest withGatewayId

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model CreateRouteRequest withGatewayId.

Prototype


public CreateRouteRequest withGatewayId(String gatewayId) 

Source Link

Document

The ID of an internet gateway or virtual private gateway attached to your VPC.

Usage

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

License:Apache License

/**
 * Creates a route with given info. Attach Id can be either an instance (as a NAT) or an
 *  gateway. I f the attachId is an instance (starts with "i-") then the src/destination check
 *  on the instance will be disabled to allow it to act as a NAT.
 *
 * @param routeTableId the id of the route table to add this route to
 * @param destCidr//from w w  w .j a  v  a2  s.c o m
 * @param attachId of the instance or internet gateway
 * @param ec2Client AmazonEC2 connection
 */
public void createRoute(String routeTableId, String destCidr, String attachId, AmazonEC2 ec2Client) {
    try {
        CreateRouteRequest request = new CreateRouteRequest().withDestinationCidrBlock(destCidr)
                .withRouteTableId(routeTableId);
        if (attachId.startsWith("i-")) {
            request = request.withInstanceId(attachId);
            // disable src/dest check to allow instance to run as NAT
            setSrcDestCheck(false, attachId, ec2Client);
        } else if (attachId.startsWith("igw-")) {
            request = request.withGatewayId(attachId);
        }
        ec2Client.createRoute(request);
    } catch (AmazonServiceException e) {
        log.error("Failed to create Route in Route Table " + routeTableId, e);
        if (!"InvalidRouteTableID.NotFound".equalsIgnoreCase(e.getErrorCode())) {
            // we're only going to swallow the expcetion if the gateway id was not found
            throw e;
        }
    }
}