In aws.amazon in the instance control panel, you can change your elastic (public) IP and connect it to your instance.

How can you implement it programmatically?

Linux Ubuntu system