

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

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

# 使用 CloudFormation 建立重構空間資源
<a name="creating-resources-with-cloudformation"></a>

AWS Migration Hub 重構空間與AWS CloudFormation，這項服務可協助您建置您的AWS資源，以減少建立和管理資源和基礎架構的時間。您建立範本，描述所有AWS資源 (例如環境、應用程式、服務和路由)，以及CloudFormation會為您佈建及設定這些資源。

當您使用CloudFormation，您可以重複使用您的範本，以便重複且一致地設定您的「重構空間」資源。只需描述一次您的資源，即可在多個 AWS 帳戶與區域內重複佈建相同資源。

## 重構空間和 CloudFormation 模板
<a name="working-with-templates"></a>

若要佈建和設定重構空間與相關服務的資源，您必須了解[CloudFormation模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html)。範本是以 JSON 或 YAML 格式化的文本檔案。而您亦可以透過這些範本的說明，了解欲在 CloudFormation 堆疊中佈建的資源。如果您不熟悉 JSON 或 YAML，您可以使用 CloudFormation Designer 協助您開始使用 CloudFormation 範本。如需詳細資訊，請參閱 *AWS CloudFormation 使用者指南*中的[什麼是 CloudFormation Designer？](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/working-with-templates-cfn-designer.html)。

重構空間支援建立環境、應用程式、服務和CloudFormation。如需詳細資訊 (包括環境、應用程式、服務和路由的 JSON 和 YAML 範本範例)，請參閱[AWS Migration Hub 重構空間](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html)中的*AWS CloudFormation使用者指南*。

### 範本範例
<a name="working-with-templates-example"></a>

下列範例範本會建立虛擬私有雲端 (VPC) 和重構空間資源。當您選擇部署CloudFormation範本來建立演示重構環境，從入門] 對話方塊中，下列範本會部署由重構空間主控台。

**Example YAML 重構空格範本**  

```
AWSTemplateFormatVersion: '2010-09-09'
Description: This creates resources in one account.
Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.2.0.0/16
      Tags:
        - Key: Name
          Value: VpcForRefactorSpaces
  PrivateSubnet1:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: !Select [ 0, !GetAZs  '' ]
      CidrBlock: 10.2.1.0/24
      MapPublicIpOnLaunch: false
      Tags:
        - Key: Name
          Value: RefactorSpaces Private Subnet (AZ1)
  PrivateSubnet2:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: !Select [ 1, !GetAZs  '' ]
      CidrBlock: 10.2.2.0/24
      MapPublicIpOnLaunch: false
      Tags:
        - Key: Name
          Value: RefactorSpaces Private Subnet (AZ2)
  RefactorSpacesTestEnvironment:
    Type: AWS::RefactorSpaces::Environment
    DeletionPolicy: Delete
    Properties:
      Name: EnvWithMultiAccountServices
      NetworkFabricType: TRANSIT_GATEWAY
      Description: "This is a test environment"
  TestApplication:
    Type: AWS::RefactorSpaces::Application
    DeletionPolicy: Delete
    DependsOn:
      - PrivateSubnet1
      - PrivateSubnet2
    Properties:
      Name: proxytest
      EnvironmentIdentifier: !Ref RefactorSpacesTestEnvironment
      VpcId: !Ref VPC
      ProxyType: API_GATEWAY
      ApiGatewayProxy:
        EndpointType: "REGIONAL"
        StageName: "admintest"
  AdminAccountService:
    Type: AWS::RefactorSpaces::Service
    DeletionPolicy: Delete
    Properties:
      Name: AdminAccountService
      EnvironmentIdentifier: !Ref RefactorSpacesTestEnvironment
      ApplicationIdentifier: !GetAtt TestApplication.ApplicationIdentifier
      EndpointType: URL
      VpcId: !Ref VPC
      UrlEndpoint:
        Url: "http://aws.amazon.com"
  RefactorSpacesDefaultRoute:
    Type: AWS::RefactorSpaces::Route
    Properties:
      RouteType: "DEFAULT"
      EnvironmentIdentifier: !Ref RefactorSpacesTestEnvironment
      ApplicationIdentifier: !GetAtt TestApplication.ApplicationIdentifier
      ServiceIdentifier: !GetAtt AdminAccountService.ServiceIdentifier
  RefactorSpacesURIRoute:
    Type: AWS::RefactorSpaces::Route
    DependsOn: 'RefactorSpacesDefaultRoute'
    Properties:
      RouteType: "URI_PATH"
      EnvironmentIdentifier: !Ref RefactorSpacesTestEnvironment
      ApplicationIdentifier: !GetAtt TestApplication.ApplicationIdentifier
      ServiceIdentifier: !GetAtt AdminAccountService.ServiceIdentifier
      UriPathRoute:
        SourcePath: "/cfn-created-route"
        ActivationState: ACTIVE
        Methods: [ "GET" ]
```

## 進一步了解 CloudFormation
<a name="learn-more-cloudformation"></a>

若要進一步了解 CloudFormation，請參閱下列資源：
+ [AWS CloudFormation](https://aws.amazon.com/cloudformation/)
+ 《[AWS CloudFormation 使用者指南](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)》
+ [CloudFormation API 參考](https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/Welcome.html)
+ [AWS CloudFormation 命令行介面使用者指南](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/what-is-cloudformation-cli.html)