Search code examples
amazon-s3amazon-ec2amazon-cloudfrontamazon-route53

Refreshing DNS after changing s3 bucket target IP address


I have an EC2 instance with a local port 8501 hosting a website app.py.

To give access to public, I have created an S3 bucket pointing to ipaddress:port in the properties dialogue and used Route53 to point to s3 bucket.

However, when I updated my EC2 instance the IP address changed. I updated S3 target and it works for all new users, but whoever had used my website before is being redirected to old ip address.

Is it possible to point it to new IP address for old users as well without asking them to clear cache?


Solution

  • In my opinion, there are better ways to achieve what you need.

    1. Assign Elastic IP (EIP) to the instance. Elastic IP won't change if you reboot or even stop and then start your instance. If you replace the instance with another one you can just reassign the EIP to the new instance.

    2. Launch an Application Load Balancer (ALB) and attach your instance to it. ALB will take care of routing the traffic to the instance no matter what IP it has. The instance doesn't even have to have a public IP, internal IP will suffice.

    3. Consider using Elastic Beanstalk. This service will span EC2 instances and load balancer for you.