

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

# 步驟 1：建立適用於 AWS Glue 服務的 IAM 政策
<a name="create-service-policy"></a>

對於存取其他 AWS 資源上資料的任何操作，例如存取 Amazon S3 中的物件， AWS Glue都需要代表您存取資源的許可。您可以使用 AWS Identity and Access Management (IAM) 提供這些許可。

**注意**  
如果您使用 AWS 受管政策 ，則可以略過此步驟`AWSGlueServiceRole`。

在本步驟中，您將建立一個類似 `AWSGlueServiceRole` 的政策。最新版本的 `AWSGlueServiceRole` 可在 IAM 主控台找到。

**為 建立 IAM 政策 AWS Glue**

此政策授予部分 Amazon S3 動作的許可，在 AWS Glue 擔任使用此政策的角色時可用於管理其所需的帳戶內資源。此政策指定的部分資源參照 AWS Glue 用於 Amazon S3 儲存貯體、Amazon S3 ETL 指令碼、CloudWatch Logs 和 Amazon EC2 資源的預設名稱。為了簡化，AWS Glue 寫入部分 Amazon S3 物件到您預設字首為 `aws-glue-*` 之帳戶的儲存貯體內。

1. 登入 AWS 管理主控台 ，並在 https：//[https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 開啟 IAM 主控台。

1. 在左側導覽窗格中選擇 **Policies** (政策)。

1. 選擇**建立政策**。

1. 在 **Create Policy** (建立政策) 畫面上導覽至索引標籤，以編輯 JSON。使用下列 JSON 陳述式建立政策文件，然後選擇 **Review policy** (檢閱政策)。
**注意**  
新增 Amazon S3 資源所需的任何許可。您可能希望將存取政策的資源部分範圍限縮在需要的資源。

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

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Action": [
           "glue:*",
           "s3:GetBucketLocation",
           "s3:ListBucket",
           "s3:ListAllMyBuckets",
           "s3:GetBucketAcl",
           "ec2:DescribeVpcEndpoints",
           "ec2:DescribeRouteTables",
           "ec2:CreateNetworkInterface",
           "ec2:DeleteNetworkInterface",
           "ec2:DescribeNetworkInterfaces",
           "ec2:DescribeSecurityGroups",
           "ec2:DescribeSubnets",
           "ec2:DescribeVpcAttribute",
           "iam:ListRolePolicies",
           "iam:GetRole",
           "iam:GetRolePolicy",
           "cloudwatch:PutMetricData"
         ],
         "Resource": [
           "*"
         ]
       },
       {
         "Effect": "Allow",
         "Action": [
           "s3:CreateBucket",
           "s3:PutBucketPublicAccessBlock"
         ],
         "Resource": [
           "arn:aws:s3:::aws-glue-*"
         ]
       },
       {
         "Effect": "Allow",
         "Action": [
           "s3:GetObject",
           "s3:PutObject",
           "s3:DeleteObject"
         ],
         "Resource": [
           "arn:aws:s3:::aws-glue-*/*",
           "arn:aws:s3:::*/*aws-glue-*/*"
         ]
       },
       {
         "Effect": "Allow",
         "Action": [
           "s3:GetObject"
         ],
         "Resource": [
           "arn:aws:s3:::crawler-public*",
           "arn:aws:s3:::aws-glue-*"
         ]
       },
       {
         "Effect": "Allow",
         "Action": [
           "logs:CreateLogGroup",
           "logs:CreateLogStream",
           "logs:PutLogEvents",
           "logs:AssociateKmsKey"
         ],
         "Resource": [
           "arn:aws:logs:*:*:log-group:/aws-glue/*"
         ]
       },
       {
         "Effect": "Allow",
         "Action": [
           "ec2:CreateTags",
           "ec2:DeleteTags"
         ],
         "Condition": {
           "ForAllValues:StringEquals": {
             "aws:TagKeys": [
               "aws-glue-service-resource"
             ]
           }
         },
         "Resource": [
           "arn:aws:ec2:*:*:network-interface/*",
           "arn:aws:ec2:*:*:security-group/*",
           "arn:aws:ec2:*:*:instance/*"
         ]
       }
     ]
   }
   ```

------

   下表說明此政策授予的許可。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/create-service-policy.html)

1. 在 **Review Policy** (檢閱政策) 畫面上，輸入 **Policy Name** (政策名稱)，例如 **GlueServiceRolePolicy**。輸入選用的說明，當您對政策滿意時，即可選擇 **Create policy (建立政策)**。