Log Amazon EC2 API calls using AWS CloudTrail - Amazon Elastic Compute Cloud

Log Amazon EC2 API calls using AWS CloudTrail

Important

As a result of changes to the Amazon EC2 API AWS CloudTrail event logging behavior, you might notice an increased number of events logged for Amazon EC2 Describe* API requests that are made by AWS services on your behalf. For more information, contact AWS Support.

The Amazon EC2 API is integrated with AWS CloudTrail, a service that provides a record of actions taken by a user, role, or an AWS service. CloudTrail captures API calls for Amazon EC2 as events, including calls from the console and from code calls to the API operations. Using the information collected by CloudTrail, you can determine the request that was made to the Amazon EC2 API, the IP address from which the request was made, when it was made, and additional details.

To learn more about CloudTrail, see the AWS CloudTrail User Guide.

Amazon EC2 API information in CloudTrail

CloudTrail is enabled on your AWS account when you create the account. When activity occurs in Amazon EC2, Amazon EBS, and Amazon VPC, that activity is recorded in a CloudTrail event along with other AWS service events in Event history. You can view, search, and download recent events in your AWS account. For more information, see Viewing Events with CloudTrail Event History.

For an ongoing record of events in your AWS account, including events for Amazon EC2, Amazon EBS, and Amazon VPC, create a trail. A trail enables CloudTrail to deliver log files to an Amazon S3 bucket. By default, when you create a trail in the console, the trail applies to all Regions. The trail logs events from all Regions in the AWS partition and delivers the log files to the Amazon S3 bucket that you specify. Additionally, you can configure other AWS services to further analyze and act upon the event data collected in CloudTrail logs. For more information, see:

All Amazon EC2, Amazon EBS, and Amazon VPC actions are logged by CloudTrail and are documented in the Amazon EC2 API Reference. For example, calls to the RunInstances, DescribeInstances, or CreateImage actions generate entries in the CloudTrail log files.

Every event or log entry contains information about who generated the request. The identity information helps you determine the following:

  • Whether the request was made with root or user credentials.

  • Whether the request was made with temporary security credentials.

  • Whether the request was made by another AWS service.

For more information, see the CloudTrail userIdentity Element.

Understand Amazon EC2 API log file entries

A trail is a configuration that enables delivery of events as log files to an Amazon S3 bucket that you specify. CloudTrail log files contain one or more log entries. An event represents a single request from any source and includes information about the requested action, the date and time of the action, request parameters, and so on. CloudTrail log files are not an ordered stack trace of the public API calls, so they do not appear in any specific order.

The following log file record shows that a user terminated an instance.

{ "Records":[ { "eventVersion":"1.03", "userIdentity":{ "type":"Root", "principalId":"123456789012", "arn":"arn:aws:iam::123456789012:root", "accountId":"123456789012", "accessKeyId":"AKIAIOSFODNN7EXAMPLE", "userName":"user" }, "eventTime":"2016-05-20T08:27:45Z", "eventSource":"ec2.amazonaws.com", "eventName":"TerminateInstances", "awsRegion":"us-west-2", "sourceIPAddress":"198.51.100.1", "userAgent":"aws-cli/1.10.10 Python/2.7.9 Windows/7botocore/1.4.1", "requestParameters":{ "instancesSet":{ "items":[{ "instanceId":"i-1a2b3c4d" }] } }, "responseElements":{ "instancesSet":{ "items":[{ "instanceId":"i-1a2b3c4d", "currentState":{ "code":32, "name":"shutting-down" }, "previousState":{ "code":16, "name":"running" } }] } }, "requestID":"be112233-1ba5-4ae0-8e2b-1c302EXAMPLE", "eventID":"6e12345-2a4e-417c-aa78-7594fEXAMPLE", "eventType":"AwsApiCall", "recipientAccountId":"123456789012" } ] }