Actually, cloud-init allows a single shell script as an input (even if you may want to use a MIME archive for complex setups).
The problem with the OP's script is that the first line is wrong. You should use something like this:
Because, while cloud-init uses #! to recognize a user script, the OS requires a complete shebang line to execute the script.
So, what's happening in the OP's case is that cloud-init behaves correctly (i.e. it downloads and tries to run the script) but the OS could not actually execute it.
If you want to learn more, check out this AWS Training Course by Intellipaat.