【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

基本的に AWS を利用する際は GUI(グラフィカルインタフェース、Web の管理画面)から利用するケースが多いと思います。

しかし数が多くなってくると、GUI(Web の管理画面)からの操作ではミスが多くなったり作業に時間が掛かるようになります。

(1台、2台程度なら GUI から操作する方が効率がいいですが)

 

そのため AWS では、AWS CLI(コマンドライン)が用意されており、AWS CLI を利用することでセキュリティグループの作成やセキュリティグループのルールの追加、EC2 インスタンスの作成をすることができます。

実際に AWS 環境で構築や運用をすると、大量に EC2 インスタンスを作成する場合は GUI(Web の管理画面)から 1つ 1つボタンをクリックして作成するより、AWS CLI(コマンドライン)から実行した方が短時間で正確に大量の EC2 インスタンスを作成することが可能になります。

 

そこで今回は AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順を解説します。

 

【AWS】AWS CLI(AWS コマンドライン)からの EC2 インスタンス作成手順

 

【AWS】aws(AWS CLI) & jq コマンドの便利な使い方解説【運用管理に役立つ】

 

【AWS】【Windows&Linux】「EC2 インスタンス」または「パソコン」に AWS CLI(aws コマンド)及び jq コマンドをインストールする手順

 

 

 

目次

AWS CLI より EC2 インスタンスを作成するための手順概要

  1. セキュリティグループの作成(create-security-group)
  2. セキュリティグループにルールを追加する(インバウンド、authorize-security-group-ingress)
  3. セキュリティグループにルールを追加する(アウトバウンド、authorize-security-group-egress)
  4. アウトバウンド全て許可の設定を削除する(アウトバウンドを設定した場合に必要)
  5. AMI、セキュリティグループを指定して EC2 インスタンスを作成する

 

それぞれで作成状況を確認しつつ作業を進めます。

 

 

 

セキュリティグループの作成(create-security-group)

最初にセキュリティグループを作成します。

 

■1行で終わらせる場合

$ aws ec2 create-security-group --group-name Test-EC2-Instance-001-sg --vpc-id vpc-xxxxxx --description "Test EC2 Instance 001 by AWS CLI"

 

 

■複数行で実行する場合

$ aws ec2 create-security-group \

--group-name Test-EC2-Instance-001-sg \

--vpc-id vpc-xxxxxx \

--description "Test EC2 Instance 001 by AWS CLI"

 

各行末にバックスラッシュ(\、円マーク)を置くことでコマンドの途中で改行することができます。

バックスラッシュを置くことでコマンドが見やすくなるというメリットがあります。

 

ただし個人的には大量の EC2 インスタンスを作成することを考慮すると 1行 1コマンドを推奨します。(今回の記事では1行コマンドを中心に解説します)

例えば、Excel でコマンド管理をすることでコマンドのミスを減らすことが出来るようになります。

 

 

セキュリティグループを一気に大量に作成する場合

1行 1コマンドの場合は、以下のような感じになります。

 

■コマンド

aws ec2 create-security-group --group-name Test-EC2-Instance-001-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-001"
aws ec2 create-security-group --group-name Test-EC2-Instance-002-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-002"
aws ec2 create-security-group --group-name Test-EC2-Instance-003-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-003"
aws ec2 create-security-group --group-name Test-EC2-Instance-004-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-004"
aws ec2 create-security-group --group-name Test-EC2-Instance-005-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-005"
aws ec2 create-security-group --group-name Test-EC2-Instance-006-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-006"
aws ec2 create-security-group --group-name Test-EC2-Instance-007-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-007"
aws ec2 create-security-group --group-name Test-EC2-Instance-008-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-008"
aws ec2 create-security-group --group-name Test-EC2-Instance-009-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-009"
aws ec2 create-security-group --group-name Test-EC2-Instance-010-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-010"
aws ec2 create-security-group --group-name Test-EC2-Instance-011-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-011"
aws ec2 create-security-group --group-name Test-EC2-Instance-012-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-012"
aws ec2 create-security-group --group-name Test-EC2-Instance-013-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-013"
aws ec2 create-security-group --group-name Test-EC2-Instance-014-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-014"
aws ec2 create-security-group --group-name Test-EC2-Instance-015-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-015"
aws ec2 create-security-group --group-name Test-EC2-Instance-016-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-016"
aws ec2 create-security-group --group-name Test-EC2-Instance-017-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-017"
aws ec2 create-security-group --group-name Test-EC2-Instance-018-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-018"
aws ec2 create-security-group --group-name Test-EC2-Instance-019-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-019"
aws ec2 create-security-group --group-name Test-EC2-Instance-020-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-020"

 

 

■コマンド実行結果

以下のような感じでコマンドの実行結果の返り値で「GroupId」が返ってきます。

※ただしコマンドラインで何度も作成・削除を繰り返すため GroupId は使わないコマンドにしています。

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-001-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-001" 

    "GroupId": "sg-07afb4a27c4d30fc3" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-002-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-002" 

    "GroupId": "sg-0637e7ca395acdfa1" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-003-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-003" 

    "GroupId": "sg-003f8e84110e0024e" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-004-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-004" 

    "GroupId": "sg-0169d05346d39f1d3" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-005-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-005" 

    "GroupId": "sg-09c80728e5995b171" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-006-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-006" 

    "GroupId": "sg-0d07916ff2a09266c" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-007-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-007" 

    "GroupId": "sg-080462d41518a5231" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-008-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-008" 

    "GroupId": "sg-0a3e868f5628a0a92" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-009-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-009" 

    "GroupId": "sg-0760e9c314bcbc874" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-010-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-010" 

    "GroupId": "sg-04161bc2700b02a94" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-011-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-011" 

    "GroupId": "sg-05dad7f25bff7efd2" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-012-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-012" 

    "GroupId": "sg-06c3a55a0b749a07e" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-013-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-013" 

    "GroupId": "sg-04637ce25cc9be041" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-014-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-014" 

    "GroupId": "sg-0a22f91bd28114b44" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-015-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-015" 

    "GroupId": "sg-08f81d591ad2d63f1" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-016-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-016" 

    "GroupId": "sg-006c6c30dae83717b" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-017-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-017" 

    "GroupId": "sg-02d24b190b2c7fd91" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-018-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-018" 

    "GroupId": "sg-082cb2aafbaff9fbb" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-019-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-019" 

    "GroupId": "sg-08d409009f58f3373" 

