ottijp blog

デフォルトサブネットが無い状態でElastic BeanstalkのEnvironmentをebコマンドで作ると失敗する

TL;DR

  • デフォルトサブネットが無いと,eb createが失敗する.
  • 失敗した場合は,1時間くらい待つと作成処理がabortされるので,その後eb terminateで削除できるようになる.
  • デフォルトサブネットを作ってから再度eb createを実行すると正常に作成できた.

詳細

Elastic Beanstalkの勉強のため,以下のページを見ながらebコマンドでEnvironmentを新規に作ってみました.

cf. Deploying an Express application to Elastic Beanstalk - AWS Elastic Beanstalk

すると,コマンド実行後に表示されるログがエラーを吐いて止まりました.

$ eb create --sample
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
Enter Environment Name
(default is <application_name>-dev):
Enter DNS CNAME prefix
(default is <application_name>-dev):
WARNING: Git is in a detached head state. Using branch "default".

Select a load balancer type
1) classic
2) application
3) network
(default is 2): 2


Would you like to enable Spot Fleet requests for this environment? (y/N): n
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
Environment details for: <application_name>-dev
  Application name: <application_name>
  Region: ap-northeast-1
  Deployed Version: Sample Application
  Environment ID: e-n5kpwpypzy
  Platform: arn:aws:elasticbeanstalk:ap-northeast-1::platform/Node.js 14 running on 64bit Amazon Linux 2/5.4.10
  Tier: WebServer-Standard-1.0
  CNAME: <application_name>-dev.ap-northeast-1.elasticbeanstalk.com
  Updated: 2022-02-11 08:40:34.050000+00:00
Printing Status:
2022-02-11 07:26:11    INFO    createEnvironment is starting.
2022-02-11 07:26:12    INFO    Using elasticbeanstalk-ap-northeast-1-<account_id> as Amazon S3 storage bucket for environment data.
2022-02-11 07:26:19    INFO    Environment health has transitioned to Pending. Initialization in progress (running for 3 seconds). There are no instances.
2022-02-11 07:26:35    INFO    Created target group named: arn:aws:elasticloadbalancing:ap-northeast-1:<account_id>:targetgroup/awseb-AWSEB-GYF0QFB0UUGT/9005206aafb4fa6d
2022-02-11 07:26:35    INFO    Created security group named: sg-00497d473a78770e0
2022-02-11 07:26:35    ERROR   Creating load balancer failed Reason: At least two subnets in two different Availability Zones must be specified (Service: AmazonElasticLoadBalancing; Status Code: 400; Error Code: ValidationError; Request ID: 058a7e1c-fd1a-4ca3-9be5-6cdb8058138b; Proxy: null)
2022-02-11 07:26:51    INFO    Created security group named: awseb-e-ghhmpzgmsy-stack-AWSEBSecurityGroup-7PNVK7XIL1P1
2022-02-11 07:26:51    INFO    Created Auto Scaling launch configuration named: awseb-e-ghhmpzgmsy-stack-AWSEBAutoScalingLaunchConfiguration-aAnqLF2fa1vO
2022-02-11 07:42:18    INFO    Environment health has transitioned from Pending to No Data. Initialization in progress (running for 16 minutes). There are no instances.

ERROR: TimeoutError - The EB CLI timed out after 10 minute(s). The operation might still be running. To keep viewing events, run 'eb events -f'. To set timeout duration, use '--timeout MINUTES'.

このときマネジメントコンソール上では,EnvironmentのHealthという項目がPendingのままになっていて,そのうちNo Dataになりました. EC2インスタンスは立ち上がっておらず,ALBも作成されていませんでした.

一度作り直そうとしてEnvironmentを消そうとしても消せませんでした.

$ eb terminate <application_name>-dev
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
The environment "<application_name>-dev" and all associated instances will be terminated.
To confirm, type the environment name: <application_name>-dev
ERROR: InvalidParameterValueError - Cannot terminate environment named <application_name>-dev. It is currently pending creation.

作成されたAuto Scaling GroupのActivityを見ると,次のようなエラーが出続けていました.

  • Status: Failed
  • Description: Launching a new EC2 instance. Status Reason: No default subnet for availability zone: ‘ap-northeast-1c’. Launching EC2 instance failed.
  • Cause: At 2022-02-11T07:58:12Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 1.

ここで,どうやらAZにデフォルトのサブネットが無いのが原因らしいということに気づき,作成しました. (昔,VPCを整理しようとした時に消してしまったような気がします.)

$ aws ec2 create-default-subnet --availability-zone ap-northeast-1a
$ aws ec2 create-default-subnet --availability-zone ap-northeast-1c

