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

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

Introduction

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

Prototype

CreateRouteRequest

Source Link

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 ww. j av a  2 s .c om*/
 * @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;
        }
    }
}

From source file:com.vmware.photon.controller.model.adapters.awsadapter.AWSNetworkService.java

License:Open Source License

public void createInternetRoute(String gatewayID, String routeTableID, String subnet,
        AmazonEC2AsyncClient client) {//from   w ww.j  a v a 2  s .c o  m
    CreateRouteRequest req = new CreateRouteRequest().withGatewayId(gatewayID).withRouteTableId(routeTableID)
            .withDestinationCidrBlock(subnet);
    client.createRoute(req);
}