

AWS Migration Hub Migration Hub Migration Hub 目前為預覽版本，並可能有所變更。

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

# 使用服務連結角色
<a name="using-service-linked-roles"></a>

AWS Migration Hub 重構空間使用AWS Identity and Access Management(IAM)[服務連結角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#iam-term-service-linked-role)。服務連結角色是直接連結至「重構空間」的一種特殊 IAM 角色類型。服務連結角色由 Researcing 的角色預先定義，並包含服務呼叫其他呼叫所有服務所需要的許可AWS服務。

服務連結角色可讓設定重構空間變得更輕鬆，因為您不必手動新增必要的許可。Resature Spaces 定義其服務連結角色的許可，除非另有定義，否則僅有 Resource Spaces 可以擔任其角色。定義的許可包括信任政策和許可政策，並且該許可政策不能連接到任何其他 IAM 實體。

您必須先刪除服務連結角色的相關資源，才能將其刪除。這樣可保護您的 Resoute Spaces 資源，避免您不小心移除資源的存取許可。

如需關於支援服務連結角色的其他服務的資訊，請參閱[可搭配 IAM 運作的 AWS 服務](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html)，並尋找 **Service-Linked Role** (服務連結角色) 欄顯示為 **Yes **(是) 的服務。選擇具有連結的 **Yes (是)**，以檢視該服務的服務連結角色文件。

## 服務連結角色許可
<a name="slr-permissions"></a>

重構空間會使用名為的服務連結角色**AWS 服務性質表單中的因子空間**並將其與**移轉因子空間服務角色原則**IAM 政策 — 提供對AWS由 AWS Migration Hub 管理或使用的資源重構空間。

AWSServiceRoleForAWSServiceRoleForAWSServiceRoleForAWSServiceRoleForAWSServiceRoleForAWSServiceRoleForAWSServiceRoleForElastic Compu
+ `refactor-spaces.amazonaws.com`

以下是 AWSServiceRoleForElastic Compute Resource Name (ARN) 的 Amazon Resource Name)。

```
arn:aws:iam::111122223333:role/aws-service-role/refactor-spaces.amazonaws.com/AWSServiceRoleForMigrationHubRefactorSpaces
```

重構空間使用**AWS 服務性質表單中的因子空間**執行跨帳戶變更時，服務連結的角色。此角色必須出現在您的帳戶中，才能使用「重構空間」。如果不存在，重構空間會在下列 API 呼叫期間建立它：
+ `CreateEnvironment`
+ `CreateService`
+ `CreateApplication`
+ `CreateRoute`

您必須具備 `iam:CreateServiceLinkedRole` 許可才能建立服務連結角色。若服務連結角色不存在於您的帳戶中，且無法建立服務連結角色，`Create`呼叫將失敗。除非您使用的是「重構空間」主控台，否則您必須先在 IAM 主控台中建立服務連結的角色，才能使用「重構空間」。

在目前登入的帳戶中進行變更時，重構 Space 不會使用服務連結角色。例如，建立應用程式時，「重構空間」會更新環境中的所有 VPC，以便它們可以與新增的 VPC 通訊。如果 VPC 位於其他帳戶中，重構空間會使用服務連結的角色，而`ec2:CreateRoute`權限來更新其他帳戶中的路由表。

若要進一步擴充建立應用程式範例，在建立應用程式時，Refactor Spaces 會更新位於`CreateApplication`呼叫。如此一來，VPC 就可以與環境中的其他 VPC 通訊。

呼叫者必須安裝`ec2:CreateRoute`權限，我們用來更新路由表。此權限存在於服務連結的角色中，但重構空間不會使用來電者帳戶中的服務連結的角色來取得此權限。相反，呼叫者必須具有`ec2:CreateRoute`許可。否則，呼叫會失敗。

您不能使用服務連結角色來提升您的許可。您的帳戶必須已經具有服務連結角色的權限，才能在呼叫帳戶中進行變更。所以此`AWSMigrationHubRefactorSpacesFullAccess`受管理的原則，以及授與額外必要權限的原則，會定義建立重構空間資源的所有必要權限。服務連結的角色是這些權限的子集，用於特定跨帳戶呼叫。如需有關 `AWSMigrationHubRefactorSpacesFullAccess` 的詳細資訊，請參閱 [AWS受管政策：外觀設定因子空間完全存取](security-iam-awsmanpol.md#security-iam-awsmanpol-AWSMigrationHubRefactorSpacesFullAccess)。



### Tags
<a name="slr-permissions-tags"></a>

當重構空間在您的帳戶中建立資源時，它們會以適當的重構空間資源識別碼加上標記。例 Transit Gateway，從`CreateEnvironment`被標記為`refactor-spaces:environment-id`標記的環境識別碼作為值。API Gateway API`CreateApplication`被標記為`refactor-spaces:application-id`將應用程式識別碼做為值。這些標籤允許重構空間來管理這些資源。如果您編輯或移除標籤，重構空間將無法再更新或刪除資源。

### MigrationHubRefactorSpacesServiceRolePolicy
<a name="slr-permissions-iam-policy"></a>

名為的角色許可政策角色許可政策原則允許重構空間在指定資源上完成下列動作：

Amazon API Gateway 動作  
 `apigateway:PUT`   
 `apigateway:POST`   
 `apigateway:GET`   
 `apigateway:PATCH`   
 `apigateway:DELETE` 

Amazon Elastic Compute Cloud 操作  
 `ec2:DescribeNetworkInterfaces`   
 `ec2:DescribeRouteTables`   
 `ec2:DescribeSubnets`   
 `ec2:DescribeSecurityGroups`   
 `ec2:DescribeVpcEndpointServiceConfigurations`   
 `ec2:DescribeTransitGatewayVpcAttachments`   
 `ec2:AuthorizeSecurityGroupIngress`   
 `ec2:RevokeSecurityGroupIngress`   
 `ec2:DeleteSecurityGroup`   
 `ec2:DeleteTransitGatewayVpcAttachment`   
 `ec2:CreateRoute`   
 `ec2:DeleteRoute`   
 `ec2:DeleteTags`   
 `ec2:DeleteVpcEndpointServiceConfigurations` 

AWS Resource Access Manager 動作  
 `ram:GetResourceShareAssociations`   
 `ram:DeleteResourceShare`   
 `ram:AssociateResourceShare`   
 `ram:DisassociateResourceShare` 

Elastic Load Balancing；動作  
 `elasticloadbalancing:DescribeTargetHealth`   
 `elasticloadbalancing:DescribeListener`   
 `elasticloadbalancing:DescribeTargetGroups`   
 `elasticloadbalancing:RegisterTargets`   
 `elasticloadbalancing:CreateLoadBalancerListeners`   
 `elasticloadbalancing:CreateListener`   
 `elasticloadbalancing:DeleteListener`   
 `elasticloadbalancing:DeleteTargetGroup`   
 `elasticloadbalancing:DeleteLoadBalancer`   
 `elasticloadbalancing:AddTags`   
 `elasticloadbalancing:CreateTargetGroup` 

以下是顯示前述動作套用於哪些資源的完整政策：

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeNetworkInterfaces",
                "ec2:DescribeRouteTables",
                "ec2:DescribeSubnets",
                "ec2:DescribeSecurityGroups",
                "ec2:DescribeVpcEndpointServiceConfigurations",
                "ec2:DescribeTransitGatewayVpcAttachments",
                "elasticloadbalancing:DescribeTargetHealth",
                "elasticloadbalancing:DescribeListeners",
                "elasticloadbalancing:DescribeTargetGroups",
                "ram:GetResourceShareAssociations"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "ec2:AuthorizeSecurityGroupIngress",
                "ec2:RevokeSecurityGroupIngress",
                "ec2:DeleteSecurityGroup",
                "ec2:DeleteTransitGatewayVpcAttachment",
                "ec2:CreateRoute",
                "ec2:DeleteRoute",
                "ec2:DeleteTags",
                "ram:DeleteResourceShare",
                "ram:AssociateResourceShare",
                "ram:DisassociateResourceShare"
            ],
            "Resource": "*",
            "Condition": {
                "Null": {
                    "aws:ResourceTag/refactor-spaces:environment-id": "false"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": "ec2:DeleteVpcEndpointServiceConfigurations",
            "Resource": "*",
            "Condition": {
                "Null": {
                    "aws:ResourceTag/refactor-spaces:application-id": "false"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "elasticloadbalancing:RegisterTargets",
                "elasticloadbalancing:CreateLoadBalancerListeners",
                "elasticloadbalancing:CreateListener",
                "elasticloadbalancing:DeleteListener",
                "elasticloadbalancing:DeleteTargetGroup"
            ],
            "Resource": "*",
            "Condition": {
                "StringLike": {
                    "aws:ResourceTag/refactor-spaces:route-id": [
                        "*"
                    ]
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "apigateway:PUT",
                "apigateway:POST",
                "apigateway:GET",
                "apigateway:PATCH",
                "apigateway:DELETE"
            ],
            "Resource": [
                "arn:aws:apigateway:*::/restapis",
                "arn:aws:apigateway:*::/restapis/*",
                "arn:aws:apigateway:*::/vpclinks/*",
                "arn:aws:apigateway:*::/tags",
                "arn:aws:apigateway:*::/tags/*"
            ],
            "Condition": {
                "Null": {
                    "aws:ResourceTag/refactor-spaces:application-id": "false"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": "apigateway:GET",
            "Resource": "arn:aws:apigateway:*::/vpclinks/*"
        },
        {
            "Effect": "Allow",
            "Action": "elasticloadbalancing:DeleteLoadBalancer",
            "Resource": "arn:*:elasticloadbalancing:*:*:loadbalancer/net/refactor-spaces-nlb-*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "elasticloadbalancing:AddTags",
                "elasticloadbalancing:CreateListener"
            ],
            "Resource": "arn:*:elasticloadbalancing:*:*:loadbalancer/net/refactor-spaces-nlb-*",
            "Condition": {
                "Null": {
                    "aws:RequestTag/refactor-spaces:route-id": "false"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": "elasticloadbalancing:DeleteListener",
            "Resource": "arn:*:elasticloadbalancing:*:*:listener/net/refactor-spaces-nlb-*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "elasticloadbalancing:DeleteTargetGroup",
                "elasticloadbalancing:RegisterTargets"
            ],
            "Resource": "arn:*:elasticloadbalancing:*:*:targetgroup/refactor-spaces-tg-*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "elasticloadbalancing:AddTags",
                "elasticloadbalancing:CreateTargetGroup"
            ],
            "Resource": "arn:*:elasticloadbalancing:*:*:targetgroup/refactor-spaces-tg-*",
            "Condition": {
                "Null": {
                    "aws:RequestTag/refactor-spaces:route-id": "false"
                }
            }
        }
    ]
}
```

您必須設定許可，IAM 實體 (如使用者、群組或角色) 才可建立、編輯或刪除服務連結角色。如需詳細資訊，請參閱 *IAM 使用者指南*中的[服務連結角色許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html#service-linked-role-permissions)。

## 為建立服務連結角色
<a name="create-slr"></a>

您不需要手動建立一個服務連結角色。當您建立重構空間環境、應用程式、服務或路由AWS 管理主控台，AWS CLI，或AWSAPI，重構空間會為您建立服務連結角色。如需為建立服務連結角色的詳細資訊，請參閱[服務連結角色許可](#slr-permissions)。

若您刪除此服務連結角色，之後需要再次建立，您可以在帳戶中使用相同程序重新建立角色。當您建立重構 Spaces 環境、應用程式、服務或路由資源時，重構 Spaces 會再次為您建立服務連結角色。

## 編輯重構空間的服務連結角色
<a name="edit-slr"></a>

重構空間不允許您編輯 AWSServiceRoleForAWSServiceRoleForAWSServiceRoleForAWSServiceRoleForAWSServiceRoleForAWSServiceRoleForAWSSer 因為有各種實體可能會參考服務連結角色，所以您無法在建立角色之後變更角色名稱。然而，您可使用 IAM 來編輯角色描述。如需更多資訊，請參閱 *IAM 使用者指南*中的[編輯服務連結角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html#edit-service-linked-role)。

## 刪除重構空間的服務連結角色
<a name="delete-slr"></a>

若您不再使用需要服務連結角色的功能或服務，我們建議您刪除該角色。如此一來，您就沒有未主動監控或維護的未使用實體。然而，在手動刪除服務連結角色之前，您必須先清除資源。

**注意**  
若重構 Spaces 服務在您試圖刪除資源時正在使用該角色，刪除可能會失敗。若此情況發生，請等待數分鐘後並再次嘗試操作。

若要刪除 AwsService 表單表單空間所使用的重構空間資源，請使用「重構空間」主控台刪除資源，或使用資源的刪除 API 作業。如需刪除 API 操作的詳細資訊，請參閱[重構空間 API 參考](https://docs.aws.amazon.com/migrationhub-refactor-spaces/latest/APIReference/Welcome.html)。

**使用 IAM 手動刪除服務連結角色**

使用 IAM 主控台、AWS CLI，或AWSAPI 來刪除 AWSServiceRoleForAWSServiceRoleForAWSServiceRoleForAWSServiceRoleForAWSServiceRoleForForAWSSer 如需詳細資訊，請參閱 *IAM 使用者指南*中的[刪除服務連結角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html#delete-service-linked-role)。

## 重構 Space 服務連結角色的支援區域
<a name="slr-regions"></a>

重構 Spaces 支援在所有提供服務的區域中，使用服務連結角色。如需詳細資訊，請參閱 [AWS 區域與端點](https://docs.aws.amazon.com/general/latest/gr/rande.html)。