Skip to content

Issue with EC2 while sending request

0

Hello, I have created a flask server as an image and am running it on ec2. So initially, I was getting response on postman and on my UI. But then I stopped my instance and started it again. Now I am getting response on postman but am not getting response on my UI it gives error on preflight itself and then cors related error but before stopping the instance it was working fine why is this happening.

Help!!!!

asked 2 years ago238 views
2 Answers
0

Do you work directly with EC2 or Load Balancer? If you use public IP of EC2, and don't use ElasticIP, your IP will be different after you stop and start the instance.

AWS
answered 2 years ago
  • Hi, I am using just the EC2 instance. And I am changing the public IP address for the get and post requests. As I mentioned in my question I am getting the response on postman but only on my front end I and seeing this issue and I assure you that I am correcting the IP address in my js code.

0

Hi Nithin Check these steps to resolve issue

It sounds like you're encountering a CORS (Cross-Origin Resource Sharing) issue after restarting your EC2 instance. When you restart your instance, the public IP address might change unless you have an Elastic IP associated with it. Here are some steps to troubleshoot and resolve this issue:

  • Check EC2 Public IP: Ensure your instance's public IP hasn't changed. If it has, update your UI and configurations accordingly.

  • Verify CORS Settings: Ensure your Flask server has the correct CORS settings. Use the flask-cors library to allow requests from your UI's domain.

  • Security Group Rules: Ensure your EC2 security group allows inbound traffic on the required port (e.g., port 5000 for Flask).

  • Handle Preflight Requests: Make sure your server correctly handles OPTIONS requests for preflight checks.

  • Consider Elastic IP: Associate an Elastic IP with your EC2 instance to avoid IP changes upon restart.

EXPERT
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.