Which user launched EC2 instance?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
In the realm of cloud computing, particularly with Amazon Web Services (AWS), managing and tracking EC2 (Elastic Compute Cloud) instances becomes imperative for operational excellence, security, and cost management. One common question that arises in cloud operations is: "Which user launched a specific EC2 instance?" Understanding this requires a grasp of how AWS keeps track of user activities and how this information can be extracted and interpreted.
Understanding EC2 Instance Launch Operations
An Amazon EC2 instance is a virtual server in Amazon's Elastic Compute Cloud for running applications on the AWS infrastructure. It is key to know who launched an instance for reasons such as security audits, cost tracking, and ensuring adherence to company policies. AWS provides several services and tools that allow an administrator to trace these operations effectively.
Relevant AWS Services
- AWS CloudTrail
- CloudTrail enables governance, compliance, and operational and risk auditing of your AWS account. It logs, continuously monitors, and retains account activity related to actions across your AWS infrastructure.
- CloudTrail logs when an EC2 instance is launched, identifying the IAM (Identity and Access Management) entity that made the request.
- AWS CloudWatch
- CloudWatch collects monitoring and operational data in the form of logs, metrics, and events, providing you with a unified view of AWS resources.
- Although primarily for performance monitoring, CloudWatch can be configured to act on CloudTrail events, such as notifications for instance launches.
Steps to Identify the User
To determine which user launched an EC2 instance:
- Enable CloudTrail Logging
- Ensure that CloudTrail is enabled in your AWS environment. By default, CloudTrail logs are stored in S3 buckets, providing a history of activity in your AWS account.
- Access CloudTrail Logs
- Navigate to the CloudTrail dashboard in the AWS Management Console.
- Use the CloudTrail search feature to query logs for
RunInstances. This event is triggered whenever an EC2 instance is launched.
- Analyze Log Entries
- Examine the CloudTrail log entries for the specific event time you are interested in. Each log entry contains details about the API call, including the
eventName,eventTime, and theuserIdentityinformation. - The
userIdentitysection will tell you which IAM user or role launched the instance, as well as other details such as the sourceIPAddress and userAgent.
- AWS Lambda Functions: Automate the extraction and reporting of EC2 launch events by setting up a Lambda function that triggers based on CloudTrail logs.
- AWS SNS (Simple Notification Service): Combine with Lambda functions to notify administrators when specific events occur, such as unauthorized launches.
- Scenario: The finance department notices an unexpected cost increase in their AWS bill.
- Action: The cloud administrator queries the CloudTrail logs for
RunInstancesevents, determining that a user with the nameJohnDoelaunched several high-cost instances. - Outcome: The administrator discusses usage policies with the user, implements stricter IAM policies, and sets CloudWatch alarms to catch cost spikes early.
- Regular Audits: Make it a regular practice to audit who launches instances and for what purpose, aiding in security and budgeting.
- IAM Policies: Implement strict IAM roles and policies governing who can launch instances.
- Cost Monitoring: Utilize AWS Budgets and CloudWatch to detect anomalous usage early.

