1
votes

If I understand things correctly, there is no way to set the property " Auto-Assign Public IP" for subnets from cloud formation templates.

This can be done from Launch configurations in Auto Scaling, making Ec2 Instances start up with public IPs.

However, this option is, AFAIK, not available for Launch Configurations configured through Elastic Beanstalk when scripted with Cloud Formation.

The AWS::ElasticBeanstalk::Environment element has 'OptionSettings', but only a subset of the namespace 'aws:autoscaling:launchconfiguration' is passed through. See this example

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'

I tried to add 'aws:autoscaling:launchconfiguration'> AssociatePublicIpAddress / true, but the template fails because the property is unknown.

The servers created in the EB auto scaling group can't signal OK back to the Elastic Beanstalk Service to say that they've started, and the whole CF stack times out and rolls back after 15 minutes.

A work around is to modify the VPC after created. I can do this because I have layered my CF scripts with export and import values. I have to manually enable the Auto Assign IP on my public Subnets. That feels hacky.

Am I missing something here?

1

1 Answers

3
votes

There are a number of possible ways to achieve what you're looking for.

You're correct that there is no AssociatePublicIpAddress on aws:autoscaling:launchconfiguration.

There is a AssociatePublicIpAddress on the aws:ec2:vpc OptionsSetting. This would likely be something like:

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

Because you're specifying properties on the VPC, you might also need to specify the VPCId and Subnets properties

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

One resource that I find indispensable when working with ElasticBeanstalk is the General Options for All Environments documentation. It lists all of the major name space and options common to CloudFormation ElasticBeanstalk resources, .ebextensions, and saved configs.

Hope that helps.