The user-data is not run as a script unless the first two characters are #!
Try adding the following as the first line of the user-data so that CloudInit knows to run it as a shell script:
#!/bin/sh
As Rico points out, you can drop the sudo
because user-data scripts are run as root on the first boot of the instance.
Also, the sleep 30
and cd /data/
are not providing any benefit if this is the entirety of the user-data script.
This would result in code like:
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/sh\n",
"yum update -y\n",
"mkdir /data \n",
]]}}
You could add the cd
back in if there are further statements you are adding to the user-data script.