Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
11
Help us understand the problem. What is going on with this article?
@rmanzoku

使っていないセキュリティグループを洗い出す

More than 3 years have passed since last update.

コンソールからセキュリティの設定をしていると、作った覚えのないVPCセキュリティグループが氾濫することがあります。
とりあえず以下のようなコマンドで洗い出し、整理しましょう。

# セキュリティグループの一覧を取得
$ aws ec2 describe-security-groups --output json | jq -r '.SecurityGroups[].GroupId' | sort > sglist
# インスタンスにアタッチされているセキュリティグループを取得
$ aws ec2 describe-instances --output json | jq -r '.Reservations[].Instances[].SecurityGroups[].GroupId' > tmp
$ aws elb describe-load-balancers --output json | jq -r '.LoadBalancerDescriptions[].SecurityGroups[]' >> tmp
$ aws elbv2  describe-load-balancers --output json | jq -r '.LoadBalancers[].SecurityGroups[]' >> tmp
$ aws rds describe-db-instances --output json | jq -r '.DBInstances[].VpcSecurityGroups[].VpcSecurityGroupId' >> tmp
$ aws elasticache describe-cache-clusters --output json | jq -r '.CacheClusters[].SecurityGroups[].SecurityGroupId' >> tmp
$ cat tmp | sort | uniq > inuse
# 差分を確認
$ diff sglist inuse
11
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
rmanzoku

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
11
Help us understand the problem. What is going on with this article?