LoginSignup
0
0

More than 1 year has passed since last update.

[AWS] 作成済みEC2インスタンスのセキュリティグループをAWS Tools for PowerShellで変更する

Last updated at Posted at 2021-10-13

本記事は「作成済みEC2インスタンスに割り当てているセキュリティグループ」をAWS Tools for PowerShellで変更したい場合のコマンドメモです。

ここの設定を変更したい:
image.png

変更するコマンド

コマンドは Edit-EC2InstanceAttribute Cmdlet を使用します:

Edit-EC2InstanceAttribute -InstanceId <String> -Group <String[]>

実行例:PowerShellに不慣れだと間違えやすいですが、リストは @() 形式での指定になります。

Edit-EC2InstanceAttribute -InstanceId 'i-0da123456' -Group @( 'sg-35b28551', 'sg-35b28552' )

関連情報の収集

変更する場合、変更前にインスタンスに設定されているグループIDのリストが必要になることも多いかと思います。その場合は Get-EC2InstanceAttribute コマンドで取得します。

Get-EC2InstanceAttribute -InstanceId <String> -Attribute 'groupset'

実行例:

$current_sgs = Get-EC2InstanceAttribute -InstanceId 'i-0da123456' -Attribute 'groupset'
foreach($group in $current_sgs.Groups) {
     $group.GroupId
}

sg-35b28550
sg-35b28551

このグループIDのリストを追加変更して Edit-EC2InstanceAttribute の引数に設定する流れとなります。

参考資料

0
0
0

Register as a new user and use Qiita more conveniently

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