Amazon Athena
User Guide

Logging Amazon Athena API Calls with AWS CloudTrail

Athena is integrated with CloudTrail, a service that captures all of the Athena API calls and delivers the log files to an Amazon S3 bucket that you specify.

CloudTrail captures API calls from the Athena console or from your code to the Athena API operations. Using the information collected by CloudTrail, you can determine the request that was made to Athena, the source IP address from which the request was made, who made the request, when it was made, and so on.

You can also use Athena to query CloudTrail log files for insight. For more information, see CloudTrail SerDe. To learn more about CloudTrail, including how to configure and enable it, see the AWS CloudTrail User Guide.

Athena Information in CloudTrail

When CloudTrail logging is enabled in your AWS account, API calls made to Athena actions are tracked in CloudTrail log files, where they are written with other AWS service records. CloudTrail determines when to create and write to a new file based on a time period and file size.

All Athena actions are logged by CloudTrail and are documented in the Amazon Athena API Reference. For example, calls to the StartQueryExecution and GetQueryResults actions generate entries in the CloudTrail log files.

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

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

  • Whether the request was made with temporary security credentials for a role or federated user

  • Whether the request was made by another AWS service

For more information, see CloudTrail userIdentity Element in the AWS CloudTrail User Guide.

You can store your log files in your S3 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 with Amazon S3 server-side encryption (SSE).

To be notified upon log file delivery, you can configure CloudTrail to publish Amazon SNS notifications when new log files are delivered. For more information, see Configuring Amazon SNS Notifications for CloudTrail.

You can also aggregate Athena log files from multiple AWS regions and multiple AWS accounts into a single S3 bucket.

For more information, see Receiving CloudTrail Log Files from Multiple Regions and Receiving CloudTrail Log Files from Multiple Accounts.

Understanding Athena Log File Entries

CloudTrail log files can contain one or more log entries. Each entry lists multiple JSON-formatted events. A log entry 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. Log entries are not an ordered stack trace of the public API calls, so they do not appear in any specific order.

The following examples demonstrate CloudTrail log entries for:

StartQueryExecution (Successful)

{ "eventVersion":"1.05", "userIdentity":{ "type":"IAMUser", "principalId":"EXAMPLE_PRINCIPAL_ID", "arn":"arn:aws:iam::123456789012:user/johndoe", "accountId":"123456789012", "accessKeyId":"EXAMPLE_KEY_ID", "userName":"johndoe" }, "eventTime":"2017-05-04T00:23:55Z", "eventSource":"", "eventName":"StartQueryExecution", "awsRegion":"us-east-1", "sourceIPAddress":"77.88.999.69", "userAgent":"aws-internal/3", "requestParameters":{ "clientRequestToken":"16bc6e70-f972-4260-b18a-db1b623cb35c", "resultConfiguration":{ "outputLocation":"s3://athena-johndoe-test/test/" }, "query":"Select 10" }, "responseElements":{ "queryExecutionId":"b621c254-74e0-48e3-9630-78ed857782f9" }, "requestID":"f5039b01-305f-11e7-b146-c3fc56a7dc7a", "eventID":"c97cf8c8-6112-467a-8777-53bb38f83fd5", "eventType":"AwsApiCall", "recipientAccountId":"123456789012" }

StartQueryExecution (Failed)

{ "eventVersion":"1.05", "userIdentity":{ "type":"IAMUser", "principalId":"EXAMPLE_PRINCIPAL_ID", "arn":"arn:aws:iam::123456789012:user/johndoe", "accountId":"123456789012", "accessKeyId":"EXAMPLE_KEY_ID", "userName":"johndoe" }, "eventTime":"2017-05-04T00:21:57Z", "eventSource":"", "eventName":"StartQueryExecution", "awsRegion":"us-east-1", "sourceIPAddress":"77.88.999.69", "userAgent":"aws-internal/3", "errorCode":"InvalidRequestException", "errorMessage":"Invalid result configuration. Should specify either output location or result configuration", "requestParameters":{ "clientRequestToken":"ca0e965f-d6d8-4277-8257-814a57f57446", "query":"Select 10" }, "responseElements":null, "requestID":"aefbc057-305f-11e7-9f39-bbc56d5d161e", "eventID":"6e1fc69b-d076-477e-8dec-024ee51488c4", "eventType":"AwsApiCall", "recipientAccountId":"123456789012" }


{ "eventVersion":"1.05", "userIdentity":{ "type":"IAMUser", "principalId":"EXAMPLE_PRINCIPAL_ID", "arn":"arn:aws:iam::123456789012:user/johndoe", "accountId":"123456789012", "accessKeyId":"EXAMPLE_KEY_ID", "userName":"johndoe" }, "eventTime":"2017-05-16T22:00:58Z", "eventSource":"", "eventName":"CreateNamedQuery", "awsRegion":"us-west-2", "sourceIPAddress":"77.88.999.69", "userAgent":"aws-cli/1.11.85 Python/2.7.10 Darwin/16.6.0 botocore/1.5.48", "requestParameters":{ "name":"johndoetest", "queryString":"select 10", "database":"default", "clientRequestToken":"fc1ad880-69ee-4df0-bb0f-1770d9a539b1" }, "responseElements":{ "namedQueryId":"cdd0fe29-4787-4263-9188-a9c8db29f2d6" }, "requestID":"2487dd96-3a83-11e7-8f67-c9de5ac76512", "eventID":"15e3d3b5-6c3b-4c7c-bc0b-36a8dd95227b", "eventType":"AwsApiCall", "recipientAccountId":"123456789012" },