While creating new AWS EC2 instance using EC2 command line API, i am passing some user data to new instance.
Now how i came to know whether that user data executed or no
Eric Hammond suggests:
Enable logging for your user data
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
Take care to put a space between the two > > characters at the beginning of the statement.
Here’s a complete user-data script as an example:
#!/bin/bash -ex
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
echo BEGIN
date '+%Y-%m-%d %H:%M:%S'
echo END
Source: Logging user-data Script Output on EC2 Instances (2010, Hammond)