what user does userdata run as?
EC2 User Data scripts run as
root (the root user) by default on Linux instances, so you generally don't need to use sudo inside the User Data script