AWS CLIでVPCを指定した場合、–security-groupsが使えない

この記事は公開されてから半年以上経過しています。情報が古い可能性がありますので、ご注意ください。

結論から言うと、run-instancesコマンドでインスタンスを作成時、VPCを指定すると–security-groupsは使えないので、
–security-group-idsを使わなければいけないらしい。

以下のCLIコマンドを使用し、インスタンスを作成しようとした際、エラーになった。


aws ec2 run-instances --image-id ami-xxxxxxx --count 1 --instance-type t2.small --key-name hogehogehoge --security-groups sg-xxxxxxx --subnet-id subnet-xxxxxxxx --user-data file://script_for_user_data.txt

エラーメッセージ

A client error (InvalidParameterCombination) occurred when calling the RunInstances operation: The parameter groupName cannot be used with the parameter subnet

公式サイトには、きちんと書いてあったが、上記のエラーメッセージは不親切でわかりづらい。

For a nondefault VPC, you must use security group IDs instead.

日本語訳

デフォルトVPCを使用しない場合、代わりにセキュリティーグループIDを使用しなければならない。

コメントを残す

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

Time limit is exhausted. Please reload CAPTCHA.