Command Line In Linux (Ubuntu ) terminal you can use ec2metadata which gives the metadata of the instance, to get only the instance id you can use ec2metadata instance-id
Which will give you the instance id of your instance, You can get more metadata and user data using the CLI or HTTP call, and you are not billed for HTTP requests used to retrieve instance metadata and user data.
[
add
]
[
|
|
...
]