pythonamazon-web-servicesamazon-ec2suec2-userdata

AWS EC2 user data: run python script at startup as non-root user


When my EC2 VM (Ubuntu) starts, I'd like it to execute a python script myscript.py as ec2-user instead of the default root user. This includes using the ec2-user's python executable, installed packages and binaries (e.g. chromedriver)

How can I do this?

What I did/ tried so far:

So, how can I make my user ec2-user execute myscript.py within the execution of the user data at instance startup?

references:


Solution

  • I finally solved the problem by using a cronjob with @reboot, running the desired commands at every startup