

# Working with the CodeDeploy agent
<a name="codedeploy-agent"></a>

 The AWS CodeDeploy agent is a software package that, when installed and configured on an instance, makes it possible for that instance to be used in CodeDeploy deployments.

AWS supports the latest minor version of the CodeDeploy agent. Currently the latest minor version is 1.8.x.

**Note**  
 The CodeDeploy agent is required only if you deploy to an EC2/On-Premises compute platform. The agent is not required for deployments that use the Amazon ECS or AWS Lambda compute platform. 

A configuration file is placed on the instance when the agent is installed. This file is used to specify how the agent works. This configuration file specifies directory paths and other settings for AWS CodeDeploy to use as it interacts with the instance. You can change some of the configuration options in the file. For information about working with the CodeDeploy agent configuration file, see [CodeDeploy agent configuration reference](reference-agent-configuration.md).

For more information about working with the CodeDeploy agent, such as steps for installing, updating, and verifying versions, see [Managing CodeDeploy agent operations](codedeploy-agent-operations.md).

**Topics**
+ [Operating systems supported by the CodeDeploy agent](#codedeploy-agent-supported-operating-systems)
+ [Communication protocol and port for the CodeDeploy agent](#codedeploy-agent-outbound-port)
+ [Version history of the CodeDeploy agent](#codedeploy-agent-version-history)
+ [Managing the CodeDeploy process](#codedeploy-agent-processes)
+ [Application revision and log file cleanup](#codedeploy-agent-revisions-logs-cleanup)
+ [Files installed by the CodeDeploy agent](#codedeploy-agent-install-files)
+ [Managing CodeDeploy agent operations](codedeploy-agent-operations.md)

## Operating systems supported by the CodeDeploy agent
<a name="codedeploy-agent-supported-operating-systems"></a>

### Supported Amazon EC2 AMI operating systems
<a name="codedeploy-agent-supported-operating-systems-ec2"></a>

The CodeDeploy agent has been tested on the following Amazon EC2 AMI operating systems:
+ Amazon Linux 2023 (ARM, x86)
+ Amazon Linux 2 (ARM, x86)
+ Microsoft Windows Server 2022, 2019
+ Red Hat Enterprise Linux (RHEL) 9.x, 8.x, 7.x
+ Ubuntu Server 22.04 LTS, 20.04 LTS, 18.04 LTS, 16.04 LTS

The CodeDeploy agent is available as open source for you to adapt to your needs. It can be used with other Amazon EC2 AMI operating systems. For more information, go to the [CodeDeploy agent](https://github.com/aws/aws-codedeploy-agent) repository in GitHub.

### Supported on-premises operating systems
<a name="codedeploy-agent-supported-operating-systems-on-premises"></a>

The CodeDeploy agent has been tested on the following on-premises operating systems:
+ Microsoft Windows Server 2022, 2019
+ Red Hat Enterprise Linux (RHEL) 9.x, 8.x, 7.x
+ Ubuntu Server 22.04 LTS, 20.04 LTS

The CodeDeploy agent is available as open source for you to adapt to your needs. It can be used with other on-premises instance operating systems. For more information, go to the [CodeDeploy agent](https://github.com/aws/aws-codedeploy-agent) repository in GitHub.

## Communication protocol and port for the CodeDeploy agent
<a name="codedeploy-agent-outbound-port"></a>

The CodeDeploy agent communicates outbound using HTTPS over port 443.

When the CodeDeploy agent runs on an EC2 instance, it will use the [EC2 metadata](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html) endpoint to retrieve instance related information. Find out more about [limiting and granting instance metadata service access](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html#instance-metadata-limiting-access).

## Version history of the CodeDeploy agent
<a name="codedeploy-agent-version-history"></a>

Your instances must be running a supported version of the CodeDeploy agent. The current minimum supported version is 1.8.x.

**Note**  
We recommend using the latest version of the CodeDeploy agent. If you’re having issues, update to the latest version before contacting AWS Support. For upgrade information, see [Update the CodeDeploy agent](codedeploy-agent-operations-update.md).

The following table lists all releases of the CodeDeploy agent and the features and enhancements included with each version.


| Version | Release date | Details | 
| --- | --- | --- | 
|  1.8.1  |  February 3, 2026  |  **Fixed**: S3 endpoint bugfix. **Added**: Sectigo CA certificate to Windows CA list.  | 
|  1.8.0  |  July 31, 2025  |  **Changed**: Upgraded the bundled Ruby to 3.2 in the CodeDeploy agent for Windows.  | 
|  1.7.1  |  November 14, 2024  |  **Changed**: Updated dependencies for security patches.  | 
|  1.7.0  |  March 6, 2024  |  **Added**: A `:disable_imds_v1:` configuration setting to the CodeDeploy agent configuration file. Use this setting to disable the fallback to IMDSv1 when IMDSv2 errors occur. Defaults to `false` (enable the fallback). For more information, see [CodeDeploy agent configuration reference](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-agent-configuration.html). **Added**: Support for the Red Hat Enterprise Linux 9 (RHEL 9) operating system. **Added**: Support for Ruby versions 3.1 and 3.2 on Ubuntu Server. **Fixed**: The CodeDeploy agent now generates a user-friendly error if the CodeDeploy agent configuration file fails to load. **Changed**: Upgraded Ruby to 2.7.8-1 in the CodeDeploy agent for Windows.  | 
|  1.6.0  |  March 30, 2023  |  **Added**: Support for Ruby 3.1, 3.2. **Added**: Support for Amazon Linux 2023. **Added**: Support for Windows Server 2022. **Changed**: The default setting of `verbose` is now `false` for Windows Server instances. To continue to print debug messages in log files on Windows, you must set `verbose` to `true`. **Removed**: Support for Windows Server 2016 and Windows Server 2012 R2. **Removed**: Support for Amazon Linux 2018.03.x.  | 
|  1.5.0  |  March 3, 2023  |  **Added**: Support for Ruby 3. **Added**: Support for Ubuntu 22.04. **Fixed**: An issue where restarting the CodeDeploy agent soon after startup would lead to the agent hanging. **Changed**: The CodeDeploy agent now fails a host deployment on agent startup if the agent service restarts unexpectedly while running a hook script. This fix lets you avoid waiting for the 70-minute timeout period before retrying a deployment. **Deprecation notice**: CodeDeploy agent 1.5.0 is the last release to support Windows Server 2016 and Windows Server 2012 R2. **Removed:** Support for the CodeDeploy agent on Ubuntu 14.04 LTS, Windows Server 2008 R2, and Windows Server 2008 R2 32-bit.  | 
|  1.4.1  |  December 6, 2022  |  **Fixed**: Security vulnerability related to logging. **Enhancement**: Improved logging when polling for the host command.  | 
|  1.4.0  |  August 31, 2022  |  **Added**: Support for Red Hat Enterprise Linux 8.  **Added**: Support for long file paths on the CodeDeploy agent for Windows. To enable long file paths, you'll need to set the appropriate Windows registry key and then restart your agent. For more information, see [Long file paths cause "No such file or directory" errors](troubleshooting-deployments.md#troubleshooting-long-file-paths). **Fixed**: An issue with the unzip operation when the disk was full. The CodeDeploy agent now detects the unzip's [exit code 50](https://linux.die.net/man/1/unzip) indicating a full disk, removes partially extracted files, and raises an exception to post a failure to the CodeDeploy server. The error message is visible as a lifecycle event error message, and the host-level deployment will stop without being stuck or timing-out. **Fixed**: An issue that would cause the agent to fail. **Fixed**: An issue where hooks would time out during an edge-case race condition. Hooks with no scripts will now continue and no longer cause failures or timeouts.  **Changed**: The `update` script from the CodeDeploy agent's `bin` directory was removed because it is no longer used. **Changed**: The CodeDeploy agent for Windows Server now bundles Ruby 2.7. **Changed**: New environment variables were added, to be used by hook scripts depending on the source of the deployment bundle (Amazon S3 or GitHub).  For more information, see [Environment variable availability for hooks](reference-appspec-file-structure-hooks.md#reference-appspec-file-structure-environment-variable-availability).  **Deprecation notice**: CodeDeploy agent 1.4.0 is the last release that will include installers for 32-bit Windows Server. **Deprecation notice**: CodeDeploy agent 1.4.0 is the last release that will support Windows Server 2008 R2. **Removed**: Support for the CodeDeploy agent on the following Amazon EC2 AMIs: Amazon Linux 2014.09, 2016.03, 2016.09, and 2017.03.   | 
|  1.3.2  |  May 6, 2021  |   CodeDeploy agent 1.3.2 addresses [CVE-2018-1000201](https://nvd.nist.gov/vuln/detail/CVE-2018-1000201) which affects Windows hosts running the agent. The CVE cites ruby-ffi, which is a dependency of the CodeDeploy agent. If your agent was installed with Amazon EC2 Systems Manager (SSM) and is set to update automatically, no action is required. Otherwise, action is required to manually update the agent. To upgrade the agent follow the instructions in [Update the CodeDeploy agent on Windows Server](https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-update-windows.html).   **Fixed**: An issue when installing the CodeDeploy agent on Ubuntu 20.04 and later. **Fixed**: An intermittent issue that occurred when extracting compressed files because relative paths weren't being handled correctly. **Added**: Support for [AWS PrivateLink and VPC endpoints](https://docs.aws.amazon.com//vpc/latest/userguide/endpoint-services-overview.html) for Windows instances. **Added**: AppSpec file improvements, as described below. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent.html) **Upgraded**: CodeDeploy now uses the AWS SDK for Ruby 3.0.  | 
|  1.3.1  |  December 22, 2020  |  **Fixed**: 1.3.0 issue that prevented on-premises instances from starting.  | 
|  1.3.0  |  November 10, 2020  |   This version is deprecated.  **Fixed**: Removed an expired certificate that was no longer used. **Fixed**: Removed the prompt message from the agent uninstall script used by AWS Systems Manager, making it easier to downgrade a host or fleet to a previous version of the agent.  | 
|  1.2.1  |  September 23, 2020  |  **Changed**: Upgraded AWS SDK for Ruby dependency from v2 to v3. **Added**: Support for IMDSv2. Includes a silent fallback to IMDSv1 if IMDSv2 http requests fail. **Changed**: Updated Rake and Rubyzip dependencies for security patches. **Fixed**: Ensure that an empty PID file will return a status of `No CodeDeploy Agent Running` and clean up the PID file on agent start.  | 
|  1.1.2  |  August 4, 2020  |  **Added**: Support for Ubuntu Server 19.10 and 20.04. **Note**: : Version 19.10 reached its end-of-life date and is no longer supported by Ubuntu or CodeDeploy. **Added**: Memory efficiency improvements for Linux and Ubuntu to release reserved memory more timely. **Added**: Compatibility with Windows Server "silent-cleanup" which was causing the agent to be unresponsive in some cases. **Added**: Ignore non-empty directories during cleanup to avoid failures on deployment. **Added**: Support for AWS Local Zone in Los Angeles (LA). **Added**: Extract AZ from instance metadata to provide compatibility for AWS Local Zones. **Added**: Users can now provide their archive in subdirectories and aren't required to store it in the root directory. **Added**: Detected an issue with Rubyzip that could result in memory leaks. Updated the unzip command to first attempt to use a system-installed unzip utility before using Rubyzip. **Added**: `:enable_auth_policy:` as an agent configuration setting. **Changed**: Unzip warnings are now ignored so deployments will continue.  | 
|  1.1.0  |  June 30, 2020  |  **Changed**: Versioning of the CodeDeploy agent now follows the Ruby standard versioning convention. **Added**: New parameter to the install and update command to allow installation of specific agent version from the command line. **Removed**: Removed the CodeDeploy agent Auto Updater for Linux and Ubuntu. To configure automatic updates of the CodeDeploy agent, see [Install the CodeDeploy agent using AWS Systems Manager](https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-ssm.html).  | 
|  1.0.1.1597  |  November 15, 2018  |  **Enhancement**: CodeDeploy supports Ubuntu 18.04. **Enhancement**: CodeDeploy supports Ruby 2.5. **Enhancement**: CodeDeploy supports FIPS endpoints. For more information about FIPS endpoints, see [FIPS 140-2 overview](https://aws.amazon.com/compliance/fips/). For endpoints that can be used with CodeBuild, see [CodeDeploy regions and endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html#codedeploy_region).  | 
|  1.0.1.1518  |  June 12, 2018  |  **Enhancement**: Fixed an issue that caused an error when the CodeDeploy agent is closed while it is accepting poll requests. **Enhancement**: Added a deployment tracking feature that prevents the CodeDeploy agent from being closed when a deployment is in progress. **Enhancement**: Improved performance when deleting files.  | 
|  1.0.1.1458  |  March 6, 2018  |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Enhancement**: Improved certificate validations to support more trusted authorities. **Enhancement**: Fixed an issue that caused the local CLI to fail during a deployment that includes a BeforeInstall lifecycle event. **Enhancement**: Fixed an issue that might cause an active deployment to fail when the CodeDeploy agent is updated.  | 
|  1.0.1.1352  |  November 16, 2017  |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Feature**: Introduced a new feature for testing and debugging an EC2/On-Premises deployment on a local machine or instance where the CodeDeploy agent is installed.  | 
|  1.0.1.1106  |  May 16, 2017  |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Feature**: Introduced new support for handling content in a target location that wasn't part of the application revision from the most recent successful deployment. Deployments options for existing content now include retaining the content, overwriting the content, or failing the deployment.  **Enhancement**: Made the CodeDeploy agent compatible with version 2.9.2 of the AWS SDK for Ruby (aws-sdk-core 2.9.2).  | 
|  1.0.1.1095  |  March 29, 2017  |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Enhancement**: Introduced support for the CodeDeploy agent in the China (Beijing) Region. **Enhancement**: Enabled Puppet to run on Windows Server instances when invoked by a lifecycle event hook. **Enhancement**: Improved the handling of `untar` operations.  | 
| 1.0.1.1067 | January 6, 2017 |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Enhancement**: Revised many error messages to include more specific causes for deployment failures. **Enhancement**: Fixed an issue that prevented the CodeDeploy agent from identifying the correct application revision to deploy during some deployments. **Enhancement**: Reverted the usage of `pushd` and `popd` before and after the `untar` operation.  | 
| 1.0.1.1045 | November 21, 2016 |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Enhancement**: Made the CodeDeploy agent compatible with version 2.6.11 of the AWS SDK for Ruby (aws-sdk-core 2.6.11).   | 
| 1.0.1.1037 | October 19, 2016 |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. The CodeDeploy agent for Amazon Linux, RHEL, and Ubuntu Server instances has been updated with the following change. For Windows Server instances, the latest version remains 1.0.1.998. **Enhancement**: The agent can now determine which version of Ruby is installed on an instance so it can invoke the `codedeploy-agent` script using that version.  | 
| 1.0.1.1011.1 | August 17, 2016 |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Enhancement**: Removed the changes introduced by version 1.0.1.1011 due to issues with shell support. This version of the agent is functionally equivalent to version 1.0.1.998 released on July 11, 2016. | 
| 1.0.1.1011 | August 15, 2016 |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. The CodeDeploy agent for Amazon Linux, RHEL, and Ubuntu Server instances has been updated with the following changes. For Windows Server instances, the latest version remains 1.0.1.998.**Feature**: Added support for invoking the CodeDeploy agent using the bash shell on operating systems where the systemd init system is in use.Enhancement: Enabled support for all versions of Ruby 2.x in the CodeDeploy agent and the CodeDeploy agent updater. Updated CodeDeploy agents are no longer dependent on Ruby 2.0 only. (Ruby 2.0 is still required for deb and rpm versions of the CodeDeploy agent installer.) | 
| 1.0.1.998 | July 11, 2016 |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Enhancement**: Fixed support for running the CodeDeploy agent with user profiles other than *root*. The variable named `USER` is replaced by `CODEDEPLOY_USER` to avoid conflicts with environmental variables.  | 
| 1.0.1.966 | June 16, 2016 |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Feature**: Introduced support for running the CodeDeploy agent with user profiles other than *root*. **Enhancement**: Fixed support for specifying the number of application revisions you want the CodeDeploy agent to archive for a deployment group. **Enhancement**: Made the CodeDeploy agent compatible with version 2.3 of the AWS SDK for Ruby (aws-sdk-core 2.3).  **Enhancement**: Fixed issues with UTF-8 encoding during deployments. **Enhancement**: Improved accuracy when identifying process names.  | 
| 1.0.1.950 | March 24, 2016 |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Feature**: Added installation proxy support. **Enhancement**: Updated the installation script to not download the CodeDeploy agent if the latest version is already installed.  | 
| 1.0.1.934 | February 11, 2016 |  **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Feature**: Introduced support for specifying the number of application revisions you want the CodeDeploy agent to archive for a deployment group.   | 
| 1.0.1.880 | January 11, 2016 | **Note**: This version is no longer supported and might cause deployments to fail. **Enhancement**: Made the CodeDeploy agent compatible with version 2.2 of the AWS SDK for Ruby (aws-sdk-core 2.2). Version 2.1.2 is still supported.  | 
| 1.0.1.854 | November 17, 2015 | **Note**: This version is no longer supported. If you use this version, your deployments might fail. **Feature**: Introduced support for the SHA-256 hash algorithm.  **Feature**: Introduced version tracking support in `.version` files. **Feature**: Made the deployment group ID available through the use of an environment variable. **Enhancement**: Added support for monitoring CodeDeploy agent logs using [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/WhatIsCloudWatchLogs.html).  | 

For related information, see the following:
+ [Determine the version of the CodeDeploy agent](codedeploy-agent-operations-version.md)
+ [Install the CodeDeploy agent](codedeploy-agent-operations-install.md)

For a history of CodeDeploy agent versions, see the [Release repository on GitHub](https://github.com/aws/aws-codedeploy-agent/releases).

## Managing the CodeDeploy process
<a name="codedeploy-agent-processes"></a>

All Linux distributions of the CodeDeploy agent (rpm and deb) use [systemd](https://systemd.io/) by default to manage the agent process.

However, both the rpm and deb distributions ship with startup scripts that reside at `/etc/init.d/codedeploy-agent`. Depending on which distribution you are using, when using a command such as `sudo service codedeploy-agent restart`, the scripts at `/etc/init.d` may be run to launch the agent process instead of allowing `systemd` to manage the process. Running scripts at `/etc/init.d` is undesirable.

To prevent this issue, for systems that support `systemd` we recommend using the `systemctl` utility for any agent operations instead of using the `service` command.

For example, to restart the CodeDeploy agent use `sudo systemctl restart codedeploy-agent` instead of the equivalent command with the `service` utility.

## Application revision and log file cleanup
<a name="codedeploy-agent-revisions-logs-cleanup"></a>

The CodeDeploy agent archives revisions and log files on instances. The CodeDeploy agent cleans up these artifacts to conserve disk space.

**Application revision deployment logs**: You can use the **:max\$1revisions:** option in the agent configuration file to specify the number of application revisions to archive by entering any positive integer. CodeDeploy also archives the log files for those revisions. All others are deleted, with the exception of the log file of the last successful deployment. That log file is always retained, even if the number of failed deployments exceeds the number of retained revisions. If no value is specified, CodeDeploy retains the five most recent revisions in addition to the currently deployed revision. 

**CodeDeploy logs**: For Amazon Linux, Ubuntu Server, and RHEL instances, the CodeDeploy agent rotates the log files under the `/var/log/aws/codedeploy-agent` folder. The log file is rotated at 00:00:00 (instance time) daily. Log files are deleted after seven days. The naming pattern for rotated log files is `codedeploy-agent.YYYYMMDD.log`.

## Files installed by the CodeDeploy agent
<a name="codedeploy-agent-install-files"></a>

The CodeDeploy agent stores revisions, deployment history, and deployment scripts in its root directory on an instance. The default name and location of this directory is:

`'/opt/codedeploy-agent/deployment-root'` for Amazon Linux, Ubuntu Server, and RHEL instances.

`'C:\ProgramData\Amazon\CodeDeploy'` for Windows Server instances. 

You can use the **root\$1dir** setting in the CodeDeploy agent configuration file to configure the directory's name and location. For more information, see [CodeDeploy agent configuration reference](reference-agent-configuration.md).

The following is an example of the file and directory structure under the root directory. The structure assumes there are N number of deployment groups, and each deployment group contains N number of deployments. 

```
|--deployment-root/
|-- deployment group 1 ID 
|    |-- deployment 1 ID 
|    |    |-- Contents and logs of the deployment's revision
|    |-- deployment 2 ID
|    |    |-- Contents and logs of the deployment's revision
|    |-- deployment N ID
|    |    |-- Contents and logs of the deployment's revision
|-- deployment group 2 ID
|    |-- deployment 1 ID
|    |    |-- bundle.tar
|    |    |-- deployment-archive
|    |    |    | -- contents of the deployment's revision
|    |    |-- logs
|    |    |    | -- scripts.log     
|    |-- deployment 2 ID
|    |    |-- bundle.tar
|    |    |-- deployment-archive
|    |    |    | -- contents of the deployment's revision
|    |    |-- logs
|    |    |    | -- scripts.log     
|    |-- deployment N ID
|    |    |-- bundle.tar
|    |    |-- deployment-archive
|    |    |    | -- contents of the deployment's revision
|    |    |-- logs
|    |    |    | -- scripts.log     
|-- deployment group N ID
|    |-- deployment 1 ID
|    |    |-- Contents and logs of the deployment's revision
|    |-- deployment 2 ID
|    |    |-- Contents and logs of the deployment's revision
|    |-- deployment N ID
|    |    |-- Contents and logs of the deployment's revision
|-- deployment-instructions
|    |-- [deployment group 1 ID]_cleanup
|    |-- [deployment group 2 ID]_cleanup
|    |-- [deployment group N ID]_cleanup
|    |-- [deployment group 1 ID]_install.json
|    |-- [deployment group 2 ID]_install.json
|    |-- [deployment group N ID]_install.json
|    |-- [deployment group 1 ID]_last_successful_install
|    |-- [deployment group 2 ID]_last_successful_install
|    |-- [deployment group N ID]_last_successful_install
|    |-- [deployment group 1 ID]_most_recent_install
|    |-- [deployment group 2 ID]_most_recent_install
|    |-- [deployment group N ID]_most_recent_install
|-- deployment-logs
|    |-- codedeploy-agent-deployments.log
```


+  **Deployment Group ID** folders represent each of your deployment groups. A deployment group directory's name is its ID (for example, `acde1916-9099-7caf-fd21-012345abcdef`). Each deployment group directory contains one subdirectory for each attempted deployment in that deployment group. 

   You can use the [batch-get-deployments](https://docs.aws.amazon.com/cli/latest/reference/deploy/batch-get-deployments.html) command to find a deployment group ID.
+  **Deployment ID** folders represent each deployment in a deployment group. Each deployment directory's name is its ID. Each folder contains:
  +  **bundle.tar**, a compressed file with the contents of the deployment's revision. Use a zip decompression utility if you want to view the revision.
  +  **deployment-archive**, a directory that contains the contents of the deployment's revision. 
  +  **logs**, a directory that contains a `scripts.log` file. This file lists the output of all scripts specified in the deployment's AppSpec file. 

   If you want to find the folder for a deployment but don't know its deployment ID or deployment group ID, you can use the [AWS CodeDeploy console](https://console.aws.amazon.com/codedeploy) or the AWS CLI to find them. For more information, see [View CodeDeploy deployment details](deployments-view-details.md). 

   The default maximum number of deployments that can be archived in a deployment group is five. When that number is reached, future deployments are archived and the oldest archive is deleted. You can use the **max\$1revisions** setting in the CodeDeploy agent configuration file to change the default. For more information, see [CodeDeploy agent configuration reference](reference-agent-configuration.md). 
**Note**  
 If you want to recover hard disk space used by archived deployments, update the **max\$1revisions** setting to a low number, such as 1 or 2. The next deployment deletes archived deployments so that the number is equal to the you specified. 
+  **deployment-instructions** contains four text files for each deployment group: 
  + **[Deployment Group ID]-cleanup**, a text file with an undo verison of each command that is run during a deployment. An example file name is `acde1916-9099-7caf-fd21-012345abcdef-cleanup`. 
  + **[Deployment Group ID]-install.json**, a JSON file created during the most recent deployment. It contains the commands run during the deployment. An example file name is `acde1916-9099-7caf-fd21-012345abcdef-install.json`.
  + **[Deployment Group ID]\$1last\$1successfull\$1install**, a text file that lists the archive directory of the last successful deployment. This file is created when the CodeDeploy agent has copied all files in the deployment application to the instance. It is used by the CodeDeploy agent during the next deployment to determine which `ApplicationStop` and `BeforeInstall` scripts to run. An example file name is `acde1916-9099-7caf-fd21-012345abcdef_last_successfull_install`.
  + **[Deployment Group ID]\$1most\$1recent\$1install**, a text file that lists the name of the archive directory of the most recent deployment. This file is created when the files in the deployment are successfully downloaded. The [deployment group ID]\$1last\$1successfull\$1install file is created after this file, when the downloaded files are copied to their final destination. An example file name is `acde1916-9099-7caf-fd21-012345abcdef_most_recent_install`.
+  **deployment-logs** contains the following log files: 
  +  **codedeploy-agent.yyyymmdd.log** files are created for each day there is a deployment. Each log file contains information about the day's deployments. These log files might be useful for debugging problems like a permissions issue. The log file is initially named `codedeploy-agent.log`. The next day, the date of its deployments is inserted into the file name. For example, if today is January 3, 2018, you can see information about all of today's deployments in `codedeploy-agent.log`. Tomorrow, on January 4, 2018, the log file is renamed `codedeploy-agent.20180103.log`. 
  +  **codedeploy-agent-deployments.log** compiles the contents of `scripts.log` files for each deployment. The `scripts.log` files are located in the `logs` subfolder under each `Deployment ID` folder. The entries in this file are preceded by a deployment ID. For example, "`[d-ABCDEF123]LifecycleEvent - BeforeInstall`" might be written during a deployment with an ID of `d-ABCDEF123`. When `codedeploy-agent-deployments.log` reaches its maximum size, the CodeDeploy agent continues to write to it while deleting old content. 

# Managing CodeDeploy agent operations
<a name="codedeploy-agent-operations"></a>

The instructions in this section show you how to install, uninstall, reinstall, or update the CodeDeploy agent and how to verify the CodeDeploy agent is running.

**Topics**
+ [Verify the CodeDeploy agent is running](codedeploy-agent-operations-verify.md)
+ [Determine the version of the CodeDeploy agent](codedeploy-agent-operations-version.md)
+ [Install the CodeDeploy agent](codedeploy-agent-operations-install.md)
+ [Update the CodeDeploy agent](codedeploy-agent-operations-update.md)
+ [Uninstall the CodeDeploy agent](codedeploy-agent-operations-uninstall.md)
+ [Send CodeDeploy agent logs to CloudWatch](codedeploy-agent-operations-cloudwatch-agent.md)

# Verify the CodeDeploy agent is running
<a name="codedeploy-agent-operations-verify"></a>

This section describes commands to run if you suspect the CodeDeploy agent has stopped running on an instance.

**Topics**
+ [Verify the CodeDeploy agent for Amazon Linux or RHEL is running](#codedeploy-agent-operations-verify-linux)
+ [Verify the CodeDeploy agent for Ubuntu Server is running](#codedeploy-agent-operations-verify-ubuntu)
+ [Verify the CodeDeploy agent for Windows Server is running](#codedeploy-agent-operations-verify-windows)

## Verify the CodeDeploy agent for Amazon Linux or RHEL is running
<a name="codedeploy-agent-operations-verify-linux"></a>

To see if the CodeDeploy agent is installed and running, sign in to the instance, and run the following command:

```
systemctl status codedeploy-agent
```

If the command returns an error, the CodeDeploy agent is not installed. Install it as described in [Install the CodeDeploy agent for Amazon Linux or RHEL](codedeploy-agent-operations-install-linux.md).

If the CodeDeploy agent is installed and running, you should see a message like `The AWS CodeDeploy agent is running`.

If you see a message like `error: No AWS CodeDeploy agent running`, start the service and run the following two commands, one at a time:

```
systemctl start codedeploy-agent
```

```
systemctl status codedeploy-agent
```

## Verify the CodeDeploy agent for Ubuntu Server is running
<a name="codedeploy-agent-operations-verify-ubuntu"></a>

To see if the CodeDeploy agent is installed and running, sign in to the instance, and run the following command:

```
systemctl status codedeploy-agent
```

If the command returns an error, the CodeDeploy agent is not installed. Install it as described in [Install the CodeDeploy agent for Ubuntu Server](codedeploy-agent-operations-install-ubuntu.md).

If the CodeDeploy agent is installed and running, you should see a message like `The AWS CodeDeploy agent is running`.

If you see a message like `error: No AWS CodeDeploy agent running`, start the service and run the following two commands, one at a time:

```
systemctl start codedeploy-agent
```

```
systemctl status codedeploy-agent
```

## Verify the CodeDeploy agent for Windows Server is running
<a name="codedeploy-agent-operations-verify-windows"></a>

To see if the CodeDeploy agent is installed and running, sign in to the instance, and run the following command:

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

You should see output similar to the following:

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

If the command returns an error, the CodeDeploy agent is not installed. Install it as described in [Install the CodeDeploy agent for Windows Server](codedeploy-agent-operations-install-windows.md).

If `Status` shows anything other than `Running`, start the service with the following command:

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

You can restart the service with the following command:

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

You can stop the service with the following command:

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

# Determine the version of the CodeDeploy agent
<a name="codedeploy-agent-operations-version"></a>

You can determine the version of the CodeDeploy agent running on your instance in two ways.

First, starting with version 1.0.1.854 of the CodeDeploy agent, you can view the version number in a `.version` file on the instance. The following table shows the location and sample version string for each of the supported operating systems.


| Operating system | File location | Sample agent\$1version string | 
| --- | --- | --- | 
| Amazon Linux and Red Hat Enterprise Linux (RHEL) | /opt/codedeploy-agent/.version | OFFICIAL\$11.0.1.854\$1rpm | 
| Ubuntu Server | /opt/codedeploy-agent/.version | OFFICIAL\$11.0.1.854\$1deb | 
| Windows Server | C:\$1ProgramData\$1Amazon\$1CodeDeploy\$1.version | OFFICIAL\$11.0.1.854\$1msi | 

Second, you can run a command on an instance to determine the version of the CodeDeploy agent.

**Topics**
+ [Determine the version on Amazon Linux or RHEL](#codedeploy-agent-operations-version-linux)
+ [Determine the version on Ubuntu Server](#codedeploy-agent-operations-version-ubuntu)
+ [Determine the version on Windows Server](#codedeploy-agent-operations-version-windows)

## Determine the version on Amazon Linux or RHEL
<a name="codedeploy-agent-operations-version-linux"></a>

Sign in to the instance and run the following command:

```
sudo yum info codedeploy-agent
```

## Determine the version on Ubuntu Server
<a name="codedeploy-agent-operations-version-ubuntu"></a>

Sign in to the instance and run the following command:

```
sudo dpkg -s codedeploy-agent
```

## Determine the version on Windows Server
<a name="codedeploy-agent-operations-version-windows"></a>

Sign in to the instance and run the following command:

```
sc qdescription codedeployagent
```

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

To use CodeDeploy on EC2 instances or on-premises servers, the CodeDeploy agent must be installed first. We recommend installing and updating the CodeDeploy agent with AWS Systems Manager. For more information about Systems Manager, see [What is AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html). You can set up installation and scheduled updates of the CodeDeploy agent with Systems Manager in the console when you create your deployment groups.

You can also install the CodeDeploy agent directly from an S3 bucket with the command line.

For the recommended version to install, see [Version history of the CodeDeploy agent](codedeploy-agent.md#codedeploy-agent-version-history).

**Topics**
+ [Install the CodeDeploy agent using AWS Systems Manager](codedeploy-agent-operations-install-ssm.md)
+ [Install the CodeDeploy agent using the command line](codedeploy-agent-operations-install-cli.md)

# Install the CodeDeploy agent using AWS Systems Manager
<a name="codedeploy-agent-operations-install-ssm"></a>

You can use the AWS Management Console or the AWS CLI to install the CodeDeploy agent to your Amazon EC2 or on-premises instances by using AWS Systems Manager. You can choose to install a specific version or choose to always install the latest version of the agent. For more information about AWS Systems Manager, see [What is AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html). 

 Using AWS Systems Manager is the recommended method for installing and updating the CodeDeploy agent. You can also install the CodeDeploy agent from an Amazon S3 bucket. For information about using an Amazon S3 download link, see [Install the CodeDeploy agent using the command line](codedeploy-agent-operations-install-cli.md). 

**Topics**
+ [Prerequisites](#install-codedeploy-agent-prereqs)
+ [Install the CodeDeploy agent](#download-codedeploy-agent-on-EC2-Instance)

## Prerequisites
<a name="install-codedeploy-agent-prereqs"></a>

Follow the steps in [Getting started with CodeDeploy](getting-started-codedeploy.md) to set up IAM permissions and the AWS CLI.

If installing the CodeDeploy agent on an on-premises server with Systems Manager, you must register your on-premises server with Amazon EC2 Systems Manager. For more information, see [ Setting up Systems Manager in hybrid environments](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-managedinstances.html) in the *AWS Systems Manager User Guide*.

## Install the CodeDeploy agent
<a name="download-codedeploy-agent-on-EC2-Instance"></a>

Before you can use Systems Manager to install the CodeDeploy agent, you must make sure that the instance is configured correctly for Systems Manager.

### Installing or updating the SSM agent
<a name="update-SSM-Agent-EC2instance"></a>

On an Amazon EC2 instance, the CodeDeploy agent requires that the instance is running version 2.3.274.0 or later. Before you install the CodeDeploy agent, update or install SSM agent on the instance if you haven't already done so. 

The SSM agent comes preinstalled on some Amazon EC2 AMIs provided by AWS. For more information, see [Amazon Machine Images (AMIs) with SSM agent preinstalled](https://docs.aws.amazon.com/systems-manager/latest/userguide/ami-preinstalled-agent.html).

**Note**  
Make sure that the instance's operating system is also supported by the CodeDeploy agent. For more information, see [Operating systems supported by the CodeDeploy agent](codedeploy-agent.md#codedeploy-agent-supported-operating-systems).

For information about installing or updating SSM agent on an instance running Linux, see [Installing and configuring the SSM agent on Linux instances](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-install-ssm-agent.html) in the *AWS Systems Manager User Guide*.

For information about installing or updating SSM agent on an instance running Windows Server, see [ Installing and configuring SSM agent on Windows instances](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-install-ssm-win.html) in the *AWS Systems Manager User Guide*.

### (Optional) Verify Systems Manager prerequisites
<a name="install-codedeploy-agent-minimum-requirements"></a>

Before you use Systems Manager Run Command to install the CodeDeploy agent, verify that your instances meet the minimum Systems Manager requirements. For more information, see [Setting up AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-setting-up.html) in the *AWS Systems Manager User Guide*.

### Install the CodeDeploy agent
<a name="install-codedeploy-agent-EC2"></a>

With SSM, you can install the CodeDeploy once or set up a schedule to install new versions.

 To install the CodeDeploy agent, choose the `AWSCodeDeployAgent` package while you follow the steps in [Install or update packages with AWS Systems Manager distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor-working-with-packages-deploy.html). 

# Install the CodeDeploy agent using the command line
<a name="codedeploy-agent-operations-install-cli"></a>

**Note**  
We recommend installing the CodeDeploy agent with AWS Systems Manager to be able to configure scheduled updates of the agent. For more information, see [Install the CodeDeploy agent using AWS Systems Manager](codedeploy-agent-operations-install-ssm.md).

Use the following topics to install and run the CodeDeploy agent using the command line.

**Topics**
+ [Install the CodeDeploy agent for Amazon Linux or RHEL](codedeploy-agent-operations-install-linux.md)
+ [Install the CodeDeploy agent for Ubuntu Server](codedeploy-agent-operations-install-ubuntu.md)
+ [Install the CodeDeploy agent for Windows Server](codedeploy-agent-operations-install-windows.md)

# Install the CodeDeploy agent for Amazon Linux or RHEL
<a name="codedeploy-agent-operations-install-linux"></a>

Sign in to the instance, and run the following commands, one at a time. Running the command `sudo yum update` first is considered best practice when using `yum` to install packages, but you can skip it if you do not wish to update all of your packages.

```
sudo yum update
```

```
sudo yum install ruby
```

```
sudo yum install wget
```

(Optional) To clean the AMI of any previous agent caching information, run the following script:

```
#!/bin/bash
CODEDEPLOY_BIN="/opt/codedeploy-agent/bin/codedeploy-agent"
$CODEDEPLOY_BIN stop
yum erase codedeploy-agent -y
```

Change to your home directory:

```
cd /home/ec2-user
```

**Note**  
In the previous command, `/home/ec2-user` represents the default user name for an Amazon Linux or RHEL Amazon EC2 instance. If your instance was created using a custom AMI, the AMI owner might have specified a different default user name. 

Download the CodeDeploy agent installer:

```
wget https://bucket-name.s3.region-identifier.amazonaws.com/latest/install
```

*bucket-name* is the name of the Amazon S3 bucket that contains the CodeDeploy Resource Kit files for your region, and *region-identifier* is the identifier for your region.

For example:

`https://aws-codedeploy-us-east-2.s3.us-east-2.amazonaws.com/latest/install`

For a list of bucket names and region identifiers, see [Resource kit bucket names by Region](resource-kit.md#resource-kit-bucket-names).

Set execute permissions on the `install` file:

```
chmod +x ./install
```

To install the latest version of the CodeDeploy agent:
+ 

  ```
  sudo ./install auto
  ```

To install a specific version of the CodeDeploy agent:
+ List the available versions in your region:

  ```
  aws s3 ls s3://aws-codedeploy-region-identifier/releases/ --region region-identifier | grep '\.rpm$'
  ```
+ Install one of the versions:

  ```
  sudo ./install auto -v releases/codedeploy-agent-version.noarch.rpm
  ```
**Note**  
AWS supports the latest minor version of the CodeDeploy agent. Currently the latest minor version is 1.7.x.

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

```
systemctl status codedeploy-agent
```

If the CodeDeploy agent is installed and running, you should see a message like `The AWS CodeDeploy agent is running`.

If you see a message like `error: No AWS CodeDeploy agent running`, start the service and run the following two commands, one at a time:

```
systemctl start codedeploy-agent
```

```
systemctl status codedeploy-agent
```

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

**Note**  
We recommend installing the CodeDeploy agent with AWS Systems Manager to be able to configure scheduled updates of the agent. For more information, see [Install the CodeDeploy agent using AWS Systems Manager](codedeploy-agent-operations-install-ssm.md).

**To install the CodeDeploy agent on Ubuntu Server**

1. Sign in to the instance.

1. Enter the following commands, one after the other:

   ```
   sudo apt update
   ```

   ```
   sudo apt install ruby-full
   ```

   ```
   sudo apt install wget
   ```

1. Enter the following command:

   ```
   cd /home/ubuntu
   ```

   */home/ubuntu* represents the default user name for an Ubuntu Server instance. If your instance was created using a custom AMI, the AMI owner might have specified a different default user name. 

1. Enter the following command:

   ```
   wget https://bucket-name.s3.region-identifier.amazonaws.com/latest/install
   ```

   *bucket-name* is the name of the Amazon S3 bucket that contains the CodeDeploy Resource Kit files for your region, and *region-identifier* is the identifier for your region.

   For example:

   `https://aws-codedeploy-us-east-2.s3.us-east-2.amazonaws.com/latest/install`

   For a list of bucket names and region identifiers, see [Resource kit bucket names by Region](resource-kit.md#resource-kit-bucket-names).

1. Enter the following command:

   ```
   chmod +x ./install
   ```

1. Do one of the following:
   + To install the latest version of the CodeDeploy agent on any supported version of Ubuntu Server *except* 20.04:

     ```
     sudo ./install auto
     ```
   + To install the latest version of the CodeDeploy agent on Ubuntu Server 20.04:
**Note**  
Writing the output to a temporary log file is a workaround that should be used while we address a known bug with the `install` script on Ubuntu Server 20.04.

     ```
     sudo ./install auto > /tmp/logfile
     ```
   + To install a specific version of the CodeDeploy agent on any supported version of Ubuntu Server *except* 20.04:
     + List the available versions in your region:

       ```
       aws s3 ls s3://aws-codedeploy-region-identifier/releases/ --region region-identifier | grep '\.deb$'
       ```
     + Install one of the versions:

       ```
       sudo ./install auto -v releases/codedeploy-agent-###.deb
       ```
**Note**  
AWS supports the latest minor version of the CodeDeploy agent. Currently the latest minor version is 1.7.x.
   + To install a specific version of the CodeDeploy agent on Ubuntu Server 20.04:
     + List the available versions in your region:

       ```
       aws s3 ls s3://aws-codedeploy-region-identifier/releases/ --region region-identifier | grep '\.deb$'
       ```
     + Install one of the versions:

       ```
       sudo ./install auto -v releases/codedeploy-agent-###.deb > /tmp/logfile
       ```
**Note**  
Writing the output to a temporary log file is a workaround that should be used while we address a known bug with the `install` script on Ubuntu Server 20.04.
**Note**  
AWS supports the latest minor version of the CodeDeploy agent. Currently the latest minor version is 1.7.x.

**To check that the service is running**

1. Enter the following command:

   ```
   systemctl status codedeploy-agent
   ```

   If the CodeDeploy agent is installed and running, you should see a message like `The AWS CodeDeploy agent is running`.

1. If you see a message like `error: No AWS CodeDeploy agent running`, start the service and run the following two commands, one at a time:

   ```
   systemctl start codedeploy-agent
   ```

   ```
   systemctl status codedeploy-agent
   ```

# 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:\Program Data\Amazon\CodeDeploy`. Make sure there are no directory junctions or symlinks on this path.

**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**  
AWS supports the latest minor version of the CodeDeploy agent. Currently the latest minor version is 1.7.x.

   To install the latest version of the CodeDeploy agent:
   + 

     ```
     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 link is:

```
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:

```
https://s3.af-south-1.amazonaws.com/aws-codedeploy-af-south-1/latest/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 Amazon S3 command is:

```
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:

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

# Update the CodeDeploy agent
<a name="codedeploy-agent-operations-update"></a>

You can configure automatic, scheduled updates of the CodeDeploy agent on all supported operating systems using AWS Systems Manager. You can also force updates on all supported operating systems by running a command on an instance.

**Topics**
+ [Update the CodeDeploy agent on Amazon Linux or RHEL](codedeploy-agent-operations-update-linux.md)
+ [Update the CodeDeploy agent on Ubuntu Server](codedeploy-agent-operations-update-ubuntu.md)
+ [Update the CodeDeploy agent on Windows Server](codedeploy-agent-operations-update-windows.md)

# Update the CodeDeploy agent on Amazon Linux or RHEL
<a name="codedeploy-agent-operations-update-linux"></a>

To configure automatic, scheduled updates of the CodeDeploy agent using AWS Systems Manager, follow the steps in [Install the CodeDeploy agent with AWS Systems Manager](https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-ssm.html).

If you want to force an update of the CodeDeploy agent, sign in to the instance, and run the following command:

```
sudo /opt/codedeploy-agent/bin/install auto
```

# Update the CodeDeploy agent on Ubuntu Server
<a name="codedeploy-agent-operations-update-ubuntu"></a>

To configure automatic, scheduled updates of the CodeDeploy agent using AWS Systems Manager, follow the steps in [Install the CodeDeploy agent with AWS Systems Manager](https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-ssm.html).

If you want to force an update of the CodeDeploy agent, sign in to the instance, and run the following command:

```
sudo /opt/codedeploy-agent/bin/install auto
```

# Update the CodeDeploy agent on Windows Server
<a name="codedeploy-agent-operations-update-windows"></a>

You can enable automatic updates of the CodeDeploy agent with AWS Systems Manager. With Systems Manager, you can configure an update schedule for your Amazon EC2 or on-premises instances by creating an association with Systems Manager State Manager. You can also manually update the CodeDeploy agent by uninstalling the current version and installing a newer one.

**Topics**
+ [Set up automatic CodeDeploy agent update with AWS Systems Manager](#codedeploy-agent-operations-update-windows-ssm)
+ [Update the CodeDeploy agent manually](#codedeploy-agent-operations-update-windows-manual)
+ [(Deprecated) Update the CodeDeploy agent with the Windows Server Updater](#codedeploy-agent-operations-update-windows-updater)

## Set up automatic CodeDeploy agent update with AWS Systems Manager
<a name="codedeploy-agent-operations-update-windows-ssm"></a>

To configure Systems Manager and enable automatic updates of the CodeDeploy agent, follow the instructions in [ Install the CodeDeploy agent using AWS Systems Manager](https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-ssm.html).

## Update the CodeDeploy agent manually
<a name="codedeploy-agent-operations-update-windows-manual"></a>

To update the CodeDeploy agent manually, you can install the latest version from the CLI or using Systems Manager. Follow the instructions in [ Install the CodeDeploy agent.](https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install.html) It is recommended that you uninstall older versions of the CodeDeploy agent by following the instructions in [ Uninstall the CodeDeploy agent](https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-uninstall.html).

## (Deprecated) Update the CodeDeploy agent with the Windows Server Updater
<a name="codedeploy-agent-operations-update-windows-updater"></a>

**Note**  
The CodeDeploy agent updater for Windows Server is deprecated and will not update to any version after 1.0.1.1597.

To enable automatic updates of the CodeDeploy agent, install the CodeDeploy agent updater for Windows Server on new or existing instances. The updater checks periodically for new versions. When a new version is detected, the updater uninstalls the current version of the agent, if one is installed, before installing the newest version.

If a deployment is already underway when the updater detects a new version, the deployment continues to completion. If a deployment attempts to start during the update process, the deployment fails.

If you want to force an update of the CodeDeploy agent, follow the instructions in [Install the CodeDeploy agent for Windows Server](codedeploy-agent-operations-install-windows.md).

On Windows Server instances, you can download and install the CodeDeploy agent updater by running Windows PowerShell commands, using a direct download link, or running an Amazon S3 copy command.

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

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

Sign in to the instance, and run the following commands in Windows PowerShell, one at a time:

```
Set-ExecutionPolicy RemoteSigned
```

 If you are prompted to change the execution policy, choose **Y** so Windows PowerShell requires all scripts and configuration files downloaded from the internet be signed by a trusted publisher. 

```
Import-Module AWSPowerShell
```

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

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

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

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

*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).

If you need to troubleshoot an update process error, type the following command to open the CodeDeploy agent updater log file:

```
notepad C:\ProgramData\Amazon\CodeDeployUpdater\log\codedeploy-agent.updater.log
```

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

If the browser security settings on the Windows Server instance provide the required permissions (for example, to ` http://s3.*.amazonaws.com ` ), you can use a direct link to download the CodeDeploy agent updater.

The link is:

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

...where *region* is the AWS Region where you're updating your application.

For example:

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

### Use an Amazon S3 copy command
<a name="codedeploy-agent-operations-update-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 updater 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 Amazon S3 command is:

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

...where *region* is the AWS Region where you're updating your application.

For example:

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

# Uninstall the CodeDeploy agent
<a name="codedeploy-agent-operations-uninstall"></a>

You can remove the CodeDeploy agent from instances when it is no longer needed or when you want to perform a fresh installation.

## Uninstall the CodeDeploy agent from Amazon Linux or RHEL
<a name="codedeploy-agent-operations-uninstall-linux"></a>

To uninstall the CodeDeploy agent, sign in to the instance and run the following command:

```
sudo yum erase codedeploy-agent
```

## Uninstall the CodeDeploy agent from Ubuntu Server
<a name="codedeploy-agent-operations-uninstall-ubuntu"></a>

To uninstall the CodeDeploy agent, sign in to the instance and run the following command:

```
sudo dpkg --purge codedeploy-agent
```

## Uninstall the CodeDeploy agent from Windows Server
<a name="codedeploy-agent-operations-uninstall-windows"></a>

To uninstall the CodeDeploy agent, sign in to the instance and run the following three commands, one at a time:

```
wmic
```

```
product where name="CodeDeploy Host Agent" call uninstall /nointeractive
```

```
exit
```

You can also sign in to the instance, and in **Control Panel**, open **Programs and Features**, choose **CodeDeploy Host Agent**, and then choose **Uninstall**.

# Send CodeDeploy agent logs to CloudWatch
<a name="codedeploy-agent-operations-cloudwatch-agent"></a>

You can send CodeDeploy agent metric and log data to CloudWatch using the [unified CloudWatch agent](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/UseCloudWatchUnifiedAgent.html), or more simply, the CloudWatch agent.

Use the following instructions to install the CloudWatch agent and configure it for use with CodeDeploy agents.

## Prerequisites
<a name="codedeploy-agent-operations-cloudwatch-prerequisites"></a>

Before you begin, complete the following tasks:
+ Install the CodeDeploy agent and make sure it's running. For more information, see [Install the CodeDeploy agent](codedeploy-agent-operations-install.md) and [Verify the CodeDeploy agent is running](codedeploy-agent-operations-verify.md).
+ Install the CloudWatch agent. For more information, see [Installing the CloudWatch agent](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-on-EC2-Instance.html).
+ Add the following permissions to the CodeDeploy IAM instance profile:
  + CloudWatchLogsFullAccess
  + CloudWatchAgentServerPolicy

  For more information on the CodeDeploy instance profile, see [Step 4: Create an IAM instance profile for your Amazon EC2 instances](getting-started-create-iam-instance-profile.md) of [Getting started with CodeDeploy](getting-started-codedeploy.md).

## Configure the CloudWatch agent to collect CodeDeploy logs
<a name="codedeploy-agent-operations-cloudwatch-configure"></a>

You can configure the CloudWatch agent by stepping through a wizard or by manually creating or editing a configuration file.

**To configure the CloudWatch agent using the wizard (Linux)**

1. Run the wizard, as described in [Run the CloudWatch agent configuration wizard](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-cloudwatch-agent-configuration-file-wizard.html#cloudwatch-agent-running-wizard).

1. In the wizard, when asked `Do you want to monitor any log files?` enter **1**.

1. Specify the CodeDeploy agent log file, as follows:

   1. For `Log file path` enter the path for the CodeDeploy log file, for example: **/var/log/aws/codedeploy-agent/codedeploy-agent.log**.

   1. For `Log group name` enter a log group name, for example: **codedeploy-agent-log**.

   1. For `Log stream name` enter a log stream name, for example: **\$1instance\$1id\$1-codedeploy-agent-log**.

1. When asked `Do you want to specify any additional log files?`, enter **1**.

1. Specify the CodeDeploy agent deployment logs, as follows:

   1. For `Log file path` enter the path for the CodeDeploy deployment log file, for example: **/opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log**.

   1. For `Log group name` enter a log group name, for example: **codedeploy-agent-deployment-log**.

   1. For `Log stream name` enter a log stream name, for example: **\$1instance\$1id\$1-codedeploy-agent-deployment-log**.

1. When asked `Do you want to specify any additional log files?`, enter **1**.

1. Specify the CodeDeploy agent updater logs, as follows:

   1. For `Log file path` enter the path for the CodeDeploy updater log file, for example: **/tmp/codedeploy-agent.update.log**.

   1. For `Log group name` enter a log group name, for example: **codedeploy-agent-updater-log**.

   1. For `Log stream name` enter a log stream name, for example: **\$1instance\$1id\$1-codedeploy-agent-updater-log**.

**To configure the CloudWatch agent using the wizard (Windows)**

1. Run the wizard, as described in [Run the CloudWatch agent configuration wizard](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-cloudwatch-agent-configuration-file-wizard.html#cloudwatch-agent-running-wizard).

1. In the wizard, when asked `Do you want to monitor any customized log files?` enter **1**.

1. Specify the CodeDeploy log file, as follows:

   1. For `Log file path` enter the path r the CodeDeploy agent log file, for example: **C:\$1ProgramData\$1Amazon\$1CodeDeploy\$1log\$1codedeploy-agent-log.txt**.

   1. For `Log group name` enter a log group name, for example: **codedeploy-agent-log**.

   1. For `Log stream name` enter a log stream name, for example: **\$1instance\$1id\$1-codedeploy-agent-log**.

1. When asked `Do you want to specify any additional log files?`, enter **1**.

1. Specify the CodeDeploy agent deployment logs, as follows:

   1. For `Log file path` enter the path the CodeDeploy deployment log file, for example: **C:\$1ProgramData\$1Amazon\$1CodeDeploy\$1deployment-logs\$1codedeploy-agent-deployments.log**.

   1. For `Log group name` enter a log group name, for example: **codedeploy-agent-deployment-log**.

   1. For `Log stream name` enter a log stream name, for example: **\$1instance\$1id\$1-codedeploy-agent-deployment-log**.

**To configure the CloudWatch agent by manually creating or editing a configuration file (Linux)**

1. Create or edit the CloudWatch agent configuration file as described in [Manually create or edit the CloudWatch agent configuration file](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html).

1. Make sure that the file is called `/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json` and that it contains the following code:

   ```
   ...
   "logs": {
       "logs_collected": {
           "files": {
               "collect_list": [
                   {
                       "file_path": "/var/log/aws/codedeploy-agent/codedeploy-agent.log",
                       "log_group_name": "codedeploy-agent-log",
                       "log_stream_name": "{instance_id}-agent-log"
                   },
                   {
                       "file_path": "/opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log",
                       "log_group_name": "codedeploy-agent-deployment-log",
                       "log_stream_name": "{instance_id}-codedeploy-agent-deployment-log"
                   },
                   {
                       "file_path": "/tmp/codedeploy-agent.update.log",
                       "log_group_name": "codedeploy-agent-updater-log",
                       "log_stream_name": "{instance_id}-codedeploy-agent-updater-log"
                   }
               ]
           }
       }
   }
   ...
   ```

**To configure the CloudWatch agent by manually creating or editing a configuration file (Windows)**

1. Create or edit the CloudWatch agent configuration file as described in [Manually create or edit the CloudWatch agent configuration file](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html).

1. Make sure that the file is called `C:\ProgramData\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent.json` and that it contains the following code:

   ```
   ...
   "logs": {
           "logs_collected": {
               "files": {
                   "collect_list": [
                       {
                           "file_path": "C:\\ProgramData\\Amazon\\CodeDeploy\\log\\codedeploy-agent-log.txt",
                           "log_group_name": "codedeploy-agent-log",
                           "log_stream_name": "{instance_id}-codedeploy-agent-log"
                       },
                       {
                           "file_path": "C:\\ProgramData\\Amazon\\CodeDeploy\\deployment-logs\\codedeploy-agent-deployments.log",
                           "log_group_name": "codedeploy-agent-deployment-log",
                           "log_stream_name": "{instance_id}-codedeploy-agent-deployment-log"
                       }
                   ]
               },
               ...
           }
       },
   ...
   ```

## Restart the CloudWatch agent
<a name="codedeploy-agent-operations-cloudwatch-restart"></a>

After making your changes, restart the CloudWatch agent as described in [Start the CloudWatch agent](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-on-EC2-Instance-fleet.html#start-CloudWatch-Agent-EC2-fleet).