使用手動磁碟分割,為整個組織的追蹤建立表格 - Amazon Athena

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用手動磁碟分割,為整個組織的追蹤建立表格

若要在 Athena 中為整個組織的 CloudTrail 記錄檔建立表格,請遵循中的步驟使用手動磁碟分割為 Athena 中的 CloudTrail 記錄建立資料表,但要進行下列程序中所述的修改。

若要為整個組織的 CloudTrail 日誌建立 Athena 表格
  1. CREATE TABLE 陳述式中,修改 LOCATION 子句以加入組織 ID,如下列範例所示:

    LOCATION 's3://amzn-s3-demo-bucket/AWSLogs/organization_id/'
  2. PARTITIONED BY 子句中,以字串形式新增帳戶 ID 項目,如下列範例所示:

    PARTITIONED BY (account string, region string, year string, month string, day string)

    上述步驟的合併結果如以下範例所示:

    ... PARTITIONED BY (account string, region string, year string, month string, day string) ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe' STORED AS INPUTFORMAT 'com.amazon.emr.cloudtrail.CloudTrailInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' LOCATION 's3://amzn-s3-demo-bucket/AWSLogs/organization_id/Account_ID/CloudTrail/'
  3. ALTER TABLE 陳述式中的 ADD PARTITION 子句內加入帳戶 ID,如下列範例所示:

    ALTER TABLE table_name ADD PARTITION (account='111122223333', region='us-east-1', year='2022', month='08', day='08')
  4. ALTER TABLE 陳述式中的 LOCATION 子句內加入組織 ID、帳戶 ID,以及您要新增的分割區,如下列範例所示:

    LOCATION 's3://amzn-s3-demo-bucket/AWSLogs/organization_id/Account_ID/CloudTrail/us-east-1/2022/08/08/'

    上述步驟的合併結果如以下 ALTER TABLE 陳述式範例所示:

    ALTER TABLE table_name ADD PARTITION (account='111122223333', region='us-east-1', year='2022', month='08', day='08') LOCATION 's3://amzn-s3-demo-bucket/AWSLogs/organization_id/111122223333/CloudTrail/us-east-1/2022/08/08/'

請注意,在大型組織中,使用此方法手動新增和維護每個組織帳戶 ID 的分割區可能很麻煩。在這種情況下,請考慮使用 CloudTrail 湖泊而不是 Athena。 CloudTrail 湖在這種情況下提供了以下優點:

  • 自動彙總整個組織的日誌

  • 不需要設置或維護分區或 Athena 桌子

  • 查詢直接在 CloudTrail 控制台中運行

  • 使用SQL相容的查詢語言

如需詳細資訊,請參閱使用 AWS CloudTrail湖AWS CloudTrail 用戶指南