

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

# 使用 自動建立 Amazon WorkSpaces 應用程式資源 AWS CloudFormation
<a name="automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation"></a>

*Ram Kandaswamy，Amazon Web Services*

## 摘要
<a name="automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation-summary"></a>

此模式提供程式碼範例和步驟， AWS 雲端 以使用 [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 範本自動在 中建立 [Amazon WorkSpaces 應用程式](https://aws.amazon.com/workspaces/applications/)資源。模式說明如何使用 CloudFormation 堆疊自動建立 WorkSpaces 應用程式應用程式資源，包括映像建置器、映像、機群執行個體和堆疊。您可以使用桌面或應用程式交付模式，將 WorkSpaces 應用程式串流至 HTML5-compliant瀏覽器上的最終使用者。

## 先決條件和限制
<a name="automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ 接受 WorkSpaces 應用程式條款與條件
+ WorkSpaces 應用程式資源的基本知識，例如[機群、堆疊](https://docs.aws.amazon.com/appstream2/latest/developerguide/managing-stacks-fleets.html)和[映像建置器](https://docs.aws.amazon.com/appstream2/latest/developerguide/managing-image-builders.html)

**限制**
+ 您無法在該執行個體建立之後修改與 WorkSpaces 應用程式執行個體相關聯的 [AWS Identity and Access Management](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)(IAM) 角色。
+ 建立映像建置器之後，您無法修改 WorkSpaces 應用程式映像建置器執行個體上的屬性 （例如[子網路](https://docs.aws.amazon.com/vpc/latest/userguide/configure-subnets.html#subnet-basics)或[安全群組](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-security-groups.html))。

## Architecture
<a name="automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation-architecture"></a>

下圖說明如何使用 CloudFormation 範本自動建立 WorkSpaces 應用程式資源。

![\[自動建立 WorkSpaces 應用程式資源的工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/4f0205f5-5b91-4832-9f0f-2135ae866226/images/cb578939-d9af-4f60-93c9-286881df4c3a.png)


該圖顯示以下工作流程：

1. 您可以在此模式的其他資訊[其他資訊](#automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation-additional)區段中，根據 YAML 程式碼建立 CloudFormation 範本。

1.  CloudFormation 範本會建立 CloudFormation 測試堆疊。

   1. （選用） 您可以使用 WorkSpaces 應用程式建立映像建置器執行個體。

   1. （選用） 您可以使用自訂軟體建立 Windows 映像。

1.  CloudFormation 堆疊會建立 WorkSpaces 應用程式機群執行個體和堆疊。

1. 您可以將 WorkSpaces 應用程式資源部署至 HTML5-compliant瀏覽器上的最終使用者。

## 工具
<a name="automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation-tools"></a>
+ [Amazon WorkSpaces 應用程式](https://docs.aws.amazon.com/appstream2/latest/developerguide/what-is-appstream.html)是一項全受管應用程式串流服務，可讓您從任何地方立即存取桌面應用程式。WorkSpaces 應用程式會管理託管和執行應用程式所需的 AWS 資源、自動擴展，以及隨需提供使用者存取權。
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可協助您模型化和設定 AWS 資源、快速一致地佈建資源，以及在整個生命週期中管理資源。您可以使用範本來描述您的資源及其相依性，並將它們一起啟動和設定為堆疊，而不是個別管理資源。您可以管理和佈建跨多個 和 的堆疊 AWS 帳戶 AWS 區域。

## 最佳實務
<a name="automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation-best-practices"></a>
+ **正確設定映像建置器的網路存取** – 使用 NAT 閘道進行傳出限定網際網路存取，在具有適當網際網路存取的虛擬私有雲端 (VPC) 子網路中啟動映像建置器。

  在建立映像之前，測試與必要資源 （例如應用程式伺服器、資料庫和授權伺服器） 的網路連線。確認 VPC 路由表允許連線至所有必要的網路資源。如需詳細資訊，請參閱 WorkSpaces 應用程式文件中的[網際網路存取](https://docs.aws.amazon.com/appstream2/latest/developerguide/internet-access.html)。
+ **根據服務配額主動監控機群容量** – WorkSpaces 應用程式執行個體類型和大小配額是根據 AWS 帳戶每個 AWS 區域。如果您在同一個區域中有多個使用相同執行個體類型和大小的機群，則該區域中所有機群的執行個體總數必須小於或等於適用的配額。如需詳細資訊，請參閱 WorkSpaces 應用程式文件中[的故障診斷機群](https://docs.aws.amazon.com/appstream2/latest/developerguide/troubleshooting-fleets.html)。
+ **在機群部署之前，在映像建置器測試模式中測試應用程式** – 在建立映像和部署至機群之前，一律在映像建置器測試模式中驗證應用程式。測試模式模擬最終使用者在機群執行個體上擁有的有限許可。如需詳細資訊，請參閱 WorkSpaces 應用程式文件中[的疑難排解映像建置器](https://docs.aws.amazon.com/appstream2/latest/developerguide/troubleshooting-image-builder.html#troubleshooting-07)。

## 史詩
<a name="automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation-epics"></a>

### （選用） 建立 WorkSpaces 應用程式映像
<a name="optional-create-a-aas2-image"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝自訂軟體並建立映像。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation.html)請考慮使用 Windows AppLocker 功能來進一步鎖定映像。 | AWS DevOps，雲端架構師 | 

### 部署 CloudFormation 範本
<a name="deploy-the-cfn-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 更新 CloudFormation 範本。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation.html) | AWS 系統管理員、雲端管理員、雲端架構師、一般 AWS、AWS 管理員 | 
| 使用 範本建立 CloudFormation 堆疊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation.html) | 應用程式擁有者、AWS 系統管理員、Windows Engineer | 

## 疑難排解
<a name="automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 各種問題 | 如需詳細資訊，請參閱 WorkSpaces 應用程式文件中[的故障診斷](https://docs.aws.amazon.com/appstream2/latest/developerguide/troubleshooting.html)。 | 

## 相關資源
<a name="automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation-resources"></a>

**參考**
+ [Amazon WorkSpaces 應用程式入門：使用範例應用程式設定](https://docs.aws.amazon.com/appstream2/latest/developerguide/getting-started.html)
+ [建立 Amazon WorkSpaces 應用程式機群和堆疊](https://docs.aws.amazon.com/appstream2/latest/developerguide/set-up-stacks-fleets.html)

**教學課程和影片**
+ [Amazon WorkSpaces 應用程式使用者工作流程](https://www.youtube.com/watch?v=hVGQ87-Uhrc)
+ [如何將舊版 Windows Forms 應用程式遷移至 Amazon WorkSpaces 應用程式](https://www.youtube.com/watch?v=CIImtS2iVbg)
+ [AWS re：Invent 2018：使用 Amazon WorkSpaces 應用程式安全地交付桌面應用程式 (BAP201)](https://www.youtube.com/watch?v=xNIyc_inOhM)

## 其他資訊
<a name="automate-the-creation-of-appstream-2-0-resources-using-aws-cloudformation-additional"></a>

下列程式碼是 CloudFormation 範本的範例，可用來自動建立 WorkSpaces 應用程式資源。

```
AWSTemplateFormatVersion: 2010-09-09
Parameters:
  SubnetIds:
    Type: 'List<AWS::EC2::Subnet::Id>'
  testSecurityGroup:
    Type: 'AWS::EC2::SecurityGroup::Id'
  ImageName:
    Type: String
Resources:
  
  AppStreamFleet:
    Type: 'AWS::AppStream::Fleet'
    Properties:
      ComputeCapacity:
        DesiredInstances: 5
      InstanceType: stream.standard.medium
      Name: appstream-test-fleet
      DisconnectTimeoutInSeconds: 1200
      FleetType: ON_DEMAND
      IdleDisconnectTimeoutInSeconds: 1200
      ImageName: !Ref ImageName
      MaxUserDurationInSeconds: 345600
      VpcConfig:
        SecurityGroupIds:
          - !Ref testSecurityGroup
        SubnetIds: !Ref SubnetIds
  AppStreamStack:
    Type: 'AWS::AppStream::Stack'
    Properties:
      Description: AppStream stack for test
      DisplayName: AppStream test Stack
      Name: appstream-test-stack
      StorageConnectors:
        - ConnectorType: HOMEFOLDERS
      UserSettings:
        - Action: CLIPBOARD_COPY_FROM_LOCAL_DEVICE
          Permission: ENABLED
        - Action: CLIPBOARD_COPY_TO_LOCAL_DEVICE
          Permission: ENABLED
        - Action: FILE_DOWNLOAD
          Permission: ENABLED
        - Action: PRINTING_TO_LOCAL_DEVICE
          Permission: ENABLED
  AppStreamFleetAssociation:
    Type: 'AWS::AppStream::StackFleetAssociation'
    Properties:
      FleetName: appstream-test-fleet
      StackName: appstream-test-stack
    DependsOn:
      - AppStreamFleet
      - AppStreamStack
```