Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment failed to launch as it entered Terminated state

Setup
Serverless.com Framework

Goal
Create AWS Elastic Beanstalk trough serverless

Code
serverless.yml

service: aws-beanstalk-sls
description: Test stack deployment 😀

provider:
  name: aws
  stage: running
  region: eu-central-1
  profile: beanstalk-test-deployment

resources:
  Resources:
    sampleApplication:
      Type: AWS::ElasticBeanstalk::Application
      Properties:
        Description: AWS Elastic Beanstalk Sample Application

    sampleApplicationVersion:
      Type: AWS::ElasticBeanstalk::ApplicationVersion
      Properties:
        ApplicationName:
          Ref: sampleApplication
        Description: AWS ElasticBeanstalk Sample Application Version
        SourceBundle:
          S3Bucket: elasticbeanstalk-samples-eu-central-1
          S3Key: nodejs-sample.zip

    sampleConfigurationTemplate:
      Type: AWS::ElasticBeanstalk::ConfigurationTemplate
      Properties:
        SolutionStackName: 64bit Amazon Linux 2018.03 v4.7.0 running Node.js
        Description: AWS ElasticBeanstalk Sample Configuration Template
        ApplicationName:
          Ref: sampleApplication
        OptionSettings:
        - Namespace: aws:autoscaling:asg
          OptionName: MinSize
          Value: '2'
        - Namespace: aws:autoscaling:asg
          OptionName: MaxSize
          Value: '6'
        - Namespace: aws:elasticbeanstalk:environment
          OptionName: EnvironmentType
          Value: LoadBalanced

    sampleEnvironment:
      Type: AWS::ElasticBeanstalk::Environment
      Properties:
        ApplicationName:
          Ref: sampleApplication
        Description: AWS ElasticBeanstalk Sample Environment
        TemplateName:
          Ref: sampleConfigurationTemplate
        VersionLabel:
          Ref: sampleApplicationVersion

Error
An error occurred: sampleEnvironment - Environment failed to launch as it entered Terminated state.

Note
The profile beanstalk-test-deployment has already the IAM roles:

  • AWSElasticBeanstalkFullAccess
  • AdministratorAccess
like image 892
Christopher Avatar asked Nov 20 '18 11:11

Christopher


1 Answers

You need to create the aws-elasticbeanstalk-ec2-role AWS::IAM::InstanceProfile and provide it in the sampleConfigurationTemplate's OptionSettings:

- Namespace: aws:autoscaling:launchconfiguration
  OptionName: IamInstanceProfile
  Value: aws-elasticbeanstalk-ec2-role

The role can use these Managed Policy Arns:

- arn:aws:iam::aws:policy/AWSElasticBeanstalkWebTier
- arn:aws:iam::aws:policy/AWSElasticBeanstalkWorkerTier
- arn:aws:iam::aws:policy/AWSElasticBeanstalkMulticontainerDocker

If adding this role doesn't help, the error could also indicate a failing .ebextensions. I once got this error by calling a nonexistent KeyName in ebextensions.

like image 166
SeanFromIT Avatar answered Nov 19 '22 13:11

SeanFromIT