Error Installing AWS CodeDeploy Agent in Windows Server 2016

Sunday, November 30, 2025
This is a repost from my old blog. First posted in 6/8/2020.

It has been a while since I added an EC2 instance to our CI/CD pipeline. And this time, I need to allow a Windows Server 2016 to receive artifacts from AWS CodeDeploy by installing the agent. And installing the CodeDeploy agent is not straight forward.


I followed the instructions to install using Windows PowerShell:

https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-windows.html#codedeploy-agent-operations-install-windows-powershell


It went smoothly until it tried to start the windows service which failed with the following error message:

Service 'CodeDeploy Host Agent Service' (codedeployagent) failed to start. 
Verify that you have sufficient privileges to start system services

The error message can be found in the log file which is located at: C:\temp\host-agent-install-log.


The following article helps me solving the installation issue:

https://github.com/aws/aws-codedeploy-agent/issues/189


Basically, we need to add Windows Defender exclusions for the installation and execution folders. In my case, it will be:

Add-MpPreference -ExclusionPath ("C:\ProgramData\Amazon\CodeDeploy","$env:windir\Temp")

The following worked in Windows Server 2016 but somehow didn't work in 2019:

Add-MpPreference -ExclusionPath ("C:\temp", "C:\ProgramData\Amazon\CodeDeploy") 

Updates June 18, 2020 The last time I checked, it is no longer an issue in the following AMI: Windows_Server-2016-English-Full-Base-2020.06.10


November 25, 2020 It happened to me again on Windows Server 2019. This time the EC2 is in private subnet, so I also checked the following: