无法通过CloudFormation启动Elastic Beanstalk应用程序

时间:2019-01-24 21:25:38

标签: amazon-web-services amazon-cloudformation amazon-elastic-beanstalk

我正在尝试通过CloudFormation模板启动Elastic Beanstalk应用程序,但是我一直收到错误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.,我已经尝试了所有可以找到的解决方案,但似乎没有任何效果。另外,我无法进入已启动的EC2实例,因此我必须假定它们是相关的。与无法通过公共互联网访问有关吗?我是Elastic Beanstalk(和EC2)的新手,所以感谢您的帮助。这是我的CloudFormation模板的相关部分:

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 个答案:

答案 0 :(得分:0)

您可以将模板分为两个

  1. 运行VPC模板
  2. 启动t2.micro并测试连接性
  3. 然后运行Elasticbeanstalk模板

似乎您缺少到Internet(公共端点)的路由

还请禁用回滚并排除故障。很有可能是其连接专用子网和elasticbeanstalk服务或s3端点。