

# Install the CodeDeploy agent for Windows Server
<a name="codedeploy-agent-operations-install-windows"></a>

On Windows Server instances, you can use one of these methods to download and install the CodeDeploy agent:
+ Use AWS Systems Manager (recommended)
+ Run a series of Windows PowerShell commands.
+ Choose a direct download link.
+ Run an Amazon S3 copy command.

**Note**  
The folder that the CodeDeploy agent is installed to is `C:\ProgramData\Amazon\CodeDeploy`. Do not place directory junctions or symlinks on this path. For version 2.0.x and later, the agent enforces this requirement and refuses to start if the service binary is not under `C:\ProgramData\Amazon\CodeDeploy\`.  
For version 2.1.3 and later, only the Administrators group and the SYSTEM account can modify this folder and its contents. Standard users can read the folders that the agent creates for deployments, such as `deployment-logs`, but can't modify them.

**Note**  
The agent installer (`codedeploy-agent.msi`) and the agent binaries it installs (`codedeploy-agent.exe` and `codedeploy-local.exe`) are Authenticode-signed by Amazon. To check a signature, run:  

```
Get-AuthenticodeSignature -FilePath .\codedeploy-agent.msi
```
The `Status` must be `Valid`.

**Topics**
+ [Use Systems Manager](#codedeploy-agent-operations-install-system-manager)
+ [Use Windows PowerShell](#codedeploy-agent-operations-install-windows-powershell)
+ [Use a direct link](#codedeploy-agent-operations-install-windows-direct-link)
+ [Use an Amazon S3 copy command](#codedeploy-agent-operations-install-windows-s3-copy)

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

Follow the instructions in [Install the CodeDeploy agent using AWS Systems Manager](codedeploy-agent-operations-install-ssm.md) to install the CodeDeploy agent.

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

Sign in to the instance, and run the following commands in Windows PowerShell:

1.  Require that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher. If you are prompted to change the execution policy, type "**Y**." 

   ```
    Set-ExecutionPolicy RemoteSigned
   ```

1.  Load the AWS Tools for Windows PowerShell. 

   ```
   Import-Module AWSPowerShell
   ```

1.  Create a directory into where the CodeDeploy agent installation file is downloaded. 

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

1. Configure AWS credentials using the `Set-AWSCredential` and `Initialize-AWSDefaultConfiguration` commands. For more information, see [Using AWS credentials](https://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html) in the *AWS tools for PowerShell User Guide*.

1.  Download the CodeDeploy agent installation file. 
**Note**  
For the latest released version, see [Version history of the CodeDeploy agent](codedeploy-agent.md#codedeploy-agent-version-history).

   To install the latest version of the CodeDeploy agent. The `latestv2/` prefix serves the version 2.x (2.0.x and later) installer, and the `latest/` prefix serves the version 1.8.x installer.
   + For version 2.0.x and later:

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

     For version 1.8.x and earlier:

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

   To install a specific version of the CodeDeploy agent:
   + 

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

   {{bucket-name}} is the name of the Amazon S3 bucket that contains the CodeDeploy Resource Kit files for your region. For example, for the US East (Ohio) Region, replace {{bucket-name}} with `aws-codedeploy-us-east-2`. For a list of bucket names, see [Resource kit bucket names by Region](resource-kit.md#resource-kit-bucket-names).

1.  Run the CodeDeploy agent installation file. 

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

To check that the service is running, run the following command:

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

 If the CodeDeploy agent was just installed and has not been started, then after running the **Get-Service** command, under **Status**, you should see **Start...**:

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

If the CodeDeploy agent is already running, after running the **Get-Service** command, under **Status**, you should see **Running**:

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

## Use a direct link
<a name="codedeploy-agent-operations-install-windows-direct-link"></a>

If the browser security settings on the Windows Server instance provide the permissions (for example, to `https://s3.*.amazonaws.com`), you can use a direct link for your Region to download the CodeDeploy agent and then run the installer manually.

The `latestv2/` prefix serves the version 2.x (2.0.x and later) installer, and the `latest/` prefix serves the version 1.8.x installer.

For version 2.0.x and later, the link is:

```
https://s3.{{region}}.amazonaws.com/aws-codedeploy-{{region}}/latestv2/codedeploy-agent.msi
```

For version 1.8.x and earlier:

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

...where {{region}} is the AWS Region where you're deploying your application.

For example, for version 2.0.x and later:

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

**Important**  
Obtain the `.msi` file from the same Region as your CodeDeploy application. Choosing a different Region may cause `inconsistent region` failures in the `codedeploy-agent-log` file when you run the `.msi` file.

## Use an Amazon S3 copy command
<a name="codedeploy-agent-operations-install-windows-s3-copy"></a>

If the AWS CLI is installed on the instance, you can use the Amazon S3 [cp](https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html) command to download the CodeDeploy agent and then run the installer manually. For information, see [Install the AWS Command Line Interface on Microsoft Windows](https://docs.aws.amazon.com/cli/latest/userguide/awscli-install-windows.html). 

The `latestv2/` prefix serves the version 2.x (2.0.x and later) installer, and the `latest/` prefix serves the version 1.8.x installer.

For version 2.0.x and later, the Amazon S3 command is:

```
aws s3 cp s3://aws-codedeploy-{{region}}/latestv2/codedeploy-agent.msi codedeploy-agent.msi --region {{region}}
```

For version 1.8.x and earlier:

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

...where {{region}} is the AWS Region where you're deploying your application.

For example, for version 2.0.x and later:

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