

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

# 建立 AWS PCS 的執行個體描述檔
<a name="security-instance-profiles_create"></a>

------
#### [ AWS PCS console ]

當您建立運算節點群組，讓 AWS PCS 使用最低必要政策為您建立基本**設定檔時，請選取建立設定檔**。

------
#### [ Amazon EC2 console ]

您可以直接從 Amazon EC2 主控台建立執行個體描述檔。如需詳細資訊，請參閱*AWS Identity and Access Management 《 使用者指南*》中的[使用執行個體描述](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html)檔。

**重要**  
請務必在 IAM 角色名稱`AWSPCS`中使用必要的字首。

------
#### [ AWS CLI ]

**使用 AWS CLI 設定基本執行個體描述檔**
**注意**  
將下列範例中的 {{example-role}} 取代為您的 IAM 角色名稱。

1. 使用 `/aws-pcs/`作為路徑屬性或開頭為 的名稱來建立 IAM 角色`AWSPCS`。

   1. 將下列內容複製並貼到名為 的新文字檔案`trust_policy.json`。  
****  

      ```
      {  
          "Version":"2012-10-17",		 	 	   
          "Statement": [  
              {  
                  "Effect": "Allow",  
                   "Principal": {  
                      "Service": [  
                          "ec2.amazonaws.com"  
                      ]  
                  },  
                  "Action": [  
                      "sts:AssumeRole"  
                  ]  
              }  
          ]  
      }
      ```

   1. 使用下列 1 個命令來建立 IAM 角色。

      ```
      aws iam create-role --path /aws-pcs/ --role-name {{example-role}} --assume-role-policy-document file://trust_policy.json
      ```

      或

      ```
      aws iam create-role --role-name {{AWSPCS-example-role}} --assume-role-policy-document file://trust_policy.json
      ```

1. **連接許可。**

   1. 將下列內容複製並貼到名為 的新文字檔案`policy_document.json`。  
****  

      ```
      {
          "Version":"2012-10-17",		 	 	 
          "Statement": [
              {
                  "Action": [
                      "pcs:RegisterComputeNodeGroupInstance"
                  ],
                  "Resource": "*",
                  "Effect": "Allow"
              }
          ]
      }
      ```

   1. 將政策文件連接至角色。此命令會將政策附加為內嵌政策。

      ```
      aws iam put-role-policy \  
          --role-name {{example-role}} \  
          --policy-name pcsRegisterInstancePolicy \  
          --policy-document file://policy_document.json
      ```

1. **建立執行個體描述檔。以執行個體{{描述檔的名稱取代 example-}}profile。**

   ```
   aws iam create-instance-profile --instance-profile-name {{example-profile}}
   ```

1. **將 IAM 角色與執行個體描述檔建立關聯。**

   ```
   aws iam add-role-to-instance-profile \  
      --instance-profile-name {{example-profile}} \  
      --role-name {{example-role}}
   ```

------