cf. デフォルト VPC とデフォルトサブネット - Amazon Virtual Private Cloud

その後,しばらく待っていると,Auto Scaling Groupでインスタンスが作成されるようになりました. しかし,この時点でBeanstalkのイベントを見ると,すでに作成がabortになっており,ALBは作成されませんでした. abortされた後であればeb terminateでEnvironmentを削除できました.

$ eb events -f
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
2022-02-11 07:26:11    INFO    createEnvironment is starting.
2022-02-11 07:26:12    INFO    Using elasticbeanstalk-ap-northeast-1-<account_id> as Amazon S3 storage bucket for environment data.
2022-02-11 07:26:19    INFO    Environment health has transitioned to Pending. Initialization in progress (running for 3 seconds). There are no instances.
2022-02-11 07:26:35    INFO    Created target group named: arn:aws:elasticloadbalancing:ap-northeast-1:<account_id>:targetgroup/awseb-AWSEB-GYF0QFB0UUGT/9005206aafb4fa6d
2022-02-11 07:26:35    INFO    Created security group named: sg-00497d473a78770e0
2022-02-11 07:26:35    ERROR   Creating load balancer failed Reason: At least two subnets in two different Availability Zones must be specified (Service: AmazonElasticLoadBalancing; Status Code: 400; Error Code: ValidationError; Request ID: 058a7e1c-fd1a-4ca3-9be5-6cdb8058138b; Proxy: null)
2022-02-11 07:26:51    INFO    Created security group named: awseb-e-ghhmpzgmsy-stack-AWSEBSecurityGroup-7PNVK7XIL1P1
2022-02-11 07:26:51    INFO    Created Auto Scaling launch configuration named: awseb-e-ghhmpzgmsy-stack-AWSEBAutoScalingLaunchConfiguration-aAnqLF2fa1vO
2022-02-11 07:42:18    INFO    Environment health has transitioned from Pending to No Data. Initialization in progress (running for 16 minutes). There are no instances.
2022-02-11 08:28:41    ERROR   Stack named 'awseb-e-ghhmpzgmsy-stack' aborted operation. Current state: 'CREATE_FAILED'  Reason: The following resource(s) failed to create: [AWSEBV2LoadBalancer, AWSEBAutoScalingGroup].
2022-02-11 08:28:41    ERROR   Creating Auto Scaling group named: awseb-e-ghhmpzgmsy-stack-AWSEBAutoScalingGroup-1TZF7PEUNBITF failed. Reason: Group did not stabilize. {current/minSize/maxSize} group size = {0/1/4}. Failed Scaling Activity: No default subnet for availability zone: 'ap-northeast-1c'. Launching EC2 instance failed.
2022-02-11 08:28:43    INFO    Launched environment: <application_name>-dev. However, there were issues during launch. See event log for details.
2022-02-11 08:32:16    INFO    Added instance [i-092390fe986d71d7d] to your environment.
2022-02-11 08:32:16    INFO    Environment health has transitioned from No Data to Info. Initialization in progress. 1 out of 1 instance completed (running for 1 hour 5 minutes).

$ eb terminate <application_name>-dev
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
The environment "<application_name>-dev" and all associated instances will be terminated.
To confirm, type the environment name: <application_name>-dev
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
2022-02-11 08:34:47    INFO    terminateEnvironment is starting.
2022-02-11 08:35:05    INFO    Waiting for EC2 instances to terminate. This may take a few minutes.
2022-02-11 08:37:38    INFO    Deleted Auto Scaling group named: awseb-e-ghhmpzgmsy-stack-AWSEBAutoScalingGroup-1TZF7PEUNBITF
2022-02-11 08:37:38    INFO    Deleted target group named: arn:aws:elasticloadbalancing:ap-northeast-1:<account_id>:targetgroup/awseb-AWSEB-GYF0QFB0UUGT/9005206aafb4fa6d
2022-02-11 08:37:38    INFO    Deleted Auto Scaling launch configuration named: awseb-e-ghhmpzgmsy-stack-AWSEBAutoScalingLaunchConfiguration-aAnqLF2fa1vO
2022-02-11 08:37:38    INFO    Deleted security group named: awseb-e-ghhmpzgmsy-stack-AWSEBSecurityGroup-7PNVK7XIL1P1
2022-02-11 08:37:38    INFO    Deleted security group named: sg-00497d473a78770e0
2022-02-11 08:37:41    INFO    Deleting SNS topic for environment <application_name>-dev.
2022-02-11 08:37:42    INFO    terminateEnvironment completed successfully.

そして,改めてeb createをしたところ,正常に作成できました.

