- Newest
- Most votes
- Most comments
If you absolutely need the same IP address on the server, one way is to create an Elastic Network Interface and attach that as a second network interface to whatever EC2 instance is currently running. Tell SAS to use this IP address. Note though you want this to be in a different subnet to your primary network interface - if you attach two or more network interfaces from the same subnet to an instance, you may encounter networking issues such as asymmetric routing.
If that's no good, another wierd workaround I've seen is to put your autoscaling group in a small /28 subnet, and consume all addresses EXCEPT ONE with other resources (e.g. ENIs) - that will force your EC2 instance to always have the same IP as it will grab the only free one.
If by AutoScaling=1 you mean there's only ever a single instance, then you can create a Launch Template with an existing ENI on it. The ASG will only ever use that ENI when launching new instances. Since an ENI can only be on a single instance, that ASG can only ever go between 0 and 1 instances.
If your usecase is just fault tolerance (or scaling to 0 during 'off' times, and then back to 1 later), then this solution will work. If you need multiple instances, then the solutions mentioned by "skinsman" where you have a pool of secondary addresses/interfaces that are attached post launch (or a small dedicated subnet) are the only options for the instances themselves to get the same private IPs
Using ASG, how can I preserve the IP?
Is it a single instance ASG? If so, you can use an existing ENI in the launch template. That ENI will have the IP(s) associated with it, and the ENI/IP(s) will be reused each time the ASG launches a replacement instance
Relevant content
- asked 2 years ago
- Accepted Answer
- asked 6 months ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
For the weird workaround, if only a single instance is ever needed, a single pre-existing ENI can be configured on an ASG: https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-launch-template.html#change-network-interface
If I have primary and secondary pvt IP address, how can I ensure that the SAS application always used secondary pvt IP?