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

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

Introduction

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

Prototype

RevokeSecurityGroupEgressResult revokeSecurityGroupEgress(
        RevokeSecurityGroupEgressRequest revokeSecurityGroupEgressRequest);

Source Link

Document

[VPC only] Removes the specified egress rules from a security group for EC2-VPC.

Usage

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

License:Apache License

/**
 *
 * @param groupId/*ww w  .ja v  a 2  s .  c  o m*/
 * @param protocol
 * @param startPort
 * @param endPort
 * @param cidr
 * @param inbound
 * @param ec2Client
 */
public void deleteRuleForSecurityGroup(String groupId, String protocol, int startPort, int endPort, String cidr,
        boolean inbound, AmazonEC2 ec2Client) {

    IpPermission perm = new IpPermission().withFromPort(startPort).withToPort(endPort).withIpProtocol(protocol)
            .withIpRanges(cidr);
    try {
        if (inbound) {
            RevokeSecurityGroupIngressRequest request = new RevokeSecurityGroupIngressRequest()
                    .withGroupId(groupId).withIpPermissions(perm);
            ec2Client.revokeSecurityGroupIngress(request);
        } else {
            RevokeSecurityGroupEgressRequest request = new RevokeSecurityGroupEgressRequest()
                    .withGroupId(groupId).withIpPermissions(perm);
            ec2Client.revokeSecurityGroupEgress(request);
        }
    } catch (AmazonServiceException e) {
        log.error("Failed to delete Rule on Security Group " + groupId);
        if (!"InvalidGroup.NotFound".equals(e.getErrorCode())) {
            throw e;
        }
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2RevokeSecurityGroupEgressTask.java

License:Apache License

@TaskAction
public void revokeEgress() {
    // to enable conventionMappings feature
    String groupId = getGroupId();
    Object ipPermissions = getIpPermissions();

    if (groupId == null) {
        throw new GradleException("groupId is not specified");
    }//ww w  .  ja  va2  s.c  o  m
    if (ipPermissions == null) {
        throw new GradleException("ipPermissions is not specified");
    }

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    try {
        ec2.revokeSecurityGroupEgress(new RevokeSecurityGroupEgressRequest().withGroupId(groupId)
                .withIpPermissions(parse(ipPermissions)));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.NotFound")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}

From source file:org.xmlsh.aws.gradle.ec2.AmazonEC2RevokeSecurityGroupEgressTask.java

License:BSD License

@TaskAction
public void revokeEgress() {
    // to enable conventionMappings feature
    String groupId = getGroupId();
    Object ipPermissions = getIpPermissions();

    if (groupId == null)
        throw new GradleException("groupId is not specified");
    if (ipPermissions == null)
        throw new GradleException("ipPermissions is not specified");

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    try {/*  w w w.ja v  a  2 s. c  o m*/
        ec2.revokeSecurityGroupEgress(new RevokeSecurityGroupEgressRequest().withGroupId(groupId)
                .withIpPermissions(parse(ipPermissions)));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.NotFound")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}