Example usage for com.amazonaws.services.ec2.model CreateSecurityGroupRequest withVpcId

List of usage examples for com.amazonaws.services.ec2.model CreateSecurityGroupRequest withVpcId

Introduction

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

Prototype


public CreateSecurityGroupRequest withVpcId(String vpcId) 

Source Link

Document

[EC2-VPC] The ID of the VPC.

Usage

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

License:Apache License

/**
 *
 * @param groupName//from w w w  .  j  a  v  a2s  .  c  o  m
 * @param vpcId leave null if you do not want your security group to be associated with a VPC
 * @param descr
 * @param ec2Client
 * @return
 */
public String createSecurityGroup(String groupName, String vpcId, String descr, AmazonEC2 ec2Client) {
    String groupId = null;
    try {
        CreateSecurityGroupRequest request = new CreateSecurityGroupRequest().withGroupName(groupName)
                .withDescription(descr);

        if (vpcId != null) {
            request = request.withVpcId(vpcId);
        }

        CreateSecurityGroupResult result = ec2Client.createSecurityGroup(request);
        groupId = result.getGroupId();

    } catch (AmazonServiceException e) {
        log.error("Failed to create Security Group", e);
        if (!"InvalidVpcID.NotFound".equalsIgnoreCase(e.getErrorCode())) {
            throw e;
        }
    }

    return groupId;
}

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

License:Open Source License

public static String createSecurityGroup(AmazonEC2AsyncClient client, String name, String description,
        String vpcId) {//from  w w  w .j a v a  2 s  . com

    CreateSecurityGroupRequest req = new CreateSecurityGroupRequest().withDescription(description)
            .withGroupName(name);

    // set vpc for the security group if provided
    if (vpcId != null) {
        req = req.withVpcId(vpcId);
    }

    CreateSecurityGroupResult result = client.createSecurityGroup(req);

    return result.getGroupId();
}