$ eb create --sample
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
Enter Environment Name
(default is <application_name>-dev):
Enter DNS CNAME prefix
(default is <application_name>-dev):
WARNING: Git is in a detached head state. Using branch "default".

Select a load balancer type
1) classic
2) application
3) network
(default is 2): 2


Would you like to enable Spot Fleet requests for this environment? (y/N): n
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
WARNING: Git is in a detached head state. Using branch "default".
Environment details for: <application_name>-dev
  Application name: <application_name>
  Region: ap-northeast-1
  Deployed Version: Sample Application
  Environment ID: e-n5kpwpypzy
  Platform: arn:aws:elasticbeanstalk:ap-northeast-1::platform/Node.js 14 running on 64bit Amazon Linux 2/5.4.10
  Tier: WebServer-Standard-1.0
  CNAME: <application_name>-dev.ap-northeast-1.elasticbeanstalk.com
  Updated: 2022-02-11 08:40:34.050000+00:00
Printing Status:
2022-02-11 08:40:32    INFO    createEnvironment is starting.
2022-02-11 08:40:34    INFO    Using elasticbeanstalk-ap-northeast-1-<account_id> as Amazon S3 storage bucket for environment data.
2022-02-11 08:40:58    INFO    Created target group named: arn:aws:elasticloadbalancing:ap-northeast-1:<account_id>:targetgroup/awseb-AWSEB-BI5EM2UIEA06/8a6dbed5f41efaee
2022-02-11 08:40:58    INFO    Created security group named: sg-0960e7e907d88c047
2022-02-11 08:41:13    INFO    Created security group named: awseb-e-n5kpwpypzy-stack-AWSEBSecurityGroup-10SKU7R7488A0
2022-02-11 08:41:14    INFO    Created Auto Scaling launch configuration named: awseb-e-n5kpwpypzy-stack-AWSEBAutoScalingLaunchConfiguration-QYxEp3V1mG1J
2022-02-11 08:42:15    INFO    Created Auto Scaling group named: awseb-e-n5kpwpypzy-stack-AWSEBAutoScalingGroup-1D3XZ3M6V8F3Y
2022-02-11 08:42:16    INFO    Waiting for EC2 instances to launch. This may take a few minutes.
2022-02-11 08:42:16    INFO    Created Auto Scaling group policy named: arn:aws:autoscaling:ap-northeast-1:<account_id>:scalingPolicy:164ab4f7-777c-42d3-8cb0-7995d4c9dc10:autoScalingGroupName/awseb-e-n5kpwpypzy-stack-AWSEBAutoScalingGroup-1D3XZ3M6V8F3Y:policyName/awseb-e-n5kpwpypzy-stack-AWSEBAutoScalingScaleDownPolicy-1OZ0JBFK2VUB
2022-02-11 08:42:16    INFO    Created Auto Scaling group policy named: arn:aws:autoscaling:ap-northeast-1:<account_id>:scalingPolicy:ba3f4ce8-3cb1-408d-8f42-ffad21eca29d:autoScalingGroupName/awseb-e-n5kpwpypzy-stack-AWSEBAutoScalingGroup-1D3XZ3M6V8F3Y:policyName/awseb-e-n5kpwpypzy-stack-AWSEBAutoScalingScaleUpPolicy-7OWPX5CT7OKD
2022-02-11 08:42:16    INFO    Created CloudWatch alarm named: awseb-e-n5kpwpypzy-stack-AWSEBCloudwatchAlarmLow-19DHAPX0T81YR
2022-02-11 08:42:31    INFO    Created CloudWatch alarm named: awseb-e-n5kpwpypzy-stack-AWSEBCloudwatchAlarmHigh-12UN0FPD79XHR
2022-02-11 08:43:06    INFO    Created load balancer named: arn:aws:elasticloadbalancing:ap-northeast-1:<account_id>:loadbalancer/app/awseb-AWSEB-UNC9A5KGQ928/6137067f86442d8e
2022-02-11 08:43:06    INFO    Created Load Balancer listener named: arn:aws:elasticloadbalancing:ap-northeast-1:<account_id>:listener/app/awseb-AWSEB-UNC9A5KGQ928/6137067f86442d8e/d4d93789d8054932
2022-02-11 08:43:25    INFO    Instance deployment: You didn't specify a Node.js version in the 'package.json' file in your source bundle. The deployment didn't install a specific Node.js version.
2022-02-11 08:43:30    INFO    Instance deployment completed successfully.
2022-02-11 08:43:46    INFO    Application available at <application_name>-dev.ap-northeast-1.elasticbeanstalk.com.
2022-02-11 08:43:47    INFO    Successfully launched environment: <application_name>-dev

ottijp
都内でアプリケーションエンジニアをしています
© 2024, ottijp