0
votes

I'm trying to launch an Elastic Beanstalk application through a CloudFormation template but I keep receiving the error The EC2 instances failed to communicate with AWS Elastic Beanstalk, either because of configuration problems with the VPC or a failed EC2 instance. Check your VPC configuration and try launching the environment again. I've tried all of the solutions I can find for this but nothing seems to be working. Additionally, I'm unable to ssh into the EC2 instances that are launched, so I have to assume those are related. Is it something to do with not being accessible through the public internet? I'm new to Elastic Beanstalk (and EC2) so any help is appreciated. Here's the relevant portion of my CloudFormation template:

Resources:

  # VPC and Subnets
  Vpc:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      EnableDnsSupport: true
      EnableDnsHostnames: true
      InstanceTenancy: default
      Tags:
      - Key: Name
        Value: !Sub "ClimbAssistVpc${ResourceNameSuffix}"
  InternetGateway:
    Type: AWS::EC2::InternetGateway
  VpcGatewayAttachment:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      InternetGatewayId: !Ref InternetGateway
      VpcId: !Ref Vpc
  SubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: us-west-2a
      CidrBlock: 10.0.0.0/17
      MapPublicIpOnLaunch: true
      VpcId: !Ref Vpc
  SubnetB:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: us-west-2b
      CidrBlock: 10.0.128.0/18
      MapPublicIpOnLaunch: true
      VpcId: !Ref Vpc
  SubnetC:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: us-west-2c
      CidrBlock: 10.0.192.0/18
      MapPublicIpOnLaunch: true
      VpcId: !Ref Vpc
  SecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: 'Security group for Climb Assist Elastic Beanstalk application'
      SecurityGroupIngress:
      - CidrIp: '0.0.0.0/0'
        IpProtocol: tcp
        FromPort: 80
        ToPort: 80
      - CidrIp: '0.0.0.0/0'
        IpProtocol: tcp
        FromPort: 22
        ToPort: 22
      SecurityGroupEgress:
      - CidrIp: '0.0.0.0/0'
        IpProtocol: -1 # all protocols
        ToPort: 0
        FromPort: 65535
      VpcId: !Ref Vpc

  # Elastic Beanstalk environments
  EBApplication:
    Description: The AWS Elastic Beanstalk application, which is a container used to deploy the correct application configuration.
    Type: AWS::ElasticBeanstalk::Application
    Properties:
      ApplicationName: !Sub '${ProjectId}app${ResourceNameSuffix}'
      Description: The name of the AWS Elastic Beanstalk application to be created for this project.
  EBApplicationVersion:
    Description: The version of the AWS Elastic Beanstalk application to be created for this project.
    Type: AWS::ElasticBeanstalk::ApplicationVersion
    Properties:
      ApplicationName: !Ref 'EBApplication'
      Description: The application version number.
      SourceBundle: 'target/ROOT'
  EBConfigurationTemplate:
    Description: The AWS Elastic Beanstalk configuration template to be created for this project, which defines configuration settings used to deploy different versions of an application.
    Type: AWS::ElasticBeanstalk::ConfigurationTemplate
    Properties:
      ApplicationName: !Ref 'EBApplication'
      Description: The name of the sample configuration template.
      OptionSettings:
      - Namespace: aws:elasticbeanstalk:environment
        OptionName: EnvironmentType
        Value: LoadBalanced
      - Namespace: aws:elasticbeanstalk:environment
        OptionName: ServiceRole
        Value: !Ref 'EBTrustRole'
      - Namespace: aws:elasticbeanstalk:healthreporting:system
        OptionName: SystemType
        Value: enhanced
      SolutionStackName: !Ref 'SolutionStackName'
  EBEnvironment:
    Description: The AWS Elastic Beanstalk deployment group where the application is deployed, which is made up of the Amazon EC2 Linux instances launched for this project.
    Type: AWS::ElasticBeanstalk::Environment
    Properties:
      ApplicationName: !Ref 'EBApplication'
      EnvironmentName: !Ref 'EBApplication'
      Description: The application to be deployed to the environment.
      TemplateName: !Ref 'EBConfigurationTemplate'
      VersionLabel: !Ref 'EBApplicationVersion'
      OptionSettings:
      - Namespace: aws:autoscaling:launchconfiguration
        OptionName: IamInstanceProfile
        Value: !Ref 'EBInstanceProfile'
      - Namespace: aws:autoscaling:launchconfiguration
        OptionName: InstanceType
        Value: !Ref 'InstanceType'
      - Namespace: aws:autoscaling:launchconfiguration
        OptionName: EC2KeyName
        Value: !Ref 'KeyPairName'
      - Namespace: aws:ec2:vpc
        OptionName: VPCId
        Value: !Ref Vpc
      - Namespace: 'aws:ec2:vpc'
        OptionName: Subnets
        Value:
          Fn::Join:
          - ','
          - - !Ref SubnetA
            - !Ref SubnetB
            - !Ref SubnetC
      - Namespace: 'aws:autoscaling:launchconfiguration'
        OptionName: SecurityGroups
        Value: !Ref SecurityGroup
      - Namespace: 'aws:ec2:vpc'
        OptionName: AssociatePublicIpAddress
        Value: 'true'
1

1 Answers

0
votes

Can you break down your template into two

  1. Run the VPC template
  2. launch a t2.micro and test connectivity
  3. then run the Elasticbeanstalk template

Seems like you are missing routing to internet( public endpoints)

Also please disable rollback and troubleshoot failures. Most likely its connectivity private subnets and elasticbeanstalk services or s3 endpoint.