0

I have a service that I want to run as a python webserver. The python code generates a FASTapi webserver. When I run the code in a running EC2 instance, the code is running and generates a webserver at port 8080 which I can access.

But I want to start the webserver as soon as I start the EC2 instance.

I put the following bash script in the user data section of launch instance in AWS.

#!/bin/bash
python3 <absolute path of the python file>

But it is not running the python file and starting the webserver.

What am I doing wrong here? Is there anything I am missing? or is there any other way to achieve the same?

  • 1
    You need to check the server's `cloud-init` log to see what the actual error is. https://stackoverflow.com/questions/18691867/where-to-find-logs-for-a-cloud-init-user-data-script – Mark B Aug 15 '23 at 14:45
  • Are you sure your python script is making it onto the EC2 instance? – C.Nivs Aug 15 '23 at 14:53

1 Answers1

0

Good Greetings,

Here are a few simple things to check off from your check list to check against before you check if its working.

1} Has your Ec2 instance fully initialised before you check if the webserver is running?

  1. Are you checking locally on the webserver or remotely? It could be that the ACLs is BLOCK you from

b. Have you tried executioning the command you are trying to run via the CLI manually? It might show what catch you out

III. Try providing the absolute path for python3 such as the below example examples:

#!/bin/bash
/usr/bin/python3 /opt/home/tmp/etc/var/www/root/w3schools.py