Coursera: AWS Cloud Technical Essentials - Week 3 Exercise 4 -The "employee-directory-app" is consistently refusing to connect upon restarting the instance.

0

For this task, I've successfully established a VPC, configured subnets, routes, and an internet gateway according to the outlined specifications. Despite thorough verification confirming the precise alignment of all configurations, a persistent issue persists: the application operates smoothly initially, but upon restarting the instance, it encounters a "refused to connect" error. Despite my dedicated adherence to each step outlined in the exercise, a resolution remains elusive.

I would greatly appreciate any assistance or insights to resolve this issue, particularly in understanding why this occurs specifically after I stop and restart the instance.

3 Answers
0

Hello.

Do you have an Elastic IP address configured for EC2?
If it is not set, the public IP address of EC2 will be changed when stopping and starting, so please try accessing with the changed IP address.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html

Also, check if the application is running within EC2.
You can check the HTTP status code by connecting to EC2 and running the following command.
If this is other than 200, it is possible that the web server is not running.

curl localhost -I
profile picture
EXPERT
answered 6 months ago
profile pictureAWS
EXPERT
reviewed 6 months ago
  • Hello, Thanks for replying. So, I tried running 'curl localhost -I' on my EC2 instance, but it threw this error: 'Failed to connect to localhost port 80 after 0 ms: Couldn't connect to server'. So, I double-checked my Security Group Settings and Network ACL, and there's definitely no block on port 80. Furthermore, I have not configured any firewall, eliminating it as a potential cause for this issue.

  • The web server is probably not running, so try running the command to run the application again. https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-GCNv2/exercise-3-compute.html

  • Does that mean that whenever I stop the instance, I will have to perform the steps mentioned in exercise-3 all over again to get the servers running?

  • I don't think it's necessary to recreate EC2. The application should be running by executing the following command, so I think it would be good if this command could be executed at startup.

    FLASK_APP=application.py /usr/local/bin/flask run --host=0.0.0.0 --port=80
    
  • After executing the command, I encountered a "KeyError: 'PHOTOS_BUCKET'". I had initially entered my S3 bucket name as instructed in the exercise, and it worked until I stopped the instance.

    " File "/usr/lib64/python3.9/os.py", line 679, in getitem raise KeyError(key) from None KeyError: 'PHOTOS_BUCKET' "

0

If security groups and network ACLs are correctly configured and you haven't set up a firewall, the issue might be related to the application or web server itself.

Let's take a systematic approach to diagnose the issue:

First and foremost, confirm if your web server (e.g., Apache, Nginx) is running:

  • For Apache: sudo systemctl status apache2 (or httpd on some distributions).
  • For Nginx: sudo systemctl status nginx.

If it's not running, that's likely the reason for the error. Start the server and check again.

If your web server isn't automatically starting after the instance restarts, you'll need to enable it:

  • For Apache: sudo systemctl enable apache2 (or httpd).
  • For Nginx: sudo systemctl enable nginx.

This ensures that the web server starts automatically upon reboot.

Check the web server logs for any errors. They can give clues if there's an issue with the application or server configuration.

  • For Apache: Check /var/log/apache2/error.log (this might vary based on the OS).
  • For Nginx: Check /var/log/nginx/error.log.

Port Configuration: Confirm that your web server is set up to listen on port 80:

Regards, Andrii

profile picture
EXPERT
answered 6 months ago
0

Relaunch another image from the application and it shall run immediately.

answered 5 months 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.

Guidelines for Answering Questions