[ec2-user@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-020-sg --vpc-id vpc-xxxxxxxxxx --description " Test-EC2-Instance-020" 

    "GroupId": "sg-02042d0969da268f4" 

[ec2-user@RedHat8 ~]$

 

 

 

 

■AWS 管理画面

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

create-security-group でセキュリティグループを作成する際にタグ付けはできない

ちなみに aws ec2 create-security-group でセキュリティグループを作成する際にタグ付けはできません。

(オプションがありません)

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

タグを付けたい場合は、別途「aws ec2 create-tags」コマンドを実行します。

 

セキュリティグループにタグを付ける

「aws ec2 create-tags」コマンドでセキュリティグループにタグを付けることができます。

 

■コマンド

aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg

 

 

■コマンド実行結果

[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$ aws ec2 create-tags --resources `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --tags Key=Name,Value=Test-EC2-Instance-001-sg
[ec2-user@RedHat8 ~]$

 

 

■AWS 管理画面での確認

実行前

 

 

実行後

 

 

 

An error occurred (UnauthorizedOperation) when calling the CreateSecurityGroup operation: You are not authorized to perform this operation.

権限が足りない場合は以下のような「You are not authorized to perform this operation.」のメッセージが出力されます。

[test@RedHat8 ~]$ aws ec2 create-security-group --group-name Test-EC2-Instance-001-sg --vpc-id vpc-xxxxxxx --description "Test-EC2-Instance-001-sg"

 

An error occurred (UnauthorizedOperation) when calling the CreateSecurityGroup operation: You are not authorized to perform this operation.
[test@RedHat8 ~]$

 

 

 

 

【トピック】大量にコマンドを実行した際にエラーになる場合

AWS CLI コマンドを数十行、数百行レベルで実行する際にエラーになる場合があります。

その場合はコマンドの投入が速すぎるのでコマンド投入のタイミングを遅らせます。

TeraTerm の場合は以下の設定をします。

 

メニューより「設定」をクリックします。

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

「その他の設定」をクリックします。

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

「コピーと貼り付け」タブで「貼り付けの行間遅延」「3000ミリ秒(3秒)」程度に設定し「OK」ボタンをクリックします。

※環境によって異なると思いますが、私の環境で何度も繰り返し行った結果、2~3秒くらいから安定してコマンドを処理できるようになりました。

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

 

セキュリティグループを大量に削除する

先ほど作成した大量のセキュリティグループを削除する手順です。

AWS CLI を利用すると何度も作ったり消したりして少しずつ改善ができるので品質を向上させることができます。

 

「--group-id」でグループIDを引数に取りますが、何度も作ったり消したりする前提なのでIDは都度変わります。

そのため、変わらないグループ名からグループIDを出力して「--grouop-id」の引数にしています。

 

グループ名からグループIDを出力するコマンドは「`aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r`」の部分です。

最後に「-r」が入っていますが、「-r」を入れないと以下のように「"(ダブルクォーテーション)」で囲まれて出力されます。

 

■-rオプションがない場合

[ec2-user@RedHat8 ~]$ aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId'

"sg-xxxxxxxx" ← ダブルクォーテーションで囲まれて表示されます。

[ec2-user@RedHat8 ~]$

 

 

■-rオプションがある場合

[ec2-user@RedHat8 ~]$ aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r

sg-xxxxxxxxxx ← ダブルクォーテーションがない状態で表示されます。

[ec2-user@RedHat8 ~]$

 

 

 

■コマンド

aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r`
aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r`

 

 

 

■コマンド実行結果

コマンド結果は以下のように返り値はありません。

[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ aws ec2 delete-security-group --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r`
[ec2-user@RedHat8 ~]$ 

 

 

 

AWS 管理画面での確認

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

セキュリティグループにルールを追加する(インバウンド、authorize-security-group-ingress)

セキュリティグループを作成したらインバウンドルールを追加します。

Windows版とLinux版を作成します。

※必要な場合は適宜追加します。

 

■ルールを複数設定する場合

ルールを複数設定する場合は以下のように「--ip-permissions」の後の「IpProtocol~」のひとかたまりずつ入れていきます。

2つ目は半角スペースを空けて「IpProtocol~」以降を入れていきます。

--ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'

 

 

 

Windows版(インバウンドルール)

■コマンド

aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'

 

 

■コマンド実行結果

返り値はありません。

[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=3389,ToPort=3389,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$

 

 

 

AWS 管理画面の確認

以下のように 1コマンドで複数のルールが作成されていることが確認できます。

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

 

Linux版(インバウンドルール)

■コマンド

aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'

 

 

■コマンド実行結果

[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-ingress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]' IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=192.168.0.0/24,Description="NetworkSegment0"},{CidrIp=192.168.1.0/24,Description="NetworkSegment1"}]'
[ec2-user@RedHat8 ~]$

 

 

 

AWS 管理画面の確認

以下のように 1コマンドで複数のルールが作成されていることが確認できます。

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

 

 

セキュリティグループにルールを追加する(アウトバウンド、authorize-security-group-egress)

次にアウトバウンドにもルールを設定したい場合は以下のコマンドで追加します。

デフォルトではアウトバウンドに関しては全て許可の設定になっています。

ちなみに今回はアウトバウンドのルールで PostgreSQL に接続することを想定し、5432/TCP のみ許可する設定とします。

 

Windows版(アウトバウンドルール)

■コマンド

aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'

 

 

■コマンド実行結果

[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$

 

 

AWS 管理画面の確認

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

Linux版(インバウンドルール)

※アウトバウンドの場合は、Windows & Linux 同じ設定になりますが、分けて記載しています。

■コマンド

aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'

 

 

■コマンド実行結果

[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$ aws ec2 authorize-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --ip-permissions IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges='[{CidrIp=10.0.0.0/24,Description="PostgreSQL Port 5432"},{CidrIp=10.0.1.0/24,Description="PostgreSQL Port 5432"}]'
[ec2-user@RedHat8 ~]$

 

 

AWS 管理画面の確認

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

 

アウトバウンド全て許可の設定を削除する(アウトバウンドを設定した場合に必要)

先ほどアウトバウンドの設定を入れましたが、デフォルトの「全て許可」の設定が残っていました。

そのデフォルトの設定を削除します。

 

Windows と Linux で同じコマンドになるので一括してコマンドを実行しています。

 

■コマンド

aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1

 

 

■コマンド実行結果

[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$ aws ec2 revoke-security-group-egress --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --cidr 0.0.0.0/0 --protocol -1 --port -1
[ec2-user@RedHat8 ~]$

 

 

 

AWS 管理画面の確認

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

セキュリティグループの内容を確認するコマンド

■コマンド

aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --output table
aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --output table

 

 

■コマンド実行結果

※非常に長くなるため最初の2つのコマンドだけ記載しています。

[ec2-user@RedHat8 ~]$ aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --output table 
------------------------------------------------------------------------------------------------------------------ 
|                                             DescribeSecurityGroups                                             | 
+----------------------------------------------------------------------------------------------------------------+ 
||                                                SecurityGroups                                                || 
|+------------------------+-----------------------+----------------------------+---------------+----------------+| 
||       Description      |        GroupId        |         GroupName          |    OwnerId    |     VpcId      || 
|+------------------------+-----------------------+----------------------------+---------------+----------------+| 
||   Test-EC2-Instance-001|  sg-0e4a352bf37b2f50e |  Test-EC2-Instance-001-sg  |  xxxxxxxxxxxxxx |  vpc-xxxxxxxxxx  || 
|+------------------------+-----------------------+----------------------------+---------------+----------------+| 
|||                                                IpPermissions                                               ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||             FromPort             |               IpProtocol                 |           ToPort             ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||  3389                            |  tcp                                     |  3389                        ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
||||                                                 IpRanges                                                 |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
||||                      CidrIp                       |                     Description                      |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
||||  192.168.0.0/24                                   |  NetworkSegment0                                     |||| 
||||  192.168.1.0/24                                   |  NetworkSegment1                                     |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
|||                                                IpPermissions                                               ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||             FromPort             |               IpProtocol                 |           ToPort             ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||  -1                              |  icmp                                    |  -1                          ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
||||                                                 IpRanges                                                 |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
||||                      CidrIp                       |                     Description                      |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
||||  192.168.0.0/24                                   |  NetworkSegment0                                     |||| 
||||  192.168.1.0/24                                   |  NetworkSegment1                                     |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
|||                                             IpPermissionsEgress                                            ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||             FromPort             |               IpProtocol                 |           ToPort             ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||  5432                            |  tcp                                     |  5432                        ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
||||                                                 IpRanges                                                 |||| 
|||+----------------------------------------+-----------------------------------------------------------------+||| 
||||                 CidrIp                 |                           Description                           |||| 
|||+----------------------------------------+-----------------------------------------------------------------+||| 
||||  10.0.0.0/24                           |  PostgreSQL Port 5432                                           |||| 
||||  10.0.1.0/24                           |  PostgreSQL Port 5432                                           |||| 
|||+----------------------------------------+-----------------------------------------------------------------+||| 
[ec2-user@RedHat8 ~]$ aws ec2 describe-security-groups --group-id `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --output table 
------------------------------------------------------------------------------------------------------------------ 
|                                             DescribeSecurityGroups                                             | 
+----------------------------------------------------------------------------------------------------------------+ 
||                                                SecurityGroups                                                || 
|+------------------------+-----------------------+----------------------------+---------------+----------------+| 
||       Description      |        GroupId        |         GroupName          |    OwnerId    |     VpcId      || 
|+------------------------+-----------------------+----------------------------+---------------+----------------+| 
||   Test-EC2-Instance-002|  sg-01eedc972e8aba652 |  Test-EC2-Instance-002-sg  |  xxxxxxxxxxxxxx |  vpc-xxxxxxxxxx  || 
|+------------------------+-----------------------+----------------------------+---------------+----------------+| 
|||                                                IpPermissions                                               ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||             FromPort             |               IpProtocol                 |           ToPort             ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||  3389                            |  tcp                                     |  3389                        ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
||||                                                 IpRanges                                                 |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
||||                      CidrIp                       |                     Description                      |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
||||  192.168.0.0/24                                   |  NetworkSegment0                                     |||| 
||||  192.168.1.0/24                                   |  NetworkSegment1                                     |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
|||                                                IpPermissions                                               ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||             FromPort             |               IpProtocol                 |           ToPort             ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||  -1                              |  icmp                                    |  -1                          ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
||||                                                 IpRanges                                                 |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
||||                      CidrIp                       |                     Description                      |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
||||  192.168.0.0/24                                   |  NetworkSegment0                                     |||| 
||||  192.168.1.0/24                                   |  NetworkSegment1                                     |||| 
|||+---------------------------------------------------+------------------------------------------------------+||| 
|||                                             IpPermissionsEgress                                            ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||             FromPort             |               IpProtocol                 |           ToPort             ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
|||  5432                            |  tcp                                     |  5432                        ||| 
||+----------------------------------+------------------------------------------+------------------------------+|| 
||||                                                 IpRanges                                                 |||| 
|||+----------------------------------------+-----------------------------------------------------------------+||| 
||||                 CidrIp                 |                           Description                           |||| 
|||+----------------------------------------+-----------------------------------------------------------------+||| 
||||  10.0.0.0/24                           |  PostgreSQL Port 5432                                           |||| 
||||  10.0.1.0/24                           |  PostgreSQL Port 5432                                           |||| 
|||+----------------------------------------+-----------------------------------------------------------------+||| 
[ec2-user@RedHat8 ~]$

 

 

 

 

セキュリティグループ名とセキュリティグループIDの確認方法

今回はセキュリティグループIDを使用する機会がありませんでしたが、以下のコマンドでセキュリティグループ名とセキュリティグループIDを確認できます。

 

■アウトプットがtableの場合

[ec2-user@RedHat8 ~]$ aws ec2 describe-security-groups --query "SecurityGroups[].[GroupName,GroupId]" --output table 
--------------------------------------------------------- 
|                DescribeSecurityGroups                 | 
+------------------------------+------------------------+ 
|  Test-EC2-Instance-008-sg    |  sg-00124498f8ef313d8  | 
|  Test-EC2-Instance-006-sg    |  sg-007e857551150d5f0  | 
|  Test-EC2-Instance-002-sg    |  sg-01eedc972e8aba652  | 
|  Test-EC2-Instance-015-sg    |  sg-0221f2f6f104d3827  | 
|  Test-EC2-Instance-010-sg    |  sg-0324a26eb4e96f8ed  | 
|  Test-EC2-Instance-018-sg    |  sg-04724257d06b6267f  | 
|  Test-EC2-Instance-007-sg    |  sg-06fa64e7be2028386  | 
|  Test-EC2-Instance-011-sg    |  sg-09870977db911339b  | 
|  Test-EC2-Instance-013-sg    |  sg-09ff24e6f0f00aec8  | 
|  Test-EC2-Instance-014-sg    |  sg-0a04c4647a396bde0  | 
|  Test-EC2-Instance-003-sg    |  sg-0a2a061064d6b036a  | 
|  Test-EC2-Instance-012-sg    |  sg-0a5e4e3e61d9a321c  | 
|  Test-EC2-Instance-017-sg    |  sg-0ae9e25189138ad23  | 
|  Test-EC2-Instance-019-sg    |  sg-0d1bde5964489bd48  | 
|  Test-EC2-Instance-004-sg    |  sg-0d8afab90cbb678d8  | 
|  Test-EC2-Instance-005-sg    |  sg-0de8fc3c05fed631d  | 
|  Test-EC2-Instance-001-sg    |  sg-0e4a352bf37b2f50e  | 
|  Test-EC2-Instance-016-sg    |  sg-0e9ef81dfed4d6c9b  | 
|  Test-EC2-Instance-009-sg    |  sg-0f997072deeb6e032  | 
|  Test-EC2-Instance-020-sg    |  sg-0feda280368f44d28  | 
|  default                     |  sg-922e21ea           | 
+------------------------------+------------------------+ 
[ec2-user@RedHat8 ~]$

 

 

 

■アウトプットがtextの場合

[ec2-user@RedHat8 ~]$ aws ec2 describe-security-groups --query "SecurityGroups[].[GroupName,GroupId]" --output text 
Test-EC2-Instance-008-sg        sg-00124498f8ef313d8 
Test-EC2-Instance-006-sg        sg-007e857551150d5f0 
Test-EC2-Instance-002-sg        sg-01eedc972e8aba652 
Test-EC2-Instance-015-sg        sg-0221f2f6f104d3827 
Test-EC2-Instance-010-sg        sg-0324a26eb4e96f8ed 
Test-EC2-Instance-018-sg        sg-04724257d06b6267f 
launch-wizard-1 sg-04e2733ee3b1cc837 
Test-EC2-Instance-007-sg        sg-06fa64e7be2028386 
Test-EC2-Instance-011-sg        sg-09870977db911339b 
Test-EC2-Instance-013-sg        sg-09ff24e6f0f00aec8 
Test-EC2-Instance-014-sg        sg-0a04c4647a396bde0 
Test-EC2-Instance-003-sg        sg-0a2a061064d6b036a 
Test-EC2-Instance-012-sg        sg-0a5e4e3e61d9a321c 
Test-EC2-Instance-017-sg        sg-0ae9e25189138ad23 
redhat7-test-security-group     sg-0c44fcf1a540bb986 
Test-EC2-Instance-019-sg        sg-0d1bde5964489bd48 
Test-EC2-Instance-004-sg        sg-0d8afab90cbb678d8 
Test-EC2-Instance-005-sg        sg-0de8fc3c05fed631d 
Test-EC2-Instance-001-sg        sg-0e4a352bf37b2f50e 
Test-EC2-Instance-016-sg        sg-0e9ef81dfed4d6c9b 
Test-EC2-Instance-009-sg        sg-0f997072deeb6e032 
Test-EC2-Instance-020-sg        sg-0feda280368f44d28 
default sg-922e21ea 
[ec2-user@RedHat8 ~]$

 

 

 

■アウトプットがデフォルト(json)の場合

[ec2-user@RedHat8 ~]$ aws ec2 describe-security-groups --query "SecurityGroups[].[GroupName,GroupId]" 

    [ 
        "Test-EC2-Instance-008-sg", 
        "sg-00124498f8ef313d8" 
    ], 
    [ 
        "Test-EC2-Instance-006-sg", 
        "sg-007e857551150d5f0" 
    ], 
    [ 
        "Test-EC2-Instance-002-sg", 
        "sg-01eedc972e8aba652" 
    ], 
    [ 
        "Test-EC2-Instance-015-sg", 
        "sg-0221f2f6f104d3827" 
    ], 
    [ 
        "Test-EC2-Instance-010-sg", 
        "sg-0324a26eb4e96f8ed" 
    ], 
    [ 
        "Test-EC2-Instance-018-sg", 
        "sg-04724257d06b6267f" 
    ], 
    [ 
        "launch-wizard-1", 
        "sg-04e2733ee3b1cc837" 
    ], 
    [ 
        "Test-EC2-Instance-007-sg", 
        "sg-06fa64e7be2028386" 
    ], 
    [ 
        "Test-EC2-Instance-011-sg", 
        "sg-09870977db911339b" 
    ], 
    [ 
        "Test-EC2-Instance-013-sg", 
        "sg-09ff24e6f0f00aec8" 
    ], 
    [ 
        "Test-EC2-Instance-014-sg", 
        "sg-0a04c4647a396bde0" 
    ], 
    [ 
        "Test-EC2-Instance-003-sg", 
        "sg-0a2a061064d6b036a" 
    ], 
    [ 
        "Test-EC2-Instance-012-sg", 
        "sg-0a5e4e3e61d9a321c" 
    ], 
    [ 
        "Test-EC2-Instance-017-sg", 
        "sg-0ae9e25189138ad23" 
    ], 
    [ 
        "redhat7-test-security-group", 
        "sg-0c44fcf1a540bb986" 
    ], 
    [ 
        "Test-EC2-Instance-019-sg", 
        "sg-0d1bde5964489bd48" 
    ], 
    [ 
        "Test-EC2-Instance-004-sg", 
        "sg-0d8afab90cbb678d8" 
    ], 
    [ 
        "Test-EC2-Instance-005-sg", 
        "sg-0de8fc3c05fed631d" 
    ], 
    [ 
        "Test-EC2-Instance-001-sg", 
        "sg-0e4a352bf37b2f50e" 
    ], 
    [ 
        "Test-EC2-Instance-016-sg", 
        "sg-0e9ef81dfed4d6c9b" 
    ], 
    [ 
        "Test-EC2-Instance-009-sg", 
        "sg-0f997072deeb6e032" 
    ], 
    [ 
        "Test-EC2-Instance-020-sg", 
        "sg-0feda280368f44d28" 
    ], 
    [ 
        "default", 
        "sg-922e21ea" 
    ] 

[ec2-user@RedHat8 ~]$

 

 

 

 

AMI、セキュリティグループを指定して EC2 インスタンスを作成する

セキュリティグループを20個分作成したので EC2 インスタンスを作成し、1つ1つのインスタンスに対してセキュリティグループを1つずつ割り当てます。

セキュリティグループをまとめてもいいのですが、まとめるとセキュリティグループを変更する際に影響範囲を正確に把握することが難しくなり思わぬ事故を引き起こしてしまう可能性があります。

せっかくコマンドラインから AWS を操作できるようになったため、1インスタンスに 1セキュリティグループを割り当てても手間ではありません。

 

AMI を決定する

まずは AMI を決定します。

Linux の場合は RedHat 系、Windows の場合は Windows の AMI を選択します。

 

今回は以下のようにしました。

 

■Windows

Microsoft Windows Server 2016 Base - ami-0404c1383f6b870a2

Microsoft Windows 2016 Datacenter edition. [English]

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

■Linux

Red Hat Enterprise Linux 8 (HVM), SSD Volume Type - ami-09f31cc5d5eecca1a

Red Hat Enterprise Linux version 8 (HVM), EBS General Purpose (SSD) Volume Type

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

 

Windows版(dry-run付き)

■コマンド

aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.101 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-001}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.102 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-002}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.103 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-003}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.104 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-004}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.105 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-005}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.106 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-006}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.107 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-007}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.108 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-008}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.109 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-009}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.110 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-010}]' --output table

 

 

■コマンド実行結果

[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.101 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-001}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.102 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-002}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.103 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-003}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.104 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-004}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.105 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-005}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.106 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-006}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.107 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-007}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.108 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-008}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.109 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-009}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.110 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-010}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$

 

 

AWS 管理画面の確認

dry-run なので AWS 管理画面には何も反映されません。

 

 

 

 

Linux版(dry-run付き)

■コマンド

aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.111 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-011}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.112 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-012}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.113 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-013}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.114 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-014}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.115 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-015}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.116 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-016}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.117 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-017}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.118 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-018}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.118 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-019}]' --output table
aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.118 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-020}]' --output table

 

 

■コマンド実行結果

[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.111 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-011}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.112 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-012}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.113 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-013}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.114 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-014}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.115 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-015}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.116 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-016}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.117 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-017}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.118 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-018}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.118 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-019}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --dry-run --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.118 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-020}]' --output table 
 
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set. 
[ec2-user@RedHat8 ~]$

 

 

AWS 管理画面の確認

dry-run なので AWS 管理画面には何も反映されません。

 

 

 

 

 

次に dry-run オプションを外して実際に作成します。

 

Windows版(実際に作成する)

■コマンド

aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.101 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-001}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.102 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-002}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.103 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-003}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.104 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-004}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.105 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-005}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.106 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-006}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.107 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-007}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.108 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-008}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.109 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-009}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.110 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-010}]' --output table

 

 

 

■コマンド実行結果

[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.101 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-001-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-001}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-09244f785249cfe9d                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-0404c1383f6b870a2                             || 
||  InstanceId            |  i-0ab0090682c4e0343                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:41:22.000Z                          || 
||  Platform              |  windows                                           || 
||  PrivateDnsName        |  ip-172-31-32-101.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.101                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:10:24:75:d5:9e                                  ||| 
|||  NetworkInterfaceId |  eni-0497f3fd86a364f22                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-101.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.101                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:41:22.000Z                 |||| 
||||  AttachmentId               |  eni-attach-0099193bff0e675b7             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0e4a352bf37b2f50e                            |||| 
||||  GroupName           |  Test-EC2-Instance-001-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-101.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.101                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0e4a352bf37b2f50e                              ||| 
|||  GroupName           |  Test-EC2-Instance-001-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-001                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.102 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-002-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-002}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0c0f4ea7a1651165b                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-0404c1383f6b870a2                             || 
||  InstanceId            |  i-049a59f1016f5de57                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:41:25.000Z                          || 
||  Platform              |  windows                                           || 
||  PrivateDnsName        |  ip-172-31-32-102.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.102                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:f0:fe:de:a3:ae                                  ||| 
|||  NetworkInterfaceId |  eni-0a55bf33e854f8105                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-102.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.102                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:41:25.000Z                 |||| 
||||  AttachmentId               |  eni-attach-09c28a753ec633ad9             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-01eedc972e8aba652                            |||| 
||||  GroupName           |  Test-EC2-Instance-002-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-102.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.102                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-01eedc972e8aba652                              ||| 
|||  GroupName           |  Test-EC2-Instance-002-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-002                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.103 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-003-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-003}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0253a8233120a01b5                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-0404c1383f6b870a2                             || 
||  InstanceId            |  i-0813d16a24942896f                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:41:28.000Z                          || 
||  Platform              |  windows                                           || 
||  PrivateDnsName        |  ip-172-31-32-103.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.103                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:f6:07:0f:b2:c8                                  ||| 
|||  NetworkInterfaceId |  eni-032b8f700fd97fe5d                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-103.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.103                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:41:28.000Z                 |||| 
||||  AttachmentId               |  eni-attach-05b8dd6ccb3d54805             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0a2a061064d6b036a                            |||| 
||||  GroupName           |  Test-EC2-Instance-003-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-103.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.103                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0a2a061064d6b036a                              ||| 
|||  GroupName           |  Test-EC2-Instance-003-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-003                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.104 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-004-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-004}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0dc248150a438a290                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-0404c1383f6b870a2                             || 
||  InstanceId            |  i-0dbcd9251dcfc1d04                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:41:31.000Z                          || 
||  Platform              |  windows                                           || 
||  PrivateDnsName        |  ip-172-31-32-104.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.104                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:77:dc:54:f4:18                                  ||| 
|||  NetworkInterfaceId |  eni-08cde13964ef643ad                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-104.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.104                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:41:31.000Z                 |||| 
||||  AttachmentId               |  eni-attach-068ff09a9ff1db9b8             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0d8afab90cbb678d8                            |||| 
||||  GroupName           |  Test-EC2-Instance-004-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-104.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.104                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0d8afab90cbb678d8                              ||| 
|||  GroupName           |  Test-EC2-Instance-004-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-004                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.105 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-005-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-005}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0ef5606781e5fce77                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-0404c1383f6b870a2                             || 
||  InstanceId            |  i-058d63992286ff3fc                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:41:34.000Z                          || 
||  Platform              |  windows                                           || 
||  PrivateDnsName        |  ip-172-31-32-105.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.105                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:22:f7:ba:55:ae                                  ||| 
|||  NetworkInterfaceId |  eni-05bd5cd140f1d0c9a                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-105.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.105                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:41:34.000Z                 |||| 
||||  AttachmentId               |  eni-attach-0355032b2c5033db7             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0de8fc3c05fed631d                            |||| 
||||  GroupName           |  Test-EC2-Instance-005-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-105.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.105                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0de8fc3c05fed631d                              ||| 
|||  GroupName           |  Test-EC2-Instance-005-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-005                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.106 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-006-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-006}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-01e680ff60572c4dc                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-0404c1383f6b870a2                             || 
||  InstanceId            |  i-0aeb9d0c014105d1c                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:41:37.000Z                          || 
||  Platform              |  windows                                           || 
||  PrivateDnsName        |  ip-172-31-32-106.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.106                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:45:84:83:f7:ac                                  ||| 
|||  NetworkInterfaceId |  eni-05174ecf7693ee4b8                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-106.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.106                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:41:37.000Z                 |||| 
||||  AttachmentId               |  eni-attach-0496023337059da4e             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-007e857551150d5f0                            |||| 
||||  GroupName           |  Test-EC2-Instance-006-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-106.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.106                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-007e857551150d5f0                              ||| 
|||  GroupName           |  Test-EC2-Instance-006-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-006                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.107 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-007-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-007}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0f8b1deb84a5c4c8c                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-0404c1383f6b870a2                             || 
||  InstanceId            |  i-0f05a31284f46acf2                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:41:40.000Z                          || 
||  Platform              |  windows                                           || 
||  PrivateDnsName        |  ip-172-31-32-107.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.107                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:d1:56:37:de:94                                  ||| 
|||  NetworkInterfaceId |  eni-04920aa8fdac22ac3                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-107.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.107                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:41:40.000Z                 |||| 
||||  AttachmentId               |  eni-attach-096eca8af6684abb3             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-06fa64e7be2028386                            |||| 
||||  GroupName           |  Test-EC2-Instance-007-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-107.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.107                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-06fa64e7be2028386                              ||| 
|||  GroupName           |  Test-EC2-Instance-007-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-007                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.108 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-008-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-008}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0c6b05e6e58561765                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-0404c1383f6b870a2                             || 
||  InstanceId            |  i-0b45098d7b94a6af3                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:41:43.000Z                          || 
||  Platform              |  windows                                           || 
||  PrivateDnsName        |  ip-172-31-32-108.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.108                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:d1:96:96:3b:a6                                  ||| 
|||  NetworkInterfaceId |  eni-0348757b513937178                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-108.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.108                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:41:43.000Z                 |||| 
||||  AttachmentId               |  eni-attach-0e32e49f919b10463             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-00124498f8ef313d8                            |||| 
||||  GroupName           |  Test-EC2-Instance-008-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-108.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.108                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-00124498f8ef313d8                              ||| 
|||  GroupName           |  Test-EC2-Instance-008-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-008                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.109 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-009-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-009}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0660bdeca300ff6c5                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-0404c1383f6b870a2                             || 
||  InstanceId            |  i-055ad2a8752c19402                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:41:46.000Z                          || 
||  Platform              |  windows                                           || 
||  PrivateDnsName        |  ip-172-31-32-109.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.109                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:11:04:23:35:62                                  ||| 
|||  NetworkInterfaceId |  eni-0e52b55a211d13ed3                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-109.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.109                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:41:46.000Z                 |||| 
||||  AttachmentId               |  eni-attach-098bf2e6988fa3914             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0f997072deeb6e032                            |||| 
||||  GroupName           |  Test-EC2-Instance-009-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-109.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.109                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0f997072deeb6e032                              ||| 
|||  GroupName           |  Test-EC2-Instance-009-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-009                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-0404c1383f6b870a2 --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.110 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-010-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-010}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0632c81d7153227ec                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-0404c1383f6b870a2                             || 
||  InstanceId            |  i-09cb0af79c91b832d                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:41:49.000Z                          || 
||  Platform              |  windows                                           || 
||  PrivateDnsName        |  ip-172-31-32-110.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.110                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:0d:67:6b:67:2e                                  ||| 
|||  NetworkInterfaceId |  eni-0364ab4fd2a2a0f20                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-110.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.110                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:41:49.000Z                 |||| 
||||  AttachmentId               |  eni-attach-0df740a3d07890a68             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0324a26eb4e96f8ed                            |||| 
||||  GroupName           |  Test-EC2-Instance-010-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-110.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.110                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0324a26eb4e96f8ed                              ||| 
|||  GroupName           |  Test-EC2-Instance-010-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-010                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$

 

AWS 管理画面の確認

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

 

Linux版(実際に作成する)

■コマンド

aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.111 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-011}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.112 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-012}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.113 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-013}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.114 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-014}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.115 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-015}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.116 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-016}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.117 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-017}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.118 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-018}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.119 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-019}]' --output table
aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.120 --security-group-ids `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-020}]' --output table

 

 

■コマンド実行結果

[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.111 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-011-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-011}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0c557dbbd1dee9305                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-09f31cc5d5eecca1a                             || 
||  InstanceId            |  i-0463e97a027c6a339                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:53:51.000Z                          || 
||  PrivateDnsName        |  ip-172-31-32-111.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.111                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:42:cb:e9:d0:aa                                  ||| 
|||  NetworkInterfaceId |  eni-0737da59b7beb6c16                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-111.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.111                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:53:51.000Z                 |||| 
||||  AttachmentId               |  eni-attach-0cc34b1842bafb885             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-09870977db911339b                            |||| 
||||  GroupName           |  Test-EC2-Instance-011-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-111.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.111                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-09870977db911339b                              ||| 
|||  GroupName           |  Test-EC2-Instance-011-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-011                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.112 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-012-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-012}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0c425be22d20e60d7                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-09f31cc5d5eecca1a                             || 
||  InstanceId            |  i-00eeb584ce678bca0                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:53:54.000Z                          || 
||  PrivateDnsName        |  ip-172-31-32-112.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.112                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:fa:77:09:19:f2                                  ||| 
|||  NetworkInterfaceId |  eni-0fb37d485787908a0                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-112.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.112                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:53:54.000Z                 |||| 
||||  AttachmentId               |  eni-attach-05b6a04b65da86a3f             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0a5e4e3e61d9a321c                            |||| 
||||  GroupName           |  Test-EC2-Instance-012-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-112.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.112                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0a5e4e3e61d9a321c                              ||| 
|||  GroupName           |  Test-EC2-Instance-012-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-012                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.113 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-013-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-013}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0e65650723315bd79                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-09f31cc5d5eecca1a                             || 
||  InstanceId            |  i-0dd24ed061fc46f6c                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:53:57.000Z                          || 
||  PrivateDnsName        |  ip-172-31-32-113.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.113                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:99:a0:ca:fc:b4                                  ||| 
|||  NetworkInterfaceId |  eni-077873f72e87fb1ec                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-113.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.113                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:53:57.000Z                 |||| 
||||  AttachmentId               |  eni-attach-04867f8a945471b38             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-09ff24e6f0f00aec8                            |||| 
||||  GroupName           |  Test-EC2-Instance-013-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-113.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.113                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-09ff24e6f0f00aec8                              ||| 
|||  GroupName           |  Test-EC2-Instance-013-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-013                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.114 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-014-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-014}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0bb3b3c64dabbdd1e                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-09f31cc5d5eecca1a                             || 
||  InstanceId            |  i-06c6c0bf2b9083080                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:54:00.000Z                          || 
||  PrivateDnsName        |  ip-172-31-32-114.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.114                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:b0:4c:c0:dc:68                                  ||| 
|||  NetworkInterfaceId |  eni-04dca10d15fd17f98                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-114.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.114                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:54:00.000Z                 |||| 
||||  AttachmentId               |  eni-attach-0a4046985ef5047c0             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0a04c4647a396bde0                            |||| 
||||  GroupName           |  Test-EC2-Instance-014-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-114.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.114                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0a04c4647a396bde0                              ||| 
|||  GroupName           |  Test-EC2-Instance-014-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-014                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.115 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-015-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-015}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0a5fa3e7971c848fd                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-09f31cc5d5eecca1a                             || 
||  InstanceId            |  i-080e84ceaf55a3675                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:54:03.000Z                          || 
||  PrivateDnsName        |  ip-172-31-32-115.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.115                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:8f:0f:29:80:22                                  ||| 
|||  NetworkInterfaceId |  eni-0dadda147d2129d4b                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-115.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.115                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:54:03.000Z                 |||| 
||||  AttachmentId               |  eni-attach-082ac0bdd9f9dfd93             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0221f2f6f104d3827                            |||| 
||||  GroupName           |  Test-EC2-Instance-015-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-115.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.115                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0221f2f6f104d3827                              ||| 
|||  GroupName           |  Test-EC2-Instance-015-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-015                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.116 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-016-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-016}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0145d3f31a4b634e6                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-09f31cc5d5eecca1a                             || 
||  InstanceId            |  i-0b72d6fd54f8092cf                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:54:06.000Z                          || 
||  PrivateDnsName        |  ip-172-31-32-116.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.116                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:22:71:38:1b:da                                  ||| 
|||  NetworkInterfaceId |  eni-0cc57863f8eb7599a                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-116.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.116                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:54:06.000Z                 |||| 
||||  AttachmentId               |  eni-attach-0e8770ee1cc6a3caa             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0e9ef81dfed4d6c9b                            |||| 
||||  GroupName           |  Test-EC2-Instance-016-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-116.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.116                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0e9ef81dfed4d6c9b                              ||| 
|||  GroupName           |  Test-EC2-Instance-016-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-016                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.117 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-017-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-017}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-0daccc520ce1a0f5d                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-09f31cc5d5eecca1a                             || 
||  InstanceId            |  i-0574b88225a3a6fc1                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:54:09.000Z                          || 
||  PrivateDnsName        |  ip-172-31-32-117.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.117                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:48:27:4a:d7:d4                                  ||| 
|||  NetworkInterfaceId |  eni-0e97e5ff84723df14                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-117.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.117                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:54:09.000Z                 |||| 
||||  AttachmentId               |  eni-attach-0fdb5d095cab84639             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0ae9e25189138ad23                            |||| 
||||  GroupName           |  Test-EC2-Instance-017-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-117.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.117                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0ae9e25189138ad23                              ||| 
|||  GroupName           |  Test-EC2-Instance-017-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-017                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.118 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-018-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-018}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-03f5bf87ab5163276                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-09f31cc5d5eecca1a                             || 
||  InstanceId            |  i-011e38be894f9f3a8                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:54:12.000Z                          || 
||  PrivateDnsName        |  ip-172-31-32-118.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.118                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:a6:ba:d9:17:ac                                  ||| 
|||  NetworkInterfaceId |  eni-04a65c07361f7a941                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-118.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.118                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:54:12.000Z                 |||| 
||||  AttachmentId               |  eni-attach-093576109af7dfe96             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-04724257d06b6267f                            |||| 
||||  GroupName           |  Test-EC2-Instance-018-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-118.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.118                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-04724257d06b6267f                              ||| 
|||  GroupName           |  Test-EC2-Instance-018-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-018                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.119 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-019-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-019}]' --output table 
--------------------------------------------------------------------------------- 
|                                 RunInstances                                  | 
+--------------------------------+----------------------------------------------+ 
|  OwnerId                       |  xxxxxxxxxxxxxx                                | 
|  ReservationId                 |  r-075f8989ff20128af                         | 
+--------------------------------+----------------------------------------------+ 
||                                  Instances                                  || 
|+------------------------+----------------------------------------------------+| 
||  AmiLaunchIndex        |  0                                                 || 
||  Architecture          |  x86_64                                            || 
||  ClientToken           |                                                    || 
||  EbsOptimized          |  False                                             || 
||  Hypervisor            |  xen                                               || 
||  ImageId               |  ami-09f31cc5d5eecca1a                             || 
||  InstanceId            |  i-0c43420caf84e35e3                               || 
||  InstanceType          |  t2.small                                          || 
||  KeyName               |  basic-network                                     || 
||  LaunchTime            |  2019-08-17T05:54:15.000Z                          || 
||  PrivateDnsName        |  ip-172-31-32-119.ap-northeast-1.compute.internal  || 
||  PrivateIpAddress      |  172.31.32.119                                     || 
||  PublicDnsName         |                                                    || 
||  RootDeviceName        |  /dev/sda1                                         || 
||  RootDeviceType        |  ebs                                               || 
||  SourceDestCheck       |  True                                              || 
||  StateTransitionReason |                                                    || 
||  SubnetId              |  subnet-653b2a2c                                   || 
||  VirtualizationType    |  hvm                                               || 
||  VpcId                 |  vpc-xxxxxxxxxx                                      || 
|+------------------------+----------------------------------------------------+| 
|||                     CapacityReservationSpecification                      ||| 
||+------------------------------------------------------------+--------------+|| 
|||  CapacityReservationPreference                             |  open        ||| 
||+------------------------------------------------------------+--------------+|| 
|||                                CpuOptions                                 ||| 
||+----------------------------------------------------------+----------------+|| 
|||  CoreCount                                               |  1             ||| 
|||  ThreadsPerCore                                          |  1             ||| 
||+----------------------------------------------------------+----------------+|| 
|||                                Monitoring                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||  State                        |  disabled                                 ||| 
||+-------------------------------+-------------------------------------------+|| 
|||                             NetworkInterfaces                             ||| 
||+---------------------+-----------------------------------------------------+|| 
|||  Description        |                                                     ||| 
|||  InterfaceType      |  interface                                          ||| 
|||  MacAddress         |  06:0a:f1:70:ee:ae                                  ||| 
|||  NetworkInterfaceId |  eni-0454b68f412b709f0                              ||| 
|||  OwnerId            |  xxxxxxxxxxxxxx                                       ||| 
|||  PrivateDnsName     |  ip-172-31-32-119.ap-northeast-1.compute.internal   ||| 
|||  PrivateIpAddress   |  172.31.32.119                                      ||| 
|||  SourceDestCheck    |  True                                               ||| 
|||  Status             |  in-use                                             ||| 
|||  SubnetId           |  subnet-653b2a2c                                    ||| 
|||  VpcId              |  vpc-xxxxxxxxxx                                       ||| 
||+---------------------+-----------------------------------------------------+|| 
||||                               Attachment                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||  AttachTime                 |  2019-08-17T05:54:15.000Z                 |||| 
||||  AttachmentId               |  eni-attach-0f9bfade6593fe5ef             |||| 
||||  DeleteOnTermination        |  True                                     |||| 
||||  DeviceIndex                |  0                                        |||| 
||||  Status                     |  attaching                                |||| 
|||+-----------------------------+-------------------------------------------+||| 
||||                                 Groups                                  |||| 
|||+----------------------+--------------------------------------------------+||| 
||||  GroupId             |  sg-0d1bde5964489bd48                            |||| 
||||  GroupName           |  Test-EC2-Instance-019-sg                        |||| 
|||+----------------------+--------------------------------------------------+||| 
||||                           PrivateIpAddresses                            |||| 
|||+-------------------+-----------------------------------------------------+||| 
||||  Primary          |  True                                               |||| 
||||  PrivateDnsName   |  ip-172-31-32-119.ap-northeast-1.compute.internal   |||| 
||||  PrivateIpAddress |  172.31.32.119                                      |||| 
|||+-------------------+-----------------------------------------------------+||| 
|||                                 Placement                                 ||| 
||+-------------------------------------+-------------------------------------+|| 
|||  AvailabilityZone                   |  ap-northeast-1a                    ||| 
|||  GroupName                          |                                     ||| 
|||  Tenancy                            |  default                            ||| 
||+-------------------------------------+-------------------------------------+|| 
|||                              SecurityGroups                               ||| 
||+----------------------+----------------------------------------------------+|| 
|||  GroupId             |  sg-0d1bde5964489bd48                              ||| 
|||  GroupName           |  Test-EC2-Instance-019-sg                          ||| 
||+----------------------+----------------------------------------------------+|| 
|||                                   State                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||  Code                        |  0                                         ||| 
|||  Name                        |  pending                                   ||| 
||+------------------------------+--------------------------------------------+|| 
|||                                StateReason                                ||| 
||+------------------------------------+--------------------------------------+|| 
|||  Code                              |  pending                             ||| 
|||  Message                           |  pending                             ||| 
||+------------------------------------+--------------------------------------+|| 
|||                                   Tags                                    ||| 
||+------------------+--------------------------------------------------------+|| 
|||  Key             |  Name                                                  ||| 
|||  Value           |  Test-EC2-Instance-019                                 ||| 
||+------------------+--------------------------------------------------------+|| 
[ec2-user@RedHat8 ~]$ aws ec2 run-instances --region ap-northeast-1 --image-id ami-09f31cc5d5eecca1a --count 1 --instance-type t2.small --key-name basic-network --subnet-id subnet-653b2a2c --private-ip-address 172.31.32.120 --security-group-ids  `aws ec2 describe-security-groups --filters "Name=group-name,Values=Test-EC2-Instance-020-sg" | jq '.SecurityGroups[].GroupId' -r` --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-EC2-Instance-020}]' --output table 
 
