问题
I have some EC2 instances that I don't really know who launched them.
Is there a way to know who launched a specific instance?
回答1:
Unfortunately this information is not directly available via an API call - you currently have two options:
- depending on your needs, you could approximate your goal by using the DescribeInstances API action to look at the
key-name
used for starting that instance (if any, it's optional, though usually in place) - assuming you have followed security best practices and are using a dedicated EC2 key pair per IAM user (rather than sharing keys), the key should usually denote the user who started the instance ;)- that's most easily tested via the AWS Command Line Interface, specifically describe-instances
- nowadays you could activate AWS CloudTrail, which records AWS API calls for your account and delivers log files to you and provides exactly the information you are after:
The recorded information includes the identity of the API caller, the time of the API call, the source IP address of the API caller, the request parameters, and the response elements returned by the AWS service.
- most importantly, it isn't available in all regions yet, but AWS has just extended it to 3 more for a total of 5, see AWS CloudTrail Expands Again - More Locations and Services, thus quickly approaching coverage of their entire Global Infrastructure
- not all services are covered yet, but AWS hast just extended it to 7 more for a total of 15, see AWS CloudTrail Update - Seven New Services
- depending on your needs, you most likely want to have a Logging as a Service (LaaS) solution in place to ease digging through the vast amount of logs, and provide alerts etc. - several providers already offer dedicated CloudTrail integration (and usually a free tier sufficient for that as well)
- events are delivered within 15 minutes of the API call and the resulting logs to your S3 bucket approximately every 5 minutes, resulting in a maximum delay of 20 minutes, which is enough for post hoc and batch analysis, but not sufficient for near real-time alerting of course (see the AWS CloudTrail FAQ)
回答2:
Expanding on Steffen Opel's Answer about Logging as a Service: You can use either a third-party service to visualize CloudTrail data or setup your own solution.
Amazon Parters will help you find such a service. If you want to go build your own solution around this then this TrailDash can help you as well.
来源:https://stackoverflow.com/questions/23489381/which-user-launched-ec2-instance