How to shutdown from a script without being root?
Assuming you are using Linux-based instance.
Use sudo to grant your script user permission to run shutdown with root privileges.
edit your sudoers file with visudo
and put this line
scriptuser ALL = NOPASSWD: /sbin/shutdown
After that your script can shutdown machine with command /usr/bin/sudo /sbin/shutdown