

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 创建 AWS Glue 爬虫
<a name="configure-custom-reports-create-crawler"></a>

AWS Glue 是一项完全托管的提取、转换和加载 (ETL) 服务，允许您从 Amazon S3 数据创建数据库并使用 Athena 查询该数据库。该数据库也称为 AWS Glue 数据目录。 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://console.aws.amazon.com/appstream2/家](https://console.aws.amazon.com/appstream2/home)中打开 WorkSpaces 应用程序控制台。

1. 选择您已订阅使用情况报告的 AWS 区域。

1. 在导航窗格中，选择 **Usage Reports (使用率报告)**，然后确认使用率报告日志记录已启用。

1. 在**报告详细信息**选项卡上，在 **Analytics** 旁边的段落中，选择**CloudFormation模板**链接。

   选择该链接将打开 CloudFormation 控制台，在运行模板之前，可以在其中查看模板指定的 CloudFormation 堆栈参数。该模板在运行时会创建一个 AWS Glue 爬虫和几个示例 Athena 查询。

1. **在 “指定详细信息**” 页面上，在旁边 **ScheduleExpression**，保留默认值或为要运行爬网程序的频率指定不同的 cron 表达式值。请勿更改任何其他默认值。完成此操作后，选择**下一步**。

   默认情况下，爬网程序设定为每天运行，但您可以配置爬网程序每周、每月或以其他频率运行。有关 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"
           }
       ]
   }
   ```

------