You can actually set that up in userdata within the launch configuration. Some AMI's have cloudinit and will execute userdata automatically, but otherwise you can bake something into the AMI that will check the instance metadata for userdata.
More information about Cloudinit: https://help.ubuntu.com/community/CloudInit