An error occurred (InstanceLimitExceeded) when calling the RunInstances operation: Your quota allows for 0 more running instance(s). You requested at least 1 
[ec2-user@RedHat8 ~]$

 

最後の1つが制限に引っかかってしまいました。

 

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

確認すると「t2.small」「20」個までしか作成できないように制限されていました。

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

 

AWS 管理画面の確認

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

 

 

【確認】インスタンスの Name タグよりインスタンスIDを取得する

 

 

■コマンド

aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-001"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-002"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-003"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-004"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-005"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-006"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-007"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-008"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-009"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-010"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-011"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-012"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-013"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-014"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-015"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-016"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-017"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-018"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-019"| jq '.Reservations[].Instances[].InstanceId' -r
aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-020"| jq '.Reservations[].Instances[].InstanceId' -r

 

 

 

■コマンド実行結果(削除中のインスタンスも表示される)

[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-001"| jq '.Reservations[].Instances[].InstanceId' -r
i-0ab0090682c4e0343
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-002"| jq '.Reservations[].Instances[].InstanceId' -r
i-049a59f1016f5de57
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-003"| jq '.Reservations[].Instances[].InstanceId' -r
i-0813d16a24942896f
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-004"| jq '.Reservations[].Instances[].InstanceId' -r
i-0dbcd9251dcfc1d04
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-005"| jq '.Reservations[].Instances[].InstanceId' -r
i-058d63992286ff3fc
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-006"| jq '.Reservations[].Instances[].InstanceId' -r
i-0aeb9d0c014105d1c
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-007"| jq '.Reservations[].Instances[].InstanceId' -r
i-0f05a31284f46acf2
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-008"| jq '.Reservations[].Instances[].InstanceId' -r
i-0b45098d7b94a6af3
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-009"| jq '.Reservations[].Instances[].InstanceId' -r
i-055ad2a8752c19402
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-010"| jq '.Reservations[].Instances[].InstanceId' -r
i-09cb0af79c91b832d
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-011"| jq '.Reservations[].Instances[].InstanceId' -r
i-0463e97a027c6a339
i-0c61ac965782d0a4d
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-012"| jq '.Reservations[].Instances[].InstanceId' -r
i-00eeb584ce678bca0
i-056307d8058f1715d
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-013"| jq '.Reservations[].Instances[].InstanceId' -r
i-0b20b430a7bc62764
i-0dd24ed061fc46f6c
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-014"| jq '.Reservations[].Instances[].InstanceId' -r
i-0dc418bac33ca912c
i-06c6c0bf2b9083080
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-015"| jq '.Reservations[].Instances[].InstanceId' -r
i-00ee604f1450f1449
i-080e84ceaf55a3675
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-016"| jq '.Reservations[].Instances[].InstanceId' -r
i-0b72d6fd54f8092cf
i-0e4b0fa171adb9ebc
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-017"| jq '.Reservations[].Instances[].InstanceId' -r
i-0574b88225a3a6fc1
i-034f102734c6a6405
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-018"| jq '.Reservations[].Instances[].InstanceId' -r
i-0e4ea87b2807fc47c
i-011e38be894f9f3a8
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-019"| jq '.Reservations[].Instances[].InstanceId' -r
i-0c43420caf84e35e3
[ec2-user@RedHat8 ~]$ aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-020"| jq '.Reservations[].Instances[].InstanceId' -r
[ec2-user@RedHat8 ~]$

 

 

 

 

削除中のインスタンスは表示しない(起動中、running のみ表示する)ためには filter に「"Name=instance-state-name,Values=running"」を追加します。

 

 

■コマンド(削除中のインスタンスは表示しない)

aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-001" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-002" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-003" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-004" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-005" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-006" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-007" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-008" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-009" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-010" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-011" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-012" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-013" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-014" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-015" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-016" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-017" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-018" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-019" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-020" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r`

 

 

■コマンド実行結果(削除中のインスタンスは表示しない)

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-001" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-0ab0090682c4e0343", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-002" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-049a59f1016f5de57", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-003" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-0813d16a24942896f", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-004" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-0dbcd9251dcfc1d04", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-005" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-058d63992286ff3fc", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-006" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-0aeb9d0c014105d1c", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-007" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-0f05a31284f46acf2", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-008" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-0b45098d7b94a6af3", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-009" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-055ad2a8752c19402", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-010" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-09cb0af79c91b832d", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-011" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-0463e97a027c6a339", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-012" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-00eeb584ce678bca0", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-013" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-0dd24ed061fc46f6c", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-014" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-06c6c0bf2b9083080", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-015" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-080e84ceaf55a3675", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-016" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-0b72d6fd54f8092cf", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-017" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-0574b88225a3a6fc1", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-018" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-011e38be894f9f3a8", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-019" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "StoppingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 64, 
                "Name": "stopping" 
            }, 
            "InstanceId": "i-0c43420caf84e35e3", 
            "PreviousState": { 
                "Code": 16, 
                "Name": "running" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 stop-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-020" "Name=instance-state-name,Values=running"| jq '.Reservations[].Instances[].InstanceId' -r` 
 
An error occurred (InvalidParameterCombination) when calling the StopInstances operation: No instances specified 
[ec2-user@RedHat8 ~]$

 

 

 

 

作成した EC2 インスタンスを削除する

最後に作成した EC2 インスタンスを削除します。

 

■コマンド

aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-001"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-002"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-003"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-004"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-005"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-006"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-007"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-008"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-009"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-010"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-011"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-012"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-013"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-014"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-015"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-016"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-017"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-018"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-019"| jq '.Reservations[].Instances[].InstanceId' -r`
aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-020"| jq '.Reservations[].Instances[].InstanceId' -r`

 

 

■コマンド実行結果

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-001"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0ab0090682c4e0343", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-002"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-049a59f1016f5de57", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-003"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0813d16a24942896f", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-004"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0dbcd9251dcfc1d04", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-005"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-058d63992286ff3fc", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-006"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0aeb9d0c014105d1c", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-007"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0f05a31284f46acf2", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-008"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0b45098d7b94a6af3", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-009"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-055ad2a8752c19402", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-010"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-09cb0af79c91b832d", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-011"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0463e97a027c6a339", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        }, 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0c61ac965782d0a4d", 
            "PreviousState": { 
                "Code": 48, 
                "Name": "terminated" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-012"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-00eeb584ce678bca0", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        }, 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-056307d8058f1715d", 
            "PreviousState": { 
                "Code": 48, 
                "Name": "terminated" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-013"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0dd24ed061fc46f6c", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        }, 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0b20b430a7bc62764", 
            "PreviousState": { 
                "Code": 48, 
                "Name": "terminated" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-014"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-06c6c0bf2b9083080", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        }, 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0dc418bac33ca912c", 
            "PreviousState": { 
                "Code": 48, 
                "Name": "terminated" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-015"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-080e84ceaf55a3675", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        }, 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-00ee604f1450f1449", 
            "PreviousState": { 
                "Code": 48, 
                "Name": "terminated" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-016"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0b72d6fd54f8092cf", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        }, 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0e4b0fa171adb9ebc", 
            "PreviousState": { 
                "Code": 48, 
                "Name": "terminated" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-017"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0574b88225a3a6fc1", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        }, 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-034f102734c6a6405", 
            "PreviousState": { 
                "Code": 48, 
                "Name": "terminated" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-018"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-011e38be894f9f3a8", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        }, 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0e4ea87b2807fc47c", 
            "PreviousState": { 
                "Code": 48, 
                "Name": "terminated" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-019"| jq '.Reservations[].Instances[].InstanceId' -r` 

    "TerminatingInstances": [ 
        { 
            "CurrentState": { 
                "Code": 48, 
                "Name": "terminated" 
            }, 
            "InstanceId": "i-0c43420caf84e35e3", 
            "PreviousState": { 
                "Code": 80, 
                "Name": "stopped" 
            } 
        } 
    ] 

[ec2-user@RedHat8 ~]$ aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filter "Name=tag:Name,Values=Test-EC2-Instance-020"| jq '.Reservations[].Instances[].InstanceId' -r` 
 
An error occurred (InvalidParameterCombination) when calling the TerminateInstances operation: No instances specified 
[ec2-user@RedHat8 ~]$

 

 

 

AWS 管理画面での確認

【AWS】AWS CLI(コマンドライン)でセキュリティグループと EC2 インスタンスを作成する手順

 

 

 

 

 

Posted by 100%レンタルサーバーを使いこなすサイト管理人

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

AlphaOmega Captcha Medica  –  What Do You See?
     
 

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください