

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

# 建立 AWS Glue 爬蟲程式
<a name="configure-custom-reports-create-crawler"></a>

AWS Glue 是一種全受管擷取、轉換和載入 (ETL) 服務，可讓您從 Amazon S3 資料建立資料庫，並使用 Athena 查詢該資料庫。此資料庫也稱為 AWS Glue Data Catalog。 AWS Glue 爬蟲程式可以自動偵測 Amazon S3 資料的結構描述，並建立對應的資料庫和資料表。WorkSpaces 應用程式提供 CloudFormation 範本，可用來建立必要的 AWS Glue 資源。

**重要**  
完成下列程序中的步驟會建立 AWS Glue 爬蟲程式。不過，這些步驟不會啟動爬蟲程式。若要啟動爬蟲程式，您必須執行下一個程序中的步驟。如需 AWS Glue 爬蟲程式的詳細資訊，請參閱[定義爬蟲程式](https://docs.aws.amazon.com/glue/latest/dg/add-crawler.html)。

**建立 AWS Glue 爬蟲程式**

1. 在 https：//[https://console.aws.amazon.com/appstream2/home](https://console.aws.amazon.com/appstream2/home) 開啟 WorkSpaces 應用程式主控台。

1. 選擇您已訂閱用量報告的 AWS 區域。

1. 在導覽窗格中選擇 **Usage Reports (用量報告)**，然後確認已啟用用量報告記錄。

1. 在 **Report Details (報告詳細資料)** 索引標籤中，於 **Analytics (分析)** 旁的段落選擇 **CloudFormation template (CloudFormation 範本)** 連結。

   選擇連結會開啟 CloudFormation 主控台，您可以在其中檢閱範本指定的 CloudFormation 堆疊參數，然後再執行它。範本會在執行時建立 AWS Glue 爬蟲程式和數個範例 Athena 查詢。

1. 在 **Specify Details (指定詳細資料)** 頁面上的 **ScheduleExpression** 旁邊，保留預設值或指定不同的 Cron 表達式來作為您所需的爬蟲程式執行頻率。請勿變更任何其他預設值。完成後，請選擇 **Next (下一步)**。

   在預設情況下，爬蟲程式會排定為每天執行，但您也可以將爬蟲程式設定為以每週、每月或其他頻率來執行。如需 Cron 語法的相關資訊，請參閱 [Cron 表達式](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions)。

1. 在 **Options (選項)** 頁面上保留預設值，然後選擇 **Next (下一步)**。

1. 在**檢閱**頁面上，選取「我確認 CloudFormation 可能會使用自訂名稱建立 IAM 資源」旁的核取方塊，然後選擇**建立**。

   您必須擁有足夠的 AWS Glue 和 AWS Identity and Access Management (IAM) 許可，才能建立和執行 CloudFormation 堆疊。如果您沒有所需許可，可請 Amazon Web Services 帳戶管理員在您的帳戶中執行這些步驟，或授予您以下許可。

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Allow",
               "Action": [
                   "athena:CreateNamedQuery",
                   "athena:BatchGetNamedQuery",
                   "athena:GetNamedQuery",
                   "athena:StartQueryExecution",
                   "athena:GetQueryResults",
                   "athena:GetQueryExecution",
                   "athena:ListNamedQueries",
                   "cloudformation:DescribeStacks",
                   "cloudformation:GetStackPolicy",
                   "cloudformation:DescribeStackEvents",
                   "cloudformation:CreateStack",
                   "cloudformation:GetTemplate",
                   "cloudformation:ListChangeSets",
                   "cloudformation:ListStackResources",
                   "iam:GetRole",
                   "iam:CreateRole",
                   "iam:GetRolePolicy",
                   "s3:GetBucketLocation",
                   "s3:ListBucketMultipartUploads",
                   "s3:ListBucket",
                   "s3:ListMultipartUploadParts",
                   "s3:PutObject",
                   "s3:GetObject",
                   "s3:AbortMultipartUpload"
               ],
               "Resource": [
                   "arn:aws:iam::*:role/AppStreamUsageReports-AppStreamUsageReportGlueRole*",
                   "arn:aws:cloudformation:*:*:stack/AppStreamUsageReports/*",
                   "arn:aws:athena:*:*:workgroup/primary",
                   "arn:aws:s3:::aws-athena-query-results-*"
               ]
           },
           {
               "Effect": "Allow",
               "Action": [
                   "iam:AttachRolePolicy",
                   "iam:PutRolePolicy",
                   "s3:GetObject",
                   "s3:ListBucket"
               ],
               "Resource": [
                   "arn:aws:s3:::appstream-logs-*",
                   "arn:aws:iam::*:role/AppStreamUsageReports-AppStreamUsageReportGlueRole*"
               ]
           },
           {
               "Effect": "Allow",
               "Action": [
                   "iam:PassRole"
               ],
               "Resource": [
                   "arn:aws:iam::*:role/AppStreamUsageReports-AppStreamUsageReportGlueRole*"
               ],
               "Condition": {
                   "StringEquals": {
                       "iam:PassedToService": "glue.amazonaws.com"
                   }
               }
           },
           {
               "Effect": "Allow",
               "Action": [
                   "cloudformation:GetTemplateSummary",
                   "glue:GetResourcePolicy",
                   "glue:GetCrawlers",
                   "glue:BatchGetCrawlers",
                   "glue:GetClassifiers",
                   "glue:CreateClassifier",
                   "glue:ListCrawlers",
                   "glue:GetTags",
                   "glue:GetCrawlerMetrics",
                   "glue:GetClassifier",
                   "tag:GetResources"
               ],
               "Resource": "*"
           },
           {
               "Effect": "Allow",
               "Action": "athena:RunQuery",
               "Resource": "arn:aws:athena:*:*:workgroup/primary"
           },
           {
               "Effect": "Allow",
               "Action": [
                   "glue:GetTables",
                   "glue:GetPartitions",
                   "glue:GetTable"
               ],
               "Resource": [
                   "arn:aws:glue:*:*:table/appstream-usage/*",
                   "arn:aws:glue:*:*:database/appstream-usage",
                   "arn:aws:glue:*:*:catalog"
               ]
           },
           {
               "Effect": "Allow",
               "Action": [
                   "glue:GetDatabase",
                   "glue:CreateDatabase",
                   "glue:GetDatabases"
               ],
               "Resource": [
                   "arn:aws:glue:*:*:database/appstream-usage",
                   "arn:aws:glue:*:*:catalog"
               ]
           },
           {
               "Effect": "Allow",
               "Action": [
                   "glue:GetCrawler",
                   "glue:StartCrawler",
                   "glue:CreateCrawler"
               ],
               "Resource": "arn:aws:glue:*:*:crawler/appstream-usage*"
           },
           {
               "Effect": "Allow",
               "Action": "glue:GetCatalogImportStatus",
               "Resource": "arn:aws:glue:*:*:catalog"
           }
       ]
   }
   ```

------