Open the Athena console.
If this is your first time to visit the Athena console in your current AWS Region, choose Explore the query editor to open the query editor. Otherwise, Athena opens in the query editor.
Choose Edit Settings to set up a query result location in Amazon S3.
For Manage settings, do one of the following:
In the Location of query result box, enter the path to the bucket that you created in Amazon S3 for your query results. Prefix the path with s3://
.
Choose Browse S3, choose the Amazon S3 bucket that you created for your current Region, and then choose Choose.
Choose Save.
Choose Editor to switch to the query editor.
On the right of the navigation pane, you can use the Athena query editor to enter and run queries and statements.
CREATE DATABASE mydatabase
In the navigation pane, for Database, make sure that mydatabase
is selected.
To give yourself more room in the query editor, you can choose the arrow icon to collapse the navigation pane.
To create a tab for a new query, choose the plus (+) sign in the query editor. You can have up to ten query tabs open at once.
To close one or more query tabs, choose the arrow next to the plus sign. To close all tabs at once, choose the arrow, and then choose Close all tabs.
In the query pane, enter the following CREATE EXTERNAL TABLE
statement. The regex breaks out the operating system, browser, and browser version information from the ClientInfo
field in the log data.
In the LOCATION
statement, replace myregion
with the AWS Region that you are currently using (for example, us-east-1
).
Choose Run.
The table cloudfront_logs
is created and appears under the list of Tables for the mydatabase
database.
CREATE EXTERNAL TABLE IF NOT EXISTS cloudfront_logs (
`Date` DATE,
Time STRING,
Location STRING,
Bytes INT,
RequestIP STRING,
Method STRING,
Host STRING,
Uri STRING,
Status INT,
Referrer STRING,
os STRING,
Browser STRING,
BrowserVersion STRING
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
"input.regex" = "^(?!#)([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+[^\(]+[\(]([^\;]+).*\%20([^\/]+)[\/](.*)$"
) LOCATION 's3://athena-examples-myregion/cloudfront/plaintext/';
SELECT os, COUNT(*) count
FROM cloudfront_logs
WHERE date BETWEEN date '2014-07-05' AND date '2014-08-05'
GROUP BY os
To save the results of the query to a .csv
file, choose Download results.
To view or run previous queries, choose the Recent queries tab.
To download the results of a previous query from the Recent queries tab, select the query, and then choose Download results. Queries are retained for 45 days.
To download one or more recent SQL query strings to a CSV file, choose Download CSV.