I recently created an AWS EC2 Instance and it had an IP address like 3.144.nnn.nnn
.
I used that IP address for an application as my IP address and there is no way I can change it. After stop and start of Instance, I get a random IP address.
Then I found I can allocate static IP address with Elastic IP address.
However, when I try to allocate the Elastic IP it also generates random IP, so I tried this with the AWS CLI:
aws ec2 allocate-address --address 3.144.nnn.nnn --domain vpc
(with the same IP above)
But it returns an error:
An error occurred (InvalidAddress.NotFound)
when calling the AllocateAddress operation:
The Elastic IP address '3.131.nnn.nnn' does not exist or is not available.
I tried with several IPs with the same range( for test purposes). However, it returns the same error.
If you want a fixed public IP you need to create an Elastic IP address and check what IP is assigned to it and then you can use that IP. You cannot choose the IP that is assigned to the Elastic IP address.
Also note if you release the Elastic IP address it will cost money if you do not have it assigned to an instance. If you delete the Elastic IP address chances of getting an Elastic IP address with the same IP is slim to none.