I had a project where I need to run a command at EC2 reboot. I found only information about User Data but that works only at first launch which is not exactly what I needed. I need a command to run everytime I connect to the machine.
About linux : How-to-run-a-command-at-EC2-Instance-RE-boot
You can store a shell script in this directory:
It will be automatically run after every boot. (This is done by
cloud-init, which also runs User Data scripts.)
After a little bit of research, I found a very easy solution. You can simply run.
echo "YOUR_COMMAND" >> .bashrc
This works also if you write it in the User Data section when launching your EC2 instance so that you don’t have to SSH into it after launch.