"Auto Assign public IP" 在子网上或使用 Elastic Beanstalk 启动配置

"Auto Assign public IP" on subnet- or Launch configuration using Elastic Beanstalk

如果我理解正确,则无法为云形成模板中的子网设置 属性“自动分配 Public IP”。

这可以通过 Auto Scaling 中的启动配置来完成,使 Ec2 实例以 public 个 IP 启动。

但是,据我所知,此选项不适用于使用 Cloud Formation 编写脚本时通过 Elastic Beanstalk 配置的启动配置。

AWS::ElasticBeanstalk::Environment 元素有 'OptionSettings',但只有命名空间 'aws:autoscaling:launchconfiguration' 的一个子集被传递。 看这个例子

someEnvironment:
    Type: AWS::ElasticBeanstalk::Environment
    Properties:
      ApplicationName:
        Ref: someApp
      Description: AWS Environment for my App
      TemplateName:
        Ref: myTemplate
      OptionSettings:
        - Namespace: 'aws:autoscaling:launchconfiguration'
          OptionName: IamInstanceProfile
          Value: 'arn:aws:iam::xxx:instance-profile/aws-elasticbeanstalk-ec2-role'
        - Namespace: 'aws:elasticbeanstalk:environment'
          OptionName: ServiceRole
          Value: 'aws-elasticbeanstalk-service-role'

我尝试添加 'aws:autoscaling:launchconfiguration'> AssociatePublicIpAddress / true,但模板失败,因为 属性 未知。

在 EB auto scaling 组中创建的服务器无法向 Elastic Beanstalk 服务发送 OK 信号以表明它们已启动,整个 CF 堆栈超时并在 15 分钟后回滚。

解决方法是在创建后修改 VPC。我可以这样做,因为我已经将我的 CF 脚本与导出和导入值分层。我必须在我的 public 子网上手动启用自动分配 IP。感觉很老套。

我是不是漏掉了什么?

有多种方法可以实现您的目标。

你说得对 aws:autoscaling:launchconfiguration 上没有 AssociatePublicIpAddress

aws:ec2:vpc 选项设置中有一个 AssociatePublicIpAddress。这可能是这样的:

    - Namespace: 'aws:ec2:vpc'
      OptionName: AssociatePublicIpAddress
      Value: true

因为您要在 VPC 上指定属性,您可能还需要指定 VPCIdSubnets 属性

    - Namespace: 'aws:ec2:vpc'
      OptionName: VPCId
      Value: <your vpc>
    - Namespace: 'aws:ec2:vpc'
      OptionName: Subnets
      Value: "instance_subnet, etc"

我发现在使用 ElasticBeanstalk 时不可或缺的一个资源是 General Options for All Environments 文档。它列出了 CloudFormation ElasticBeanstalk 资源、.ebextensions 和保存的配置的所有主要名称 space 和通用选项。

希望对您有所帮助。