{"id":9233,"date":"2022-02-10T17:51:08","date_gmt":"2022-02-10T12:21:08","guid":{"rendered":"https:\/\/www.skynats.com\/?p=9233"},"modified":"2023-06-15T17:12:36","modified_gmt":"2023-06-15T11:42:36","slug":"create-table-for-cloudtrail-logs-in-athena","status":"publish","type":"post","link":"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/","title":{"rendered":"How To Create Table for CloudTrail Logs in Athena"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Create tables in Athena for CloudTrail logs<\/h2>\n\n\n\n<p>To make it easier for you to create tables in Athena for CloudTrail logs, our Technical Support team have placed together this handy guide:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>CloudTrail Logs in Athena via Manual Partitioning<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>CloudTrail Logs Table in Athena via Partition Projection<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-create-tables-for-cloudtrail-logs-in-athena-via-manual-partitioning\"><strong>Create Tables For CloudTrail Logs In Athena Via Manual Partitioning<\/strong><\/h3>\n\n\n\n<p>Consider the following example of manually creating tables for a CloudTrail using the Athena console.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>To begin, we&#8217;ll copy the DDL statement from the CloudTrail console&#8217;s Create a table in the Amazon Athena dialogue box. To partition the table, we&#8217;ll paste this DDL statement into the Athena console and add a &#8220;PARTITIONED BY&#8221; clause.<\/li><\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>Next, change the following code to point to the Amazon S3 bucket containing the log data:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>s3:\/\/CloudTrail_bucket_name\/AWSLogs\/Account_ID\/CloudTrail\/<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li>Then we&#8217;ll double-check that all of the fields are listed correctly.<\/li><\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\"><li>The query will then be run through the Athena console.<\/li><\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"5\"><li>The partitions should then be loaded using the ALTER TABLE ADD PARTITION command.<\/li><\/ol>\n\n\n\n<p>For example,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER TABLE table_name ADD \n   PARTITION (region='us-east-1',\n              year='2019',\n              month='02',\n              day='01')\n   LOCATION 's3:\/\/CloudTrail_bucket_name\/AWSLogs\/Account_ID\/CloudTrail\/us-east-1\/2021\/02\/01\/'<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Create Tables For CloudTrail Logs In Athena Via Partition Projection<\/strong><\/h3>\n\n\n\n<p>With the Athena partition projection feature, we can clarify the partition scheme in advance, decrease query run time, and automate partition management. Whenever new data is added, this feature creates new partitions.<\/p>\n\n\n\n<p>Furthermore, it eliminates the need to manually create a partition using the ALTER TABLE ADD PARTITION command.<\/p>\n\n\n\n<p>For example, in the example below, the CREATE TABLE statement automatically projects partitions in CloudTrail logs from a given date to the current date for a specific AWS Region. Here, we must replace the placeholders bucket, account-id, and AWS-region with accurate values in the LOCATION and storage.location.template.clauses.<\/p>\n\n\n\n<p>Furthermore, we must replace 2020\/01\/01 with the preferred start date. We can query the table once the query has been successfully run. Moreover, the ALTER TABLE ADD PARTITION command is not required to load the partitions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE EXTERNAL TABLE cloudtrail_logs_pp(\n    eventVersion STRING,\n    userIdentity STRUCT&lt;\n        type: STRING,\n        principalId: STRING,\n        arn: STRING,\n        accountId: STRING,\n        invokedBy: STRING,\n        accessKeyId: STRING,\n        userName: STRING,\n        sessionContext: STRUCT&lt;\n            attributes: STRUCT&lt;\n                mfaAuthenticated: STRING,\n                creationDate: STRING&gt;,\n            sessionIssuer: STRUCT&lt;\n                type: STRING,\n                principalId: STRING,\n                arn: STRING,\n                accountId: STRING,\n                userName: STRING&gt;&gt;&gt;,\n    eventTime STRING,\n    eventSource STRING,\n    eventName STRING,\n    awsRegion STRING,\n    sourceIpAddress STRING,\n    userAgent STRING,\n    errorCode STRING,\n    errorMessage STRING,\n    requestParameters STRING,\n    responseElements STRING,\n    additionalEventData STRING,\n    requestId STRING,\n    eventId STRING,\n    readOnly STRING,\n    resources ARRAY&lt;STRUCT&lt;\n        arn: STRING,\n        accountId: STRING,\n        type: STRING&gt;&gt;,\n    eventType STRING,\n    apiVersion STRING,\n    recipientAccountId STRING,\n    serviceEventDetails STRING,\n    sharedEventID STRING,\n    vpcEndpointId STRING\n  )\nPARTITIONED BY (\n   `timestamp` string)\nROW FORMAT SERDE 'com.amazon.emr.hive.serde.CloudTrailSerde'\nSTORED AS INPUTFORMAT 'com.amazon.emr.cloudtrail.CloudTrailInputFormat'\nOUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'\nLOCATION\n  's3:\/\/bucket\/AWSLogs\/account-id\/CloudTrail\/aws-region'\nTBLPROPERTIES (\n  'projection.enabled'='true', \n  'projection.timestamp.format'='yyyy\/MM\/dd', \n  'projection.timestamp.interval'='1', \n  'projection.timestamp.interval.unit'='DAYS', \n  'projection.timestamp.range'='2020\/01\/01,NOW', \n  'projection.timestamp.type'='date', \n  'storage.location.template'='s3:\/\/bucket\/AWSLogs\/account-id\/CloudTrail\/aws-region\/${timestamp}')<\/code><\/pre>\n\n\n\n<p>Looking for solution? We are here to help you. <a href=\"https:\/\/www.skynats.com\/contact-us\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span style=\"color:#016b98\" class=\"has-inline-color\">Contact Us<\/span><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create tables in Athena for CloudTrail logs To make it easier for you to create tables in Athena for CloudTrail logs, our Technical Support team have placed together this handy guide: CloudTrail Logs in Athena via Manual Partitioning CloudTrail Logs Table in Athena via Partition Projection Create Tables For CloudTrail Logs In Athena Via Manual [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[681,682],"class_list":["post-9233","post","type-post","status-publish","format-standard","hentry","category-blog","tag-athena","tag-cloudtrail-logs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How To Create Table for CloudTrail Logs in Athena | Skynats<\/title>\n<meta name=\"description\" content=\"To make it easier for you to create tables in Athena for CloudTrail logs, our technical support team have placed together this handy guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Create Table for CloudTrail Logs in Athena\" \/>\n<meta property=\"og:description\" content=\"To make it easier for you to create tables in Athena for CloudTrail logs, our technical support team have placed together this handy guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/\" \/>\n<meta property=\"og:site_name\" content=\"Server Management Services | Cloud Management | Skynats\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/skynats\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-10T12:21:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-15T11:42:36+00:00\" \/>\n<meta name=\"author\" content=\"Arjun N\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@skynatstech\" \/>\n<meta name=\"twitter:site\" content=\"@skynatstech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Arjun N\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/create-table-for-cloudtrail-logs-in-athena\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/create-table-for-cloudtrail-logs-in-athena\\\/\"},\"author\":{\"name\":\"Arjun N\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/person\\\/2428d280a8b32a1fbd909b1411e32fb7\"},\"headline\":\"How To Create Table for CloudTrail Logs in Athena\",\"datePublished\":\"2022-02-10T12:21:08+00:00\",\"dateModified\":\"2023-06-15T11:42:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/create-table-for-cloudtrail-logs-in-athena\\\/\"},\"wordCount\":330,\"publisher\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#organization\"},\"keywords\":[\"athena\",\"cloudtrail logs\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/create-table-for-cloudtrail-logs-in-athena\\\/\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/create-table-for-cloudtrail-logs-in-athena\\\/\",\"name\":\"How To Create Table for CloudTrail Logs in Athena | Skynats\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#website\"},\"datePublished\":\"2022-02-10T12:21:08+00:00\",\"dateModified\":\"2023-06-15T11:42:36+00:00\",\"description\":\"To make it easier for you to create tables in Athena for CloudTrail logs, our technical support team have placed together this handy guide.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/create-table-for-cloudtrail-logs-in-athena\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.skynats.com\\\/blog\\\/create-table-for-cloudtrail-logs-in-athena\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/create-table-for-cloudtrail-logs-in-athena\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Create Table for CloudTrail Logs in Athena\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/\",\"name\":\"Server Management Services | Cloud Management | Skynats\",\"description\":\"Server Management and Cloud Management\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#organization\",\"name\":\"Skynats Technologies\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/Sknats-Logo-New-whole.png\",\"contentUrl\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/Sknats-Logo-New-whole.png\",\"width\":989,\"height\":367,\"caption\":\"Skynats Technologies\"},\"image\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/skynats\",\"https:\\\/\\\/x.com\\\/skynatstech\",\"https:\\\/\\\/www.instagram.com\\\/skynatstech\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/skynats-technologies\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCvTAjrFJ4_E2MJKwlDHomlg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/person\\\/2428d280a8b32a1fbd909b1411e32fb7\",\"name\":\"Arjun N\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g\",\"caption\":\"Arjun N\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How To Create Table for CloudTrail Logs in Athena | Skynats","description":"To make it easier for you to create tables in Athena for CloudTrail logs, our technical support team have placed together this handy guide.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/","og_locale":"en_US","og_type":"article","og_title":"How To Create Table for CloudTrail Logs in Athena","og_description":"To make it easier for you to create tables in Athena for CloudTrail logs, our technical support team have placed together this handy guide.","og_url":"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/","og_site_name":"Server Management Services | Cloud Management | Skynats","article_publisher":"https:\/\/www.facebook.com\/skynats","article_published_time":"2022-02-10T12:21:08+00:00","article_modified_time":"2023-06-15T11:42:36+00:00","author":"Arjun N","twitter_card":"summary_large_image","twitter_creator":"@skynatstech","twitter_site":"@skynatstech","twitter_misc":{"Written by":"Arjun N","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/#article","isPartOf":{"@id":"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/"},"author":{"name":"Arjun N","@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/person\/2428d280a8b32a1fbd909b1411e32fb7"},"headline":"How To Create Table for CloudTrail Logs in Athena","datePublished":"2022-02-10T12:21:08+00:00","dateModified":"2023-06-15T11:42:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/"},"wordCount":330,"publisher":{"@id":"https:\/\/www.skynats.com\/blog\/#organization"},"keywords":["athena","cloudtrail logs"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/","url":"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/","name":"How To Create Table for CloudTrail Logs in Athena | Skynats","isPartOf":{"@id":"https:\/\/www.skynats.com\/blog\/#website"},"datePublished":"2022-02-10T12:21:08+00:00","dateModified":"2023-06-15T11:42:36+00:00","description":"To make it easier for you to create tables in Athena for CloudTrail logs, our technical support team have placed together this handy guide.","breadcrumb":{"@id":"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.skynats.com\/blog\/create-table-for-cloudtrail-logs-in-athena\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.skynats.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Create Table for CloudTrail Logs in Athena"}]},{"@type":"WebSite","@id":"https:\/\/www.skynats.com\/blog\/#website","url":"https:\/\/www.skynats.com\/blog\/","name":"Server Management Services | Cloud Management | Skynats","description":"Server Management and Cloud Management","publisher":{"@id":"https:\/\/www.skynats.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.skynats.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.skynats.com\/blog\/#organization","name":"Skynats Technologies","url":"https:\/\/www.skynats.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.skynats.com\/blog\/wp-content\/uploads\/2021\/08\/Sknats-Logo-New-whole.png","contentUrl":"https:\/\/www.skynats.com\/blog\/wp-content\/uploads\/2021\/08\/Sknats-Logo-New-whole.png","width":989,"height":367,"caption":"Skynats Technologies"},"image":{"@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/skynats","https:\/\/x.com\/skynatstech","https:\/\/www.instagram.com\/skynatstech\/","https:\/\/www.linkedin.com\/company\/skynats-technologies","https:\/\/www.youtube.com\/channel\/UCvTAjrFJ4_E2MJKwlDHomlg"]},{"@type":"Person","@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/person\/2428d280a8b32a1fbd909b1411e32fb7","name":"Arjun N","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e0f4d2489abeea1769beb944d2258c862259b62ff26853075066ca8ad37e3333?s=96&d=mm&r=g","caption":"Arjun N"}}]}},"_links":{"self":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/9233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/comments?post=9233"}],"version-history":[{"count":0,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/9233\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/media?parent=9233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/categories?post=9233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/tags?post=9233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}