

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

# 创建调度器角色
<a name="getting-started"></a>

执行角色是一个 IAM 角色，该角色 AWS FIS 是为了与 EventBridge 调度器交互以及让事件桥调度器启动 FIS 实验。您可以将权限策略附加到此角色以授予 EventBridge调度程序调用 FIS 实验的权限。以下步骤描述了如何创建新的执行角色和 EventBridge 允许启动实验的策略。

**使用 AWS CLI 创建调度器角色**  
 EventBridge 需要使用此 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 命令行界面 (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`本地。以下政策允许 S EventBridge cheduler 对您账户中的所有实验模板进行`fis:StartExperiment`操作。如要将角色限制为单个实验模板，则使用您实验模板的 ID，在 `"arn:aws:fis:*:*:experiment-template/*"` 的底部替换 `*`。

------
#### [ 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"
                   }
               }
           }
       ]
   }
   ```

------