Using the ubuntu ec2 images from canonical you can have user data execute as a script. Simply start the data with a #!. If you want to log what happens you can log to a file at the start of your script.
#!/bin/bash exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 apt-get update apt-get -y install build-essential
Or can go to syslog with the appropriate logger command.