4

My goal is to automatically assign an elastic IP to an auto-scaled EC2 instance.

I have done the following: - Configured EC2 instance w/ startup script to assign IP - Configured launch config and auto-scale group per spec.

The issue is that when deploying the auto-scaled launch config I lose the ability to allow it to automatically assign a public address (at first) before it picks up the elastic IP assignment.

When I deploy the AMI manually, provided that I check that "assign public IP address" box, the instance will deploy, temporarily assign the xxxx.amazon.xxxx address, then roll over to my elastic IP assignment.

however..

when deployed through the auto-scale command line utilities (as-create-launch-config + as-create-auto-scaling-group) the IP will not work. I feel it could be fixed if there was an option when setting up the launch config to temporarily grab a public IP in order to communicate with the amazon API to pull the elastic assignment.

I greatly appreciate your help!

dgall
  • 53
  • 1
  • 4

1 Answers1

1

You may want to use cloud-init to run a command on the local autoscaled server that attaches the EIP. Here is an example of a local command running on a server on first boot: http://cloudinit.readthedocs.org/en/latest/topics/examples.html#run-commands-on-first-boot

In that local command you could use amazon's built in tools to associate the address: http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-AssociateAddress.html

In the launch config, add that cloud-init syntax to the user-data attribute as base64 encoded and all future autoscaled instances will do exactly what the cloud-init states it will do.

I usually base64 encode by doing:

base64 <filename>
nictrix
  • 1,483
  • 1
  • 17
  • 34
  • I don't believe this will work at all. You can't reach out to the AWS API nodes until such time as you have got that EIP. – Christopher Smith Oct 18 '14 at 05:35
  • Christopher, you can call for an EIP and then assign it to the instance. I do this on a bunch of nodes already. If you need to have a reserved list of EIPs, then reserve them ahead of time and use cloud-init to assign them. – nictrix Oct 20 '14 at 02:44
  • @nicrix My mistake. It will work if you have a NAT'd VPC setup or you've somehow enabled public IP's for your instances (seems odd to do that with EIP). – Christopher Smith Dec 30 '14 at 09:45
  • @ChristopherSmith - I do this sometimes when I want to make sure DNS caching or DNS issues are not the problem for an instance that has critical services is running and available. (database server, etc...) – nictrix Dec 31 '14 at 02:40