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

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

Introduction

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

Prototype

AssociateRouteTableResult associateRouteTable(AssociateRouteTableRequest associateRouteTableRequest);

Source Link

Document

Associates a subnet with a route table.

Usage

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

License:Apache License

/**
 *
 * @param routeTableId/*  w w  w.  j a  v a 2  s  . c  om*/
 * @param subnetId
 * @param ec2Client
 * @return
 */
public String associateRouteTableWithSubnet(String routeTableId, String subnetId, AmazonEC2 ec2Client) {
    String assId = null;
    try {
        AssociateRouteTableRequest request = new AssociateRouteTableRequest().withRouteTableId(routeTableId)
                .withSubnetId(subnetId);
        AssociateRouteTableResult result = ec2Client.associateRouteTable(request);

        if (result != null) {
            assId = result.getAssociationId();
        }
    } catch (AmazonServiceException e) {
        log.error("Failed to associate Route Table with Subnet", e);
        if (!"InvalidRouteTableID.NotFound".equalsIgnoreCase(e.getErrorCode())) {
            throw e;
        }
    }

    return assId;
}