LoginSignup
10
7

More than 5 years have passed since last update.

AWSセキュリティグループ設定をコマンド(aws-cli)でやる

Posted at

ブラウザでぽちぽちは面倒ってことで
aws cliで登録する。

セキュリティグループの作成

VpcId="vpc-12345678"
NewGroup="application.stg.sg"
aws ec2 create-security-group --group-name ${NewGroup} --description "${NewGroup}" --vpc-id ${VpcId} --description "${NewGroup}" > create-security-group

環境変数に設定

まぁ、いろいろ便利なので

GroupID=`cat create-security-group | jq -r .GroupId`

確認

# 人間が見やすいフォーマット
aws ec2 describe-security-groups --group-id ${GroupID} --output table
# json
aws ec2 describe-security-groups --group-id ${GroupID} --output json

追加

aws ec2 authorize-security-group-ingress --group-id ${GroupID} --protocol tcp --port 8081-8082 --cidr 10.0.0.1/32

Port 8081~8082で10.0.0.1/32からのアクセスをallowする

削除

aws ec2 revoke-security-group-ingress --group-id ${GroupID} --ip-permissions '[{"IpProtocol": "tcp", "FromPort": 8081, "ToPort": 8082, "IpRanges": [{"CidrIp": "10.0.0.1/32"}]}]'

Port 8081~8082で10.0.0.1/32からのアクセスを削除する

知りたいこと

GUIの名前タグに相当するオプションが見つからない。なんかあるんでしょうかね。
https://docs.aws.amazon.com/cli/latest/reference/ec2/authorize-security-group-ingress.html

あとで追記すること

jsonフォーマットを読み込み

10
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
7