How can I find out the email address I used to create an EC2/lightsail instance through SSH?
-
The AWS account email address? EC2 instances by itself don't have email addresses. – Marcin Nov 12 '20 at 09:20
-
From what I've looked in the docs, you don't *need* an email address to create a lightsail (or EC2) instance, and there's nothing about it in the output for describing instances as far as I can tell. Is this a tag you use on your own environment? or is it that your IAM user account is setup with your email as username? do you have CloudTrail active? – Oscar De León Nov 13 '20 at 08:15
2 Answers
Firstly their may not always be an email as others has said. As to call AWS APIs you need to be able to assume a role which has the ability to call ec2:RunInstances
. If for example you granted this role to an Lambda
function, that Lambda could indeed create a new ec2 instance, but it's not like it has an email.
Using Tags
What you want to see is who called ec2:RunInstances
for that ec2 instance. If you have enabled Cost Allocation tags you could use the aws:createdBy
tag, as described here. To access the tags in the instance, you first need the id, and then query for the tags:
instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
aws ec2 describe-tags \
--filters "Name=resource-id,Values=$instance_id" 'Name=key,Values=aws:createdBy' \
--query 'Tags[].Value' --output text
CloudTrail
If you weren't in the instance, you could search for events of name RunInstances
and find where responseElements.instanceSet.items[].instanceId == 'YOUR INSTANCE ID'
. This can be done in AWS Config I as well I believe, if you have enabled it for your instance from created at date.

- 7,651
- 5
- 30
- 60
Not sure if we can get email id, but we would be definitely able to get the accountid using the below command on the EC2 instance. AWS might not be allowing to get the email address fo the sake of security.
curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i accountid

- 32,799
- 16
- 80
- 117