Elastic Beanstalk 環境に紐づくセキュリティグループを削除したことによるエラーの解決策を教えてください
この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
困っていた内容
Elastic Beanstalk 環境にカスタムセキュリティグループを追加していました。
カスタムセキュリティグループが不要になったのでセキュリティグループのコンソール上から削除したところ、Elastic Beanstalk 環境で以下のエラーが発生してしまい環境の設定変更ができなくなってしまいました。
Failed Environment update activity. Reason: Configuration validation exception: Invalid option value: ‘sg-xxx’ (Namespace: ‘aws:autoscaling:launchconfiguration’, OptionName: ‘SecurityGroups’): The security group having id ‘sg-xxx’ does not exist
上記エラーの解決策を教えてください。
どう対応すればいいの?
update-environment コマンドを以下のオプションで実行してください。
$ aws elasticbeanstalk update-environment \
--environment-name your-environment-name \
--option-settings Namespace=aws:autoscaling:launchconfiguration,OptionName=SecurityGroups,Value=""
更新前の起動設定または起動テンプレートには削除されたカスタムセキュリティグループが設定されているため実際の環境との不一致が発生しています。
上記コマンドを実行することで Elastic Beanstalk 環境に紐づくカスタセキュリティグループの設定が削除されるので、実際の環境との不一致を解消できます。
やってみた
実際にエラーを発生させ、update-environment でエラーが解消されることを確認します。
なお、検証には CloudShell と EB CLI を利用します。
環境準備
まずはコンソールでセキュリティグループを作成します。
CloudShell に EB CLI をインストールします。
$ git clone https://github.com/aws/aws-elastic-beanstalk-cli-setup.git
$ python ./aws-elastic-beanstalk-cli-setup/scripts/ebcli_installer.py
$ echo 'export PATH="/home/ec2-user/.ebcli-virtual-env/executables:$PATH"' >> ~/.bash_profile && source ~/.bash_profile
$ eb --version
EB CLI 3.21.0 (Python 3.9.20 (main, Dec 11 2024, 00:00:00)
[GCC 11.4.1 20230605 (Red Hat 11.4.1-2)])
AWS 公式ドキュメントから Node.js のサンプルアプリケーションを取得します。
$ mkdir nodejs
$ cd nodejs
$ wget https://docs.aws.amazon.com/ja_jp/elasticbeanstalk/latest/dg/samples/nodejs.zip
$ unzip nodejs.zip
$ rm nodejs.zip
AWS ナレッジセンターを参考にカスタムセキュリティグループの設定を追加します。
custom-sg の部分にはコンソールから作成したセキュリティグループ名を記載します。
$ nano .ebextensions/securitygroup.config
option_settings:
- namespace: aws:autoscaling:launchconfiguration
option_name: SecurityGroups
value: custom-sg
Elastic Beanstalk 環境を作成してデプロイします。
$ eb init -i
# リージョン選択
Select a default region
1) us-east-1 : US East (N. Virginia)
2) us-west-1 : US West (N. California)
3) us-west-2 : US West (Oregon)
4) eu-west-1 : EU (Ireland)
5) eu-central-1 : EU (Frankfurt)
6) ap-south-1 : Asia Pacific (Mumbai)
7) ap-southeast-1 : Asia Pacific (Singapore)
8) ap-southeast-2 : Asia Pacific (Sydney)
9) ap-northeast-1 : Asia Pacific (Tokyo)
10) ap-northeast-2 : Asia Pacific (Seoul)
11) sa-east-1 : South America (Sao Paulo)
12) cn-north-1 : China (Beijing)
13) cn-northwest-1 : China (Ningxia)
14) us-east-2 : US East (Ohio)
15) ca-central-1 : Canada (Central)
16) eu-west-2 : EU (London)
17) eu-west-3 : EU (Paris)
18) eu-north-1 : EU (Stockholm)
19) eu-south-1 : EU (Milano)
20) ap-east-1 : Asia Pacific (Hong Kong)
21) me-south-1 : Middle East (Bahrain)
22) af-south-1 : Africa (Cape Town)
23) ap-southeast-3 : Asia Pacific (Jakarta)
24) ap-northeast-3 : Asia Pacific (Osaka)
(default is 3): 9
# アプリケーション名設定
Enter Application Name
(default is "nodejs"):
Application nodejs has been created.
# プラットフォームの確認
It appears you are using Node.js. Is this correct?
(Y/n):
Select a platform branch.
1) Node.js 22 running on 64bit Amazon Linux 2023
2) Node.js 20 running on 64bit Amazon Linux 2023
3) Node.js 18 running on 64bit Amazon Linux 2023
4) Node.js 18 running on 64bit Amazon Linux 2
(default is 1):
# SSH キーペアの設定
Cannot setup CodeCommit because there is no Source Control setup, continuing with initialization
Do you want to set up SSH for your instances?
(Y/n): n
# Creating Elastic Beanstalk environment
$ eb create --single
Enter Environment Name
(default is nodejs-dev):
Enter DNS CNAME prefix
(default is nodejs-dev):
Would you like to enable Spot Fleet requests for this environment? (y/N):
2025-09-24 02:24:08 INFO Successfully launched environment: nodejs-dev
デプロイ完了後、Auto Scaling グループの設定を確認すると custom-sg が追加されていることがわかります。
カスタムセキュリティグループを削除してみる
環境が準備できたのでエラーを発生させるためにカスタムのセキュリティグループを削除してみます。
削除するためには ENI からセキュリティグループを外す必要があるので、ENI の設定変更でカスタムセキュリティグループを削除します。
ENI での削除後にカスタムセキュリティグループ自体を削除します。
この状態で Elastic Beanstalk 環境から設定変更を実施しようとするとエラーが発生します。
Configuration validation exception: Invalid option value: 'custom-sg' (Namespace: 'aws:autoscaling:launchconfiguration', OptionName: 'SecurityGroups'): The security group 'custom-sg' does not exist
Elastic Beanstalk 環境に紐づくカスタムセキュリティグループを削除したことで、実際の環境との不一致が発生している状態です。
update-environment コマンドを実行する
エラーを解消するために CloudShell から update-environment を実行してみます。
$ aws elasticbeanstalk update-environment \
--environment-name nodejs-dev \
--option-settings Namespace=aws:autoscaling:launchconfiguration,OptionName=SecurityGroups,Value=""
{
"EnvironmentName": "nodejs-dev",
"EnvironmentId": "e-ab4fa2c2pd",
"ApplicationName": "nodejs",
"VersionLabel": "app-250924_022131889490",
"SolutionStackName": "64bit Amazon Linux 2023 v6.6.5 running Node.js 22",
"PlatformArn": "arn:aws:elasticbeanstalk:ap-northeast-1::platform/Node.js 22 running on 64bit Amazon Linux 2023/6.6.5",
"Description": "Environment created from the EB CLI using \"eb create\"",
"EndpointURL": "35.74.194.200",
"CNAME": "nodejs-dev.ap-northeast-1.elasticbeanstalk.com",
"DateCreated": "2025-09-24T02:21:33.782000+00:00",
"DateUpdated": "2025-09-24T02:35:43.236000+00:00",
"Status": "Updating",
"AbortableOperationInProgress": true,
"Health": "Grey",
"Tier": {
"Name": "WebServer",
"Type": "Standard",
"Version": "1.0"
},
"EnvironmentArn": "arn:aws:elasticbeanstalk:ap-northeast-1:012345678901:environment/nodejs/nodejs-dev"
}
コマンド実行後、Elastic Beanstalk 環境が更新されます。
再度 Auto Scaling グループの設定を確認すると、カスタムセキュリティグループが削除されていることがわかります。
この状態であれば、Elastic Beanstalk 環境で先ほどのエラーは発生せず、設定変更が可能です。
補足
update-environment コマンド実行時に Value="" とすることで、Elastic Beanstalk によって自動作成されたセキュリティグループのみが使用される状況に変更できました。
もしカスタムセキュリティグループが複数あり、そのうちの 1 つだけを削除したい場合には残したいセキュリティグループ ID を Value に指定してください。
$ aws elasticbeanstalk update-environment \
--environment-name your-environment-name \
--option-settings Namespace=aws:autoscaling:launchconfiguration,OptionName=SecurityGroups,Value="sg-xxx"