Select Language:
Setting up an Auto Scaling group with one instance having an Elastic IP (EIP) and other instances using standard public IPs can be achieved by following a few straightforward steps.
First, create a launch template that includes all your application needs. This template will be used to launch your instances automatically. Make sure to set the minimum size of your Auto Scaling group to at least one, so there’s always one instance running.
Once the first instance starts, you’ll want to attach an Elastic IP to it. To do this, use the AWS command-line interface to attach the instance to your Auto Scaling group:
bash
aws autoscaling attach-instances –instance-ids i-yourinstanceid –auto-scaling-group-name your-asg-name
After attaching the instance, associate your Elastic IP with this specific instance. This gives the instance a permanent public IP that doesn’t change, making it suitable for services that require a consistent address.
For any new instances that launch afterward, automatically assign public IPs through your launch template or configuration. This way, every time your Auto Scaling group scales out, new instances will receive regular public IPs automatically.
To keep this setup in place during scaling events, consider adding a lifecycle hook or user data script. These can check if the instance is the first one in the group — if it isn’t, the instance proceeds with a normal public IP assignment. You may also want to implement instance protection for the EIP-attached instance to prevent it from being terminated during scale-in events, ensuring your static IP setup remains stable.
With this approach, you’ll have one stable, static Elastic IP for critical services while other instances scale freely with dynamic public IPs. This flexibility helps you manage your network addresses efficiently without disrupting your operations.
Sources for more details include the official AWS documentation on detaching and attaching instances in an Auto Scaling group and how to create Auto Scaling groups via SDKs or CLI.





