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

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

Introduction

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

Prototype

AssociateRouteTableRequest

Source Link

Usage

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

License:Apache License

/**
 *
 * @param routeTableId//  w  w  w  .j ava  2s  .  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;
}