

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

# 安裝適用於 Windows Server 的 CodeDeploy 代理程式
<a name="codedeploy-agent-operations-install-windows"></a>

在 Windows Server 執行個體上，您可以使用下列其中一種方法來下載和安裝 CodeDeploy 代理程式：
+ Use AWS Systems Manager （建議）
+ 執行一系列的 Windows PowerShell 命令。
+ 選擇直接下載連結。
+ 執行 Amazon S3 複製命令。

**注意**  
CodeDeploy 代理程式安裝到的資料夾是 `C:\Program Data\Amazon\CodeDeploy`。請確定此路徑上沒有目錄連接或符號連結。

**Topics**
+ [使用 Systems Manager](#codedeploy-agent-operations-install-system-manager)
+ [使用 Windows PowerShell](#codedeploy-agent-operations-install-windows-powershell)
+ [使用直接連結](#codedeploy-agent-operations-install-windows-direct-link)
+ [使用 Amazon S3 複製命令](#codedeploy-agent-operations-install-windows-s3-copy)

## 使用 Systems Manager
<a name="codedeploy-agent-operations-install-system-manager"></a>

依照 中的指示[使用 安裝 CodeDeploy 代理程式 AWS Systems Manager](codedeploy-agent-operations-install-ssm.md)安裝 CodeDeploy 代理程式。

## 使用 Windows PowerShell
<a name="codedeploy-agent-operations-install-windows-powershell"></a>

登入執行個體，並且在 Windows PowerShell 執行以下命令：

1.  要求所有從網際網路下載的指令碼和組態檔案由信任的發行者簽署。如果您被提示更改執行政策，請輸入「**Y**」。

   ```
    Set-ExecutionPolicy RemoteSigned
   ```

1.  載入 AWS Tools for Windows PowerShell。

   ```
   Import-Module AWSPowerShell
   ```

1.  建立下載 CodeDeploy 代理程式安裝檔案的目錄。

   ```
   New-Item -Path "c:\temp" -ItemType "directory" -Force
   ```

1. 使用 `Set-AWSCredential`和 `Initialize-AWSDefaultConfiguration`命令設定 AWS 登入資料。如需詳細資訊，請參閱《PowerShell 使用者指南》的工具中的[使用 AWS 登入](https://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html)資料。 *AWS PowerShell *

1.  下載 CodeDeploy 代理程式安裝檔案。
**注意**  
AWS 支援 CodeDeploy 代理程式的最新次要版本。目前最新的次要版本為 1.7.x。

   若要安裝最新版本的 CodeDeploy 代理程式：
   + 

     ```
     powershell.exe -Command Read-S3Object -BucketName bucket-name -Key latest/codedeploy-agent.msi -File c:\temp\codedeploy-agent.msi
     ```

   若要安裝 CodeDeploy 代理程式的特定版本：
   + 

     ```
     powershell.exe -Command Read-S3Object -BucketName bucket-name -Key releases/codedeploy-agent-###.msi -File c:\temp\codedeploy-agent.msi
     ```

   *bucket-name* 是 Amazon S3 儲存貯體的名稱，其中包含您所在區域的 CodeDeploy 資源套件檔案。例如，對於美國東部 （俄亥俄） 區域，將 *bucket-name* 取代為 `aws-codedeploy-us-east-2`。如需儲存貯體名稱的清單，請參閱 [依區域顯示的資源套件儲存貯體名稱](resource-kit.md#resource-kit-bucket-names)。

1.  執行 CodeDeploy 代理程式安裝檔案。

   ```
   c:\temp\codedeploy-agent.msi /quiet /l c:\temp\host-agent-install-log.txt
   ```

若要確認服務是否正在執行，請執行下列命令：

```
powershell.exe -Command Get-Service -Name codedeployagent
```

 如果 CodeDeploy 代理程式剛安裝且尚未啟動，則在執行**Get-Service**命令之後，您應該會在**狀態**下看到 **Start...**：

```
Status     Name                DisplayName
------     ----                -----------
Start...   codedeployagent    CodeDeploy Host Agent Service
```

如果 CodeDeploy 代理程式已在執行中，則在執行**Get-Service**命令之後，在**狀態**下，您應該會看到 **Running**：

```
Status     Name                DisplayName
------     ----                -----------
Running    codedeployagent    CodeDeploy Host Agent Service
```

## 使用直接連結
<a name="codedeploy-agent-operations-install-windows-direct-link"></a>

如果 Windows Server 執行個體上的瀏覽器安全設定提供許可 （例如 到 `https://s3.*.amazonaws.com`)，您可以使用 區域的直接連結下載 CodeDeploy 代理程式，然後手動執行安裝程式。

連結為：

```
https://s3.region.amazonaws.com/aws-codedeploy-region/latest/codedeploy-agent.msi
```

...其中 *region* 是您 AWS 部署應用程式的 區域。

例如：

```
https://s3.af-south-1.amazonaws.com/aws-codedeploy-af-south-1/latest/codedeploy-agent.msi
```

**重要**  
從與 CodeDeploy 應用程式相同的區域取得`.msi`檔案。當您執行 `codedeploy-agent-log` 檔案時，選擇不同的區域可能會導致 `.msi` 檔案`inconsistent region`失敗。

## 使用 Amazon S3 複製命令
<a name="codedeploy-agent-operations-install-windows-s3-copy"></a>

如果執行個體上安裝 AWS CLI ，您可以使用 Amazon S3 [cp](https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html) 命令下載 CodeDeploy 代理程式，然後手動執行安裝程式。如需詳細資訊，請參閱[在 Microsoft Windows AWS Command Line Interface 上安裝](https://docs.aws.amazon.com/cli/latest/userguide/awscli-install-windows.html) 。

Amazon S3 命令為：

```
aws s3 cp s3://aws-codedeploy-region/latest/codedeploy-agent.msi codedeploy-agent.msi --region region
```

...其中 *region* 是您 AWS 部署應用程式的 區域。

例如：

```
aws s3 cp s3://aws-codedeploy-af-south-1/latest/codedeploy-agent.msi codedeploy-agent.msi --region af-south-1
```