Skip to content

Instantly share code, notes, and snippets.

@lancehunt
Forked from asinghal/prune_aws_security_groups.md
Last active October 31, 2017 17:27

Revisions

  1. lancehunt revised this gist Oct 31, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions prune_aws_security_groups.md
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,6 @@
    ```
    aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq > used.txt
    aws ec2 describe-security-groups --query 'SecurityGroups[*].IpPermissions[*].UserIdGroupPairs[*].GroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws elbv2 describe-load-balancers --query 'LoadBalancers[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws autoscaling describe-launch-configurations --query 'LaunchConfigurations[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    @@ -16,6 +14,8 @@ aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[
    aws rds describe-db-instances --query 'DBInstances[*].VpcSecurityGroups[*].VpcSecurityGroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws ec2 describe-security-groups --query 'SecurityGroups[*].IpPermissions[*].UserIdGroupPairs[*].GroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws elasticache describe-cache-clusters --query "CacheClusters[].SecurityGroups[].SecurityGroupId" --output text | tr '\t' '\n' | sort | uniq >> used.txt
    comm -23 <(aws ec2 describe-security-groups --query 'SecurityGroups[*].[GroupName,GroupId]' --output text | grep -v "default" | cut -f2| sort) <(cat used.txt | sort | uniq )
  2. lancehunt revised this gist Oct 31, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions prune_aws_security_groups.md
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,8 @@
    ```
    aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq > used.txt
    aws ec2 describe-security-groups --query 'SecurityGroups[*].IpPermissions[*].UserIdGroupPairs[*].GroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws elbv2 describe-load-balancers --query 'LoadBalancers[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws autoscaling describe-launch-configurations --query 'LaunchConfigurations[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq >> used.txt
  3. lancehunt revised this gist Oct 27, 2017. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions prune_aws_security_groups.md
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,13 @@ aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].SecurityGro
    aws elbv2 describe-load-balancers --query 'LoadBalancers[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws autoscaling describe-launch-configurations --query 'LaunchConfigurations[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws rds describe-db-instances --query 'DBInstances[*].VpcSecurityGroups[*].VpcSecurityGroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws elasticache describe-cache-clusters --query "CacheClusters[].SecurityGroups[].SecurityGroupId" --output text | tr '\t' '\n' | sort | uniq >> used.txt
    comm -23 <(aws ec2 describe-security-groups --query 'SecurityGroups[*].[GroupName,GroupId]' --output text | grep -v "default" | cut -f2| sort) <(cat used.txt | sort | uniq )
    ```
  4. lancehunt revised this gist Oct 27, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions prune_aws_security_groups.md
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,8 @@
    ```
    aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq > used.txt
    aws elbv2 describe-load-balancers --query 'LoadBalancers[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    aws rds describe-db-instances --query 'DBInstances[*].VpcSecurityGroups[*].VpcSecurityGroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt
  5. @asinghal asinghal revised this gist Jul 4, 2016. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions prune_aws_security_groups.md
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,12 @@
    *Note*: Always check manually before deleting security groups. There are various places the groups may be used, and the scripts output may not always be conclusive


    ```aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq > used.txt```
    ```
    aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq > used.txt
    ```aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt```
    aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    ```aws rds describe-db-instances --query 'DBInstances[*].VpcSecurityGroups[*].VpcSecurityGroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt```
    aws rds describe-db-instances --query 'DBInstances[*].VpcSecurityGroups[*].VpcSecurityGroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt

    ```comm -23 <(aws ec2 describe-security-groups --query 'SecurityGroups[*].[GroupName,GroupId]' --output text | grep -v "default" | cut -f2| sort) <(cat used.txt | sort | uniq )```
    comm -23 <(aws ec2 describe-security-groups --query 'SecurityGroups[*].[GroupName,GroupId]' --output text | grep -v "default" | cut -f2| sort) <(cat used.txt | sort | uniq )
    ```
  6. @asinghal asinghal renamed this gist Jul 4, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. @asinghal asinghal revised this gist Jul 4, 2016. 1 changed file with 9 additions and 4 deletions.
    13 changes: 9 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,13 @@
    aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq > used.txt
    ## Commands to get security groups in use and echo names of groups that can not be found in use

    aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    *Note*: Always check manually before deleting security groups. There are various places the groups may be used, and the scripts output may not always be conclusive

    aws rds describe-db-instances --query 'DBInstances[*].VpcSecurityGroups[*].VpcSecurityGroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt

    ```aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq > used.txt```

    comm -23 <(aws ec2 describe-security-groups --query 'SecurityGroups[*].[GroupName,GroupId]' --output text | grep -v "default" | cut -f2| sort) <(cat used.txt | sort | uniq )
    ```aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt```

    ```aws rds describe-db-instances --query 'DBInstances[*].VpcSecurityGroups[*].VpcSecurityGroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt```


    ```comm -23 <(aws ec2 describe-security-groups --query 'SecurityGroups[*].[GroupName,GroupId]' --output text | grep -v "default" | cut -f2| sort) <(cat used.txt | sort | uniq )```
  8. @asinghal asinghal revised this gist Jul 4, 2016. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    ```
    aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq > used.txt

    aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt
    @@ -7,4 +6,3 @@ aws rds describe-db-instances --query 'DBInstances[*].VpcSecurityGroups[*].VpcS


    comm -23 <(aws ec2 describe-security-groups --query 'SecurityGroups[*].[GroupName,GroupId]' --output text | grep -v "default" | cut -f2| sort) <(cat used.txt | sort | uniq )
    ```
  9. @asinghal asinghal created this gist Jul 4, 2016.
    10 changes: 10 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    ```
    aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].SecurityGroups' --output text | tr '\t' '\n' | sort | uniq > used.txt

    aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt

    aws rds describe-db-instances --query 'DBInstances[*].VpcSecurityGroups[*].VpcSecurityGroupId' --output text | tr '\t' '\n' | sort | uniq >> used.txt


    comm -23 <(aws ec2 describe-security-groups --query 'SecurityGroups[*].[GroupName,GroupId]' --output text | grep -v "default" | cut -f2| sort) <(cat used.txt | sort | uniq )
    ```