

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

# 建立排程器角色
<a name="getting-started"></a>

執行角色是 AWS FIS 擔任的 IAM 角色，以便與 EventBridge 排程器互動，以及讓 Event Bridge 排程器啟動 FIS 實驗。您可以將許可政策連接至此角色，以授予 EventBridge 排程器調用 FIS 實驗的存取權。下列步驟說明如何建立新的執行角色和政策，以允許 EventBridge 開始實驗。

**使用 AWS CLI 建立排程器角色**  
 這是 Event Bridge 能夠代表客戶排程實驗所需的 IAM 角色。

1. 複製下列擔任角色 JSON 政策，並將其儲存為 ` fis-execution-role.json`。此信任政策允許 EventBridge 排程器代表您擔任角色。

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

****  

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

------

1.  從 AWS Command Line Interface (AWS CLI) 輸入下列命令來建立新的角色。`FisSchedulerExecutionRole` 將 取代為您要提供此角色的名稱。

   ```
   aws iam create-role --role-name FisSchedulerExecutionRole --assume-role-policy-document file://fis-execution-role.json
   ```

    如果成功，您會看到下列輸出：

   ```
   {
       "Role": {
           "Path": "/",
           "RoleName": "FisSchedulerExecutionRole",
           "RoleId": "AROAZL22PDN5A6WKRBQNU",
           "Arn": "arn:aws:iam::123456789012:role/FisSchedulerExecutionRole",
           "CreateDate": "2023-08-24T17:23:05+00:00",
           "AssumeRolePolicyDocument": {
               "Version": "2012-10-17",		 	 	 
               "Statement": [
                   {
                       "Effect": "Allow",
                       "Principal": {
                           "Service": "scheduler.amazonaws.com"
                       },
                       "Action": "sts:AssumeRole"
                   }
               ]
           }
       }
   }
   ```

1.  若要建立新的政策，以允許 EventBridge 排程器叫用實驗，請複製下列 JSON，並將其儲存為 ` fis-start-experiment-permissions.json`。下列政策允許 EventBridge 排程器在您帳戶中的所有實驗範本上呼叫 `fis:StartExperiment`動作。如果您想要將角色限制為單一實驗範本`"arn:aws:fis:*:*:experiment-template/*"`，請將 `*` 結尾的 取代為實驗範本的 ID。

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Allow",
               "Action": "fis:StartExperiment",
               "Resource": [
                   "arn:aws:fis:*:*:experiment-template/*",
                   "arn:aws:fis:*:*:experiment/*"
               ]
           }
       ]
   }
   ```

------

1.  執行下列命令來建立新的許可政策。` FisSchedulerPolicy` 將 取代為您要提供此政策的名稱。

   ```
   aws iam create-policy --policy-name FisSchedulerPolicy --policy-document file://fis-start-experiment-permissions.json
   ```

    如果成功，您會看到下列輸出。請注意政策 ARN。您可以在下一個步驟中使用此 ARN，將政策連接至我們的執行角色。

   ```
   {
       "Policy": {
           "PolicyName": "FisSchedulerPolicy",
           "PolicyId": "ANPAZL22PDN5ESVUWXLBD",
           "Arn": "arn:aws:iam::123456789012:policy/FisSchedulerPolicy",
           "Path": "/",
           "DefaultVersionId": "v1",
           "AttachmentCount": 0,
           "PermissionsBoundaryUsageCount": 0,
           "IsAttachable": true,
           "CreateDate": "2023-08-24T17:34:45+00:00",
           "UpdateDate": "2023-08-24T17:34:45+00:00"
       }
   }
   ```

1.  執行下列命令，將政策連接至您的執行角色。`your-policy-arn` 以您在上一個步驟中建立的政策 ARN 取代 。`FisSchedulerExecutionRole` 將 取代為您執行角色的名稱。

   ```
   aws iam attach-role-policy --policy-arn your-policy-arn --role-name FisSchedulerExecutionRole
   ```

    `attach-role-policy` 操作不會在命令列傳回回應。

1.  您可以限制排程器只執行具有特定標籤值的 AWS FIS 實驗範本。例如，下列政策會授予所有 AWS FIS 實驗的` fis:StartExperiment`許可，但限制排程器只執行標記為 的實驗範本` Purpose=Schedule`。

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Allow",
               "Action": "fis:StartExperiment",
               "Resource": "arn:aws:fis:*:*:experiment/*"
           },
           {
               "Effect": "Allow",
               "Action": "fis:StartExperiment",
               "Resource": "arn:aws:fis:*:*:experiment-template/*",
               "Condition": {
                   "StringEquals": {
                       "aws:ResourceTag/Purpose": "Schedule"
                   }
               }
           }
       ]
   }
   ```

------