Amazon Elastic Compute Cloud
API Reference (API Version 2016-11-15)

Logging API Calls Using AWS CloudTrail

Amazon EC2, Amazon EBS, and Amazon VPC are integrated with AWS CloudTrail, a service that captures API calls and delivers the log files to an Amazon S3 bucket that you specify. The API calls can be made indirectly by using the console, or directly by using a client such as the Amazon EC2 CLI, the AWS CLI, or the AWS SDKs. Using the information collected by CloudTrail, you can determine what request was made, the source IP address from which the request was made, who made the request, when it was made, and so on. To learn more about CloudTrail, including how to configure and enable it, see the AWS CloudTrail User Guide.

Amazon EC2, Amazon EBS, and Amazon VPC Information in CloudTrail

When CloudTrail logging is enabled, calls made to Amazon EC2, Amazon EBS, and Amazon VPC actions are tracked in log files, along with any other AWS service records. CloudTrail determines when to create and write to a new file based on a specified time period and file size.

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

As a security best practice, AWS does not log certain parameters; for example, any user data that's specified in a RunInstances request. The relevant values may be excluded completely or returned as <sensitiveDataRemoved> in the log entry. User data is not logged because it could expose potentially sensitive information, such as a user password.

Every log entry contains information about who generated the request. The user identity information in the log helps you determine whether the request was made with root or IAM user credentials, with temporary security credentials for a role or federated user, or by another AWS service. For more information, see the userIdentity element topic in the CloudTrail Event Reference.

You can store your log files in your bucket for as long as you want, but you can also define Amazon S3 lifecycle rules to archive or delete log files automatically. By default, your log files are encrypted by using Amazon S3 server-side encryption (SSE).

You can choose to have CloudTrail publish Amazon SNS notifications when new log files are delivered if you want to take quick action upon log file delivery. For more information, see Configuring Amazon SNS Notifications.

You can also aggregate Amazon EC2, Amazon EBS, and Amazon VPC log files from multiple AWS regions and multiple AWS accounts into a single Amazon S3 bucket. For more information, see Aggregating CloudTrail Log Files to a Single Amazon S3 Bucket.

Understanding Amazon EC2, Amazon EBS, and Amazon VPC Log File Entries

CloudTrail log files can contain one or more log entries where each entry is made up of multiple JSON-formatted events. A log entry represents a single request from any source and includes information about the requested action, any input parameters, the date and time of the action, and so on. The log entries are not in any particular order; that is, they are not an ordered stack trace of the public API calls.

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":"", "eventName":"TerminateInstances", "awsRegion":"us-west-2", "sourceIPAddress":"", "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" } ] }