

# Working with on-premises instances for CodeDeploy
<a name="instances-on-premises"></a>

An on-premises instance is any physical device that is not an Amazon EC2 instance that can run the CodeDeploy agent and connect to public AWS service endpoints. 

Deploying a CodeDeploy application revision to an on-premises instance involves two major steps:
+ **Step 1** – Configure each on-premises instance, register it with CodeDeploy, and then tag it. 
+ **Step 2** – Deploy application revisions to the on-premises instance.
**Note**  
To experiment with creating and deploying a sample application revision to a correctly configured and registered on-premises instance, see [Tutorial: Deploy an application to an on-premises instance with CodeDeploy (Windows Server, Ubuntu Server, or Red Hat Enterprise Linux)](tutorials-on-premises-instance.md). For information about on-premises instances and how they work with CodeDeploy, see [Working with on-premises instances for CodeDeploy](#instances-on-premises).

If you don't want an on-premises instance to be used in deployments anymore, you can remove the on-premises instance tags from the deployment groups. For a more robust approach, remove the on-premises instance tags from the instance. You can also explicitly deregister an on-premises instance so it can no longer be used in any deployments. For more information, see [Managing on-premises instances operations in CodeDeploy](on-premises-instances-operations.md).

The instructions in this section show you how to configure an on-premises instance and then register and tag it with CodeDeploy so it can be used in deployments. This section also describes how to use CodeDeploy to get information about on-premises instances and deregister an on-premises instance after you're no longer planning to deploy to it.

**Topics**
+ [

# Prerequisites for configuring an on-premises instance
](instances-on-premises-prerequisites.md)
+ [Register an on-premises instance](on-premises-instances-register.md)
+ [Managing on-premises instances operations](on-premises-instances-operations.md)

# Prerequisites for configuring an on-premises instance
<a name="instances-on-premises-prerequisites"></a>

The following prerequisites must be met before you can register an on-premises instance.

**Important**  
If you are using the [register-on-premises-instance](https://docs.aws.amazon.com/cli/latest/reference/deploy/register-on-premises-instance.html) command and periodically refreshed temporary credentials generated with the AWS Security Token Service (AWS STS), there are other prerequisites. For information, see [IAM session ARN registration prerequisites](register-on-premises-instance-iam-session-arn.md#register-on-premises-instance-iam-session-arn-prerequisites).

**Device requirements**

The device you want to prepare, register, and tag as an on-premises instance with CodeDeploy must be running a supported operating system. For a list, see [Operating systems supported by the CodeDeploy agent](codedeploy-agent.md#codedeploy-agent-supported-operating-systems).

If your operating system is not supported, the CodeDeploy agent is available as open source for you to adapt to your needs. For more information, see the [CodeDeploy agent](https://github.com/aws/aws-codedeploy-agent) repository in GitHub.

**Outbound communication**

The on-premises instance must be able to connect to public AWS service endpoints to communicate with CodeDeploy.

The CodeDeploy agent communicates outbound using HTTPS over port 443.

**Administrative control**

The local or network account used on the on-premises instance to configure the on-premises instance must be able to run either as `sudo` or `root` (for Ubuntu Server) or as an administrator (for Windows Server).

**IAM permissions**

The IAM identity you use to register the on-premises instance must be granted permissions to complete the registration (and to deregister the on-premises instance, as needed).

In addition to the policy described in [Step 3: Limit the CodeDeploy user's permissions](getting-started-policy.md), make sure the calling IAM identity has the following additional policy attached.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow", 
      "Action": [
        "iam:CreateAccessKey",
        "iam:CreateUser",
        "iam:DeleteAccessKey",
        "iam:DeleteUser",
        "iam:DeleteUserPolicy",
        "iam:ListAccessKeys",
        "iam:ListUserPolicies",
        "iam:PutUserPolicy",
        "iam:GetUser"
      ],
      "Resource": "*"
    }
  ]
}
```

------

For information on how to attach IAM policies, see [Managing IAM policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage.html).

# Register an on-premises instance with CodeDeploy
<a name="on-premises-instances-register"></a>

To register an on-premises instance, you must use an IAM identity to authenticate your requests. You can choose from the following options for the IAM identity and registration method you use:
+ Use an IAM role ARN to authenticate requests. 
  + Use the [register-on-premises-instance](https://docs.aws.amazon.com/cli/latest/reference/deploy/register-on-premises-instance.html) command and periodically refreshed temporary credentials generated with the AWS Security Token Service (AWS STS) to manually configure most registration options. This option offers the highest level of security, because authentication occurs using a temporary token that times out and must be refreshed periodically. This option is recommended for production deployments of any size. For information, see [Use the register-on-premises-instance command (IAM Session ARN) to register an on-premises instance](register-on-premises-instance-iam-session-arn.md).
+ (Not recommended) Use an IAM user ARN to authenticate requests.
  + Use the [register](https://docs.aws.amazon.com/cli/latest/reference/deploy/register.html) command for the most automated registration process. This option should only be used for non-production deployments where security is less of a concern. This option is less secure because it uses static (permanent) credentials for authentication. This option works well for registering a single on-premises instance. For information, see [Use the register command (IAM user ARN) to register an on-premises instance](instances-on-premises-register-instance.md). 
  + Use the [register-on-premises-instance](https://docs.aws.amazon.com/cli/latest/reference/deploy/register-on-premises-instance.html) command to manually configure most registration options. Suitable for registering a small number of on-premises instances. For information, see [Use the register-on-premises-instance command (IAM user ARN) to register an on-premises instance](register-on-premises-instance-iam-user-arn.md). 

**Topics**
+ [

# Use the register-on-premises-instance command (IAM Session ARN) to register an on-premises instance
](register-on-premises-instance-iam-session-arn.md)
+ [

# Use the register command (IAM user ARN) to register an on-premises instance
](instances-on-premises-register-instance.md)
+ [

# Use the register-on-premises-instance command (IAM user ARN) to register an on-premises instance
](register-on-premises-instance-iam-user-arn.md)

# Use the register-on-premises-instance command (IAM Session ARN) to register an on-premises instance
<a name="register-on-premises-instance-iam-session-arn"></a>

For maximum control over the authentication and registration of your on-premises instances, you can use the [register-on-premises-instance](https://docs.aws.amazon.com/cli/latest/reference/deploy/register-on-premises-instance.html) command and periodically refreshed temporary credentials generated with the AWS Security Token Service (AWS STS). A static IAM role for the instance assumes the role of these refreshed AWS STS credentials to perform CodeDeploy deployment operations. 

This method is most useful when you need to register a large number of instances. It allows you to automate the registration process with CodeDeploy. You can use your own identity and authentication system to authenticate on-premises instances and distribute IAM session credentials from the service to the instances for use with CodeDeploy. 

**Note**  
Alternatively, you can use a shared IAM user distributed to all on-premises instances to call the AWS STS [AssumeRole](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) API to retrieve session credentials for on-premises instances. This method is less secure and not recommended for production or mission-critical environments.

Use the information in the following topics to configure an on-premises instance using temporary security credentials generated with AWS STS.

**Topics**
+ [

## IAM session ARN registration prerequisites
](#register-on-premises-instance-iam-session-arn-prerequisites)
+ [

## Step 1: Create the IAM role that on-premises instances will assume
](#register-on-premises-instance-iam-session-arn-1)
+ [

## Step 2: Generate temporary credentials for an individual instance using AWS STS
](#register-on-premises-instance-iam-session-arn-2)
+ [

## Step 3: Add a configuration file to the on-premises instance
](#register-on-premises-instance-iam-session-arn-3)
+ [

## Step 4: Prepare an on-premises instance for CodeDeploy deployments
](#register-on-premises-instance-iam-session-arn-4)
+ [

## Step 5: Register the on-premises instance with CodeDeploy
](#register-on-premises-instance-iam-session-arn-5)
+ [

## Step 6: Tag the on-premises instance
](#register-on-premises-instance-iam-session-arn-6)
+ [

## Step 7: Deploy application revisions to the on-premises instance
](#register-on-premises-instance-iam-session-arn-7)
+ [

## Step 8: Track deployments to the on-premises instance
](#register-on-premises-instance-iam-session-arn-8)

## IAM session ARN registration prerequisites
<a name="register-on-premises-instance-iam-session-arn-prerequisites"></a>

In addition to the prerequisites listed in [Prerequisites for configuring an on-premises instance](instances-on-premises-prerequisites.md), the following additional requirements must be met:

**IAM permissions**

The IAM identity you use to register an on-premises instance must be granted permissions to perform CodeDeploy operations. Make sure the **AWSCodeDeployFullAccess** managed policy is attached to the IAM identity. For information, see [AWS managed policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#aws-managed-policies) in the *IAM User Guide*.

**System to refresh temporary credentials**

If you use an IAM session ARN to register on-premises instances, you must have a system in place to periodically refresh the temporary credentials. Temporary credentials expire after one hour or sooner if a shorter period is specified when the credentials are generated. There are two methods for refreshing the credentials:
+ **Method 1**: Use the identity and authentication system in place in your corporate network with a CRON script that periodically polls the identity and authentication system and copies the latest session credentials to the instance. This enables you to integrate your authentication and identity structure with AWS without needing to make changes to the CodeDeploy agent or service to support authentication types you use in your organization.
+ **Method 2**: Periodically run a CRON job on the instance to call the AWS STS [AssumeRole](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) action and write the session credentials to a file that the CodeDeploy agent can access. This method still requires using an IAM user and copying credentials to the on-premises instance, but you can re-use the same IAM user and credentials across your fleet of on-premises instances. 

**Note**  
Regardless of whether you're using method 1 or 2, you must set up a process to restart the CodeDeploy agent after the temporary session credentials are updated so that the new credentials take effect.

For information about creating and working with AWS STS credentials, see [AWS Security Token Service API Reference](https://docs.aws.amazon.com/STS/latest/APIReference/) and [Using temporary security credentials to request access to AWS resources](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html).

## Step 1: Create the IAM role that on-premises instances will assume
<a name="register-on-premises-instance-iam-session-arn-1"></a>

You can use the AWS CLI or the IAM console to create an IAM role that will be used by your on-premises instances to authenticate and interact with CodeDeploy. 

You only need to create a single IAM role. Each one of your on-premises instances can assume this role to retrieve the temporary security credentials that provide the permissions granted to this role. 

The role you create will require the following permissions to access the files required to install the CodeDeploy agent: 

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Action": [
                "s3:Get*",
                "s3:List*"
            ],
            "Effect": "Allow",
            "Resource": "*"
        }
    ]
}
```

------

We recommend that you restrict this policy to only those Amazon S3 buckets your on-premises instance needs to access. If you restrict this policy, make sure to give access to the Amazon S3 buckets that contain the CodeDeploy agent. Otherwise, an error might occur whenever the CodeDeploy agent is installed or updated on the on-premises instance. For information about controlling access to Amazon S3 buckets, see [Managing access permissions to your Amazon S3 resources](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-access-control.html).

**To create the IAM role**

1. Call the [create-role](https://docs.aws.amazon.com/cli/latest/reference/iam/create-role.html) command using the `--role-name` option to specify a name for the IAM role (for example, `CodeDeployInstanceRole`) and the `--assume-role-policy-document` option to provide the permissions.

   When you create the IAM role for this instance, you might give it the name `CodeDeployInstanceRole` and include the required permissions in a file named `CodeDeployRolePolicy.json`:

   ```
   aws iam create-role --role-name CodeDeployInstanceRole --assume-role-policy-document file://CodeDeployRolePolicy.json
   ```

1. In the output of the call to the **create-role** command, note the value of the ARN field. For example:

   ```
   arn:aws:iam::123456789012:role/CodeDeployInstanceRole
   ```

   You will need the role ARN when you use the AWS STS [AssumeRole](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) API to generate short-term credentials for each instance.

   For more information about creating IAM roles, see [Creating a role to delegate permissions to an AWS service](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html) in *IAM User Guide*.

   For information about assigning permissions to an existing role, see [put-role-policy](https://docs.aws.amazon.com/cli/latest/reference/iam/put-role-policy.html) in [AWS CLI Command Reference](https://docs.aws.amazon.com/cli/latest/reference/).

## Step 2: Generate temporary credentials for an individual instance using AWS STS
<a name="register-on-premises-instance-iam-session-arn-2"></a>

Before you generate the temporary credentials that will be used for registering an on-premises instance, you must create or choose the IAM identity (user or role) that you will generate the temporary credentials for. The `sts:AssumeRole` permission must be included in the policy settings for this IAM identity.

For information about granting `sts:AssumeRole` permissions to an IAM identity, see [Creating a role to delegate permissions to an AWS service](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html) and [AssumeRole](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html).

There are two ways to generate the temporary credentials:
+ Use the [assume-role](https://docs.aws.amazon.com/cli/latest/reference/sts/assume-role.html) command with the AWS CLI. For example:

  ```
  aws sts assume-role --role-arn arn:aws:iam::12345ACCOUNT:role/role-arn --role-session-name session-name
  ```

  Where:
  + *12345ACCOUNT* is the 12-digit account number for your organization.
  + *role-arn* is the ARN of the role to be assumed, which you generated in [Step 1: Create the IAM role that on-premises instances will assume](#register-on-premises-instance-iam-session-arn-1).
  + *session-name* is the name you want to give to the role session you are creating now.
**Note**  
If you use a CRON script that periodically polls the identity and authentication system and copies the latest session credentials to the instance (method 1 for refreshing temporary credentials described in [IAM session ARN registration prerequisites](#register-on-premises-instance-iam-session-arn-prerequisites)), you can instead use any supported AWS SDK to call [AssumeRole](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html).
+ Use a tool provided by AWS.

  The aws-codedeploy-session-helper tool generates AWS STS credentials and writes them to a file you place on the instance. This tool is best suited to method 2 for refreshing temporary credentials described in [IAM session ARN registration prerequisites](#register-on-premises-instance-iam-session-arn-prerequisites). In this method, the aws-codedeploy-session-helper tool is placed on each instance and executes the command using an IAM user’s permissions. Each instance uses the same IAM user’s credentials in conjunction with this tool.

  For more information, see the [aws-codedeploy-session-helper](https://github.com/awslabs/aws-codedeploy-samples/tree/master/utilities/aws-codedeploy-session-helper) GitHub repository.
**Note**  
After you have created the IAM session credentials, place them in any location on the on-premises instance. In the next step, you will configure the CodeDeploy agent to access the credentials in this location.

Before continuing, make sure the system you will use to periodically refresh the temporary credentials is in place. If the temporary credentials are not refreshed, deployments to the on-premises instance will fail. For more information, see "System to refresh temporary credentials" in [IAM session ARN registration prerequisites](#register-on-premises-instance-iam-session-arn-prerequisites).

## Step 3: Add a configuration file to the on-premises instance
<a name="register-on-premises-instance-iam-session-arn-3"></a>

Add a configuration file to the on-premises instance, using root or administrator permissions. This configuration file is used to declare the IAM credentials and the target AWS region to be used for CodeDeploy. The file must be added to a specific location on the on-premises instance. The file must include the IAM temporary session ARN, its secret key ID and secret access key, and the target AWS region. 

**To add a configuration file**

1. Create a file named `codedeploy.onpremises.yml` (for an Ubuntu Server or RHEL on-premises instance) or `conf.onpremises.yml` (for a Windows Server on-premises instance) in the following location on the on-premises instance:
   + For Ubuntu Server: `/etc/codedeploy-agent/conf`
   + For Windows Server: `C:\ProgramData\Amazon\CodeDeploy`

1. Use a text editor to add the following information to the newly created `codedeploy.onpremises.yml` file (Linux) or `conf.onpremises.yml` file (Windows): 

   ```
   ---
   iam_session_arn: iam-session-arn
   aws_credentials_file: credentials-file
   region: supported-region
   ```

   Where:
   + *iam-session-arn* is the IAM session ARN you noted in [Step 2: Generate temporary credentials for an individual instance using AWS STS](#register-on-premises-instance-iam-session-arn-2). 
   + *credentials-file* is the location of the credentials file for the temporary session ARN, as noted in [Step 2: Generate temporary credentials for an individual instance using AWS STS](#register-on-premises-instance-iam-session-arn-2).
   + *supported-region* is one of the regions that CodeDeploy supports, as listed in [Region and endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html#codedeploy_region) in *AWS General Reference*.

## Step 4: Prepare an on-premises instance for CodeDeploy deployments
<a name="register-on-premises-instance-iam-session-arn-4"></a>

**Install and configure the AWS CLI **

Install and configure the AWS CLI on the on-premises instance. (The AWS CLI will be used to download and install the CodeDeploy agent on the on-premises instance.) 

1. To install the AWS CLI on the on-premises instance, follow the instructions in [Getting set up with the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html) in the *AWS Command Line Interface User Guide*.
**Note**  
CodeDeploy commands for working with on-premises instances became available in version 1.7.19 of the AWS CLI. If you have a version of the AWS CLI already installed, you can check its version by calling **aws --version**.

1. To configure the AWS CLI on the on-premises instance, follow the instructions in [Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) in the *AWS Command Line Interface User Guide*.
**Important**  
As you configure the AWS CLI (for example, by calling the **aws configure** command), be sure to specify the secret key ID and secret access key of an IAM user that has, at minimum, the permissions described in [IAM session ARN registration prerequisites](#register-on-premises-instance-iam-session-arn-prerequisites).

**Set the AWS\$1REGION Environment Variable (Ubuntu Server and RHEL Only)**

If you are not running Ubuntu Server or RHEL on your on-premises instance, skip this step and go directly to "Install the CodeDeploy agent ." 

Install the CodeDeploy agent on an Ubuntu Server or RHEL on-premises instance and enable instance to update the CodeDeploy agent whenever a new version becomes available. You do this by setting the `AWS_REGION` environment variable on the instance to the identifier of one of the regions supported by CodeDeploy. We recommend that you set the value to the region where your CodeDeploy applications, deployment groups, and application revisions are located (for example, `us-west-2`). For a list of regions, see [Region and endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html#codedeploy_region) in the *AWS General Reference*.

To set the environment variable, call the following from the terminal:

```
export AWS_REGION=supported-region
```

Where *supported-region* is the region identifier (for example, `us-west-2`).

**Install the CodeDeploy agent**
+ For an Ubuntu Server on-premises instance, follow the instructions in [Install the CodeDeploy agent for Ubuntu Server](codedeploy-agent-operations-install-ubuntu.md), and then return to this page.
+ For a RHEL on-premises instance, follow the instructions in [Install the CodeDeploy agent for Amazon Linux or RHEL](codedeploy-agent-operations-install-linux.md), and then return to this page.
+ For a Windows Server on-premises instance, follow the instructions in [Install the CodeDeploy agent for Windows Server](codedeploy-agent-operations-install-windows.md), and then return to this page.

## Step 5: Register the on-premises instance with CodeDeploy
<a name="register-on-premises-instance-iam-session-arn-5"></a>

The instructions in this step assume you are registering the on-premises instance from the on-premises instance itself. You can register an on-premises instance from a separate device or instance that has the AWS CLI installed and configured.

Use the AWS CLI to register the on-premises instance with CodeDeploy so that it can be used in deployments.

Before you can use the AWS CLI, you will need the ARN of the temporary session credentials you created in [Step 3: Add a configuration file to the on-premises instance](#register-on-premises-instance-iam-session-arn-3). For example, for an instance you identify as `AssetTag12010298EX`:

```
arn:sts:iam::123456789012:assumed-role/CodeDeployInstanceRole/AssetTag12010298EX
```

Call the [register-on-premises-instance](https://docs.aws.amazon.com/cli/latest/reference/deploy/register-on-premises-instance.html) command, specifying:
+  A name that uniquely identifies the on-premises instance (with the `--instance-name` option).
**Important**  
To help identify the on-premises instance, especially for debugging purposes, we strongly recommend that you specify a name that maps to some unique characteristic of the on-premises instance (for example, the session-name of the STS credentials and the serial number or an internal asset identifier, if applicable). If you specify a MAC address as a name, be aware that MAC addresses contain characters that CodeDeploy does not allow, such as colon (:). For a list of allowed characters, see [CodeDeploy quotas](limits.md).
+ The IAM session ARN that you set up to authenticate multiple on-premises instances in [Step 1: Create the IAM role that on-premises instances will assume](#register-on-premises-instance-iam-session-arn-1).

For example:

```
aws deploy register-on-premises-instance --instance-name name-of-instance --iam-session-arn arn:aws:sts::account-id:assumed-role/role-to-assume/session-name
```

Where:
+ *name-of-instance* is the name you use to identify the on-premises instance, such as `AssetTag12010298EX`.
+ *account-id* is the 12-digit account ID for your organization, such as `111222333444`.
+ *role-to-assume* is the name of the IAM role you created for the instance, such as `CodeDeployInstanceRole`.
+ *session-name* is the name of the session role you specified in [Step 2: Generate temporary credentials for an individual instance using AWS STS](#register-on-premises-instance-iam-session-arn-2).

## Step 6: Tag the on-premises instance
<a name="register-on-premises-instance-iam-session-arn-6"></a>

You can use either the AWS CLI or the CodeDeploy console to tag the on-premises instance. (CodeDeploy uses on-premises instance tags to identify the deployment targets during a deployment.)

**To tag the on-premises instance (CLI)**
+ Call the [add-tags-to-on-premises-instances](https://docs.aws.amazon.com/cli/latest/reference/deploy/add-tags-to-on-premises-instances.html) command, specifying:
  + The name that uniquely identifies the on-premises instance (with the `--instance-names` option). 
  + The name of the on-premises instance tag key and tag value you want to use (with the `--tags` option). You must specify both a name and value. CodeDeploy does not allow on-premises instance tags that have values only.

    For example:

    ```
    aws deploy add-tags-to-on-premises-instances --instance-names AssetTag12010298EX --tags Key=Name,Value=CodeDeployDemo-OnPrem
    ```

**To tag the on-premises instance (console)**

1. Sign in to the AWS Management Console and open the CodeDeploy console at [https://console.aws.amazon.com/codedeploy](https://console.aws.amazon.com/codedeploy).
**Note**  
Sign in with the same user that you set up in [Getting started with CodeDeploy](getting-started-codedeploy.md).

1. In the navigation pane, expand **Deploy**, and choose **On-premises instances**.

1. In the list of on-premises instances, choose name of the on-premises instance you want to tag.

1. In the list of tags, select or enter the desired tag key and tag value. After you enter the tag key and tag value, another row appears. You can repeat this for up to 10 tags. To remove a tag, choose **Remove**.

1. After you have added tags, choose **Update Tags**.

## Step 7: Deploy application revisions to the on-premises instance
<a name="register-on-premises-instance-iam-session-arn-7"></a>

You are now ready to deploy application revisions to the registered and tagged on-premises instance. 

You deploy application revisions to on-premises instances in a way that's similar to deploying application revisions to Amazon EC2 instances. For instructions, see [Create a deployment with CodeDeploy](deployments-create.md). These instructions include a link to prerequisites, including creating an application, creating a deployment group, and preparing an application revision. If you need a simple sample application revision to deploy, you can create the one described in [Step 2: Create a sample application revision](tutorials-on-premises-instance-2-create-sample-revision.md) in the [Tutorial: Deploy an application to an on-premises instance with CodeDeploy (Windows Server, Ubuntu Server, or Red Hat Enterprise Linux)](tutorials-on-premises-instance.md).

**Important**  
If you reuse a CodeDeploy service role as part of creating a deployment group that targets on-premises instances, you must include `Tag:get*` to the `Action` portion of the service role's policy statement. For more information, see [Step 2: Create a service role for CodeDeploy](getting-started-create-service-role.md).

## Step 8: Track deployments to the on-premises instance
<a name="register-on-premises-instance-iam-session-arn-8"></a>

After you deploy an application revision to registered and tagged on-premises instances, you can track the deployment's progress.

You track deployments to on-premises instances in a way that's similar to tracking deployments to Amazon EC2 instances. For instructions, see [View CodeDeploy deployment details](deployments-view-details.md).

# Use the register command (IAM user ARN) to register an on-premises instance
<a name="instances-on-premises-register-instance"></a>

**Important**  
Registering an instance using an IAM user is not recommended because it uses static (permanent) credentials for authentication. For improved security, we recommend registering an instance using temporary credentials for authentication. For more information, see [Use the register-on-premises-instance command (IAM Session ARN) to register an on-premises instance](register-on-premises-instance-iam-session-arn.md).

**Important**  
Make sure you have a plan in place to rotate the IAM user's access keys (permanent credentials). For more information, see [Rotating access keys](https://docs.aws.amazon.com//IAM/latest/UserGuide/id_credentials_access-keys.html#Using_RotateAccessKey).

This section describes how to configure an on-premises instance and register and tag it with CodeDeploy with the least amount of effort. The **register** command is most useful when you are working with single or small fleets of on-premises instances. You can use the **register** command only when you are using an IAM user ARN to authenticate an instance. You cannot use the **register** command with an IAM session ARN for authentication.

When you use the **register** command, you can let CodeDeploy do the following:
+ Create an IAM user in AWS Identity and Access Management for the on-premises instance, if you do not specify one with the command.
+ Save the IAM user's credentials to an on-premises instance configuration file.
+ Register the on-premises instance with CodeDeploy.
+ Add tags to the on-premises instance, if you specify them as part of the command.

**Note**  
The [register-on-premises-instance](https://docs.aws.amazon.com/cli/latest/reference/deploy/register-on-premises-instance.html) command is an alternative to the [register](https://docs.aws.amazon.com/cli/latest/reference/deploy/register.html) command. You use the **register-on-premises-instance** command if you want to configure an on-premises instance and register and tag it with CodeDeploy mostly on your own. The **register-on-premises-instance** command also gives you the option to use an IAM session ARN to register instances instead of an IAM user ARN. This approach provides a major advantage if you have large fleets of on-premises instances. Specifically, you can use a single IAM session ARN to authenticate multiple instances instead of having to create an IAM user for each on-premises instance one by one. For more information, see [Use the register-on-premises-instance command (IAM user ARN) to register an on-premises instance](register-on-premises-instance-iam-user-arn.md) and [Use the register-on-premises-instance command (IAM Session ARN) to register an on-premises instance](register-on-premises-instance-iam-session-arn.md).

**Topics**
+ [

## Step 1: Install and configure the AWS CLI on the on-premises instance
](#instances-on-premises-register-instance-1-install-cli)
+ [

## Step 2: Call the register command
](#instances-on-premises-register-instance-2-register-command)
+ [

## Step 3: Call the install command
](#instances-on-premises-register-instance-3-install-command)
+ [

## Step 4: Deploy application revisions to the on-premises instance
](#instances-on-premises-register-instance-4-deploy-revision)
+ [

## Step 5: Track deployments to the on-premises instance
](#instances-on-premises-register-instance-5-track-deployment)

## Step 1: Install and configure the AWS CLI on the on-premises instance
<a name="instances-on-premises-register-instance-1-install-cli"></a>

1. Install the AWS CLI on the on-premises instance. Follow the instructions in [Getting set up with the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html) in the *AWS Command Line Interface User Guide*.
**Note**  
CodeDeploy commands for working with on-premises instances are available in AWS CLI version 1.7.19 and later. If you have the AWS CLI already installed, call **aws --version** to check its version.

1. Configure the AWS CLI on the on-premises instance. Follow the instructions in [Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) in *AWS Command Line Interface User Guide*.
**Important**  
As you configure the AWS CLI (for example, by calling the **aws configure** command), be sure to specify the secret key ID and secret access key of an IAM user who has, at minimum, the following AWS access permissions in addition to the permissions specified in [Prerequisites for configuring an on-premises instance](instances-on-premises-prerequisites.md). This makes it possible to download and install the CodeDeploy agent on the on-premises instance. The access permissions might look similar to this:  

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement" : [
       {
         "Effect" : "Allow",
         "Action" : [
           "codedeploy:*",
           "iam:CreateAccessKey",
           "iam:CreateUser",
           "iam:DeleteAccessKey",
           "iam:DeleteUser",
           "iam:DeleteUserPolicy",
           "iam:ListAccessKeys",
           "iam:ListUserPolicies",
           "iam:PutUserPolicy",
           "iam:GetUser",
           "tag:getTagKeys",
           "tag:getTagValues",
           "tag:GetResources"
         ],
         "Resource" : "*"
       },
       {
         "Effect" : "Allow",
         "Action" : [
           "s3:Get*",
           "s3:List*"
         ],
         "Resource" : [
           "arn:aws:s3:::amzn-s3-demo-bucket/*",
           "arn:aws:s3:::amzn-s3-demo-bucket1/*"
         ]
       }     
     ]
   }
   ```
If you see access denied errors when trying to access one of the Amazon S3 buckets shown previously, try omitting the `/*` portion of the bucket's resource ARN, for example, `arn:aws:s3:::aws-codedeploy-sa-east-1`.

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement" : [
       {
         "Effect" : "Allow",
         "Action" : [
           "codedeploy:*",
           "iam:CreateAccessKey",
           "iam:CreateUser",
           "iam:DeleteAccessKey",
           "iam:DeleteUser",
           "iam:DeleteUserPolicy",
           "iam:ListAccessKeys",
           "iam:ListUserPolicies",
           "iam:PutUserPolicy",
           "iam:GetUser",
           "tag:GetResources"
         ],
         "Resource" : "*"
       },
       {
         "Effect" : "Allow",
         "Action" : [
           "s3:Get*",
           "s3:List*"
         ],
         "Resource" : [
           "arn:aws:s3:::amzn-s3-demo-bucket/*",
           "arn:aws:s3:::amzn-s3-demo-bucket2/*"
         ]
       }     
     ]
   }
   ```

## Step 2: Call the register command
<a name="instances-on-premises-register-instance-2-register-command"></a>

For this step, we assume you are registering the on-premises instance from the on-premises instance itself. You can also register an on-premises instance from a separate device or instance that has the AWS CLI installed and configured as described in the preceding step.

Use the AWS CLI to call the [register](https://docs.aws.amazon.com/cli/latest/reference/deploy/register.html) command, specifying:
+ A name that uniquely identifies the on-premises instance to CodeDeploy (with the `--instance-name` option). 
**Important**  
To help identify the on-premises instance later, especially for debugging purposes, we strongly recommend that you use a name that maps to some unique characteristic of the on-premises instance (for example, the serial number or some unique internal asset identifier, if applicable). If you specify a MAC address for a name, be aware that MAC addresses contain characters that CodeDeploy does not allow, such as colon (`:`). For a list of allowed characters, see [CodeDeploy quotas](limits.md).
+ Optionally, the ARN of an existing IAM user that you want to associate with this on-premises instance (with the `--iam-user-arn` option). To get the ARN of an IAM user, call the [get-user](https://docs.aws.amazon.com/cli/latest/reference/iam/get-user.html) command, or choose the IAM user name in the **Users** section of the IAM console and then find the **User ARN** value in the **Summary** section. If this option is not specified, CodeDeploy will create an IAM user on your behalf in your AWS account and associate it with the on-premises instance.
**Important**  
If you specify the `--iam-user-arn` option, you must also manually create the on-premises instance configuration file, as described in [Step 4: Add a configuration file to the on-premises instance](register-on-premises-instance-iam-user-arn.md#register-on-premises-instance-iam-user-arn-4).  
 You can associate only one IAM user with only one on-premises instance. Trying to associate a single IAM user with multiple on-premises instances can result in errors, failed deployments to those on-premises instances, or deployments to those on-premises instances that are stuck in a perpetual pending state. 
+ Optionally, a set of on-premises instance tags (with the `--tags` option) that CodeDeploy will use to identify the set of Amazon EC2 instances to which to deploy. Specify each tag with `Key=tag-key,Value=tag-value` (for example, `Key=Name,Value=Beta Key=Name,Value=WestRegion`). If this option is not specified, no tags will be registered. To register tags later, call the [add-tags-to-on-premises-instances](https://docs.aws.amazon.com/cli/latest/reference/deploy/add-tags-to-on-premises-instances.html) command.
+ Optionally, the AWS region where the on-premises instance will be registered with CodeDeploy (with the `--region` option). This must be one of the supported regions listed in [Region and endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html#codedeploy_region) in *AWS General Reference* (for example, `us-west-2`). If this option is not specified, the default AWS region associated with the calling IAM user will be used.

For example:

```
aws deploy register --instance-name AssetTag12010298EX --iam-user-arn arn:aws:iam::444455556666:user/CodeDeployUser-OnPrem --tags Key=Name,Value=CodeDeployDemo-OnPrem --region us-west-2
```

The **register** command does the following:

1. If no existing IAM user is specified, creates an IAM user, attaches the required permissions to it, and generates a corresponding secret key and secret access key. The on-premises instance will use this IAM user and its permissions and credentials to authenticate and interact with CodeDeploy. 

1. Registers the on-premises instance with CodeDeploy.

1. If specified, associates in CodeDeploy the tags that are specified with the `--tags` option with the registered on-premises instance name. 

1. If an IAM user was created, also creates the required configuration file in the same directory from which the **register** command was called.

If this command encounters any errors, an error message appears, describing how you can manually complete the remaining steps. Otherwise, a success message appears, describing how to call the **install** command as listed in the next step.

## Step 3: Call the install command
<a name="instances-on-premises-register-instance-3-install-command"></a>

From the on-premises instance, use the AWS CLI to call the [install](https://docs.aws.amazon.com/cli/latest/reference/deploy/install.html) command, specifying:
+ The path to the configuration file (with the `--config-file` option).
+ Optionally, whether to replace the configuration file that already exists on the on-premises instance (with the `--override-config` option). If not specified, the existing configuration file will not be replaced.
+ Optionally, the AWS region where the on-premises instance will be registered with CodeDeploy (with the `--region` option). This must be one of the supported regions listed in [Region and endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html#codedeploy_region) in *AWS General Reference* (for example, `us-west-2`). If this option is not specified, the default AWS region associated with the calling IAM user will be used.
+ Optionally, a custom location from which to install the CodeDeploy agent (with the `--agent-installer` option). This option is useful for installing a custom version of the CodeDeploy agent that CodeDeploy does not officially support (such as a custom version based on the [CodeDeploy agent](https://github.com/aws/aws-codedeploy-agent) repository in GitHub). The value must be the path to an Amazon S3 bucket that contains either: 
  + A CodeDeploy agent installation script (for Linux- or Unix-based operating systems, similar to the install file in the [CodeDeploy agent](https://github.com/aws/aws-codedeploy-agent/blob/master/bin/install) repository in GitHub).
  + A CodeDeploy agent installer package (.msi) file (for Windows-based operating systems).

   If this option is not specified, CodeDeploy will make its best attempt to install from its own location an officially supported version of the CodeDeploy agent that is compatible with the operating system on the on-premises instance.

For example:

```
aws deploy install --override-config --config-file /tmp/codedeploy.onpremises.yml --region us-west-2 --agent-installer s3://aws-codedeploy-us-west-2/latest/codedeploy-agent.msi
```

The **install** command does the following:

1. Checks whether the on-premises instance is an Amazon EC2 instance. If it is, an error message appears.

1. Copies the on-premises instances configuration file from the specified location on the instance to the location where the CodeDeploy agent expects to find it, provided that the file is not already in that location.

   For Ubuntu Server and Red Hat Enterprise Linux (RHEL)), this is `/etc/codedeploy-agent/conf`/`codedeploy.onpremises.yml`.

   For Windows Server, this is `C:\ProgramData\Amazon\CodeDeploy`\$1`conf.onpremises.yml`.

   If the `--override-config` option was specified, creates or overwrites the file.

1. Installs the CodeDeploy agent on the on-premises instance and then starts it. 

## Step 4: Deploy application revisions to the on-premises instance
<a name="instances-on-premises-register-instance-4-deploy-revision"></a>

You are now ready to deploy application revisions to the registered and tagged on-premises instance. 

You deploy application revisions to on-premises instances in a way that's similar to deploying application revisions to Amazon EC2 instances. For instructions, see [Create a deployment with CodeDeploy](deployments-create.md). These instructions link to prerequisites, including creating an application, creating a deployment group, and preparing an application revision. If you need a simple sample application revision to deploy, you can create the one described in [Step 2: Create a sample application revision](tutorials-on-premises-instance-2-create-sample-revision.md) in the [Tutorial: Deploy an application to an on-premises instance with CodeDeploy (Windows Server, Ubuntu Server, or Red Hat Enterprise Linux)](tutorials-on-premises-instance.md).

**Important**  
If you reuse an existing CodeDeploy service role as part of creating a deployment group that targets on-premises instances, you must include `Tag:get*` to the `Action` portion of the service role's policy statement. For more information, see [Step 2: Create a service role for CodeDeploy](getting-started-create-service-role.md).

## Step 5: Track deployments to the on-premises instance
<a name="instances-on-premises-register-instance-5-track-deployment"></a>

After you deploy an application revision to registered and tagged on-premises instances, you can track the deployment's progress.

You track deployments to on-premises instances in a way that's similar to tracking deployments to Amazon EC2 instances. For instructions, see [View CodeDeploy deployment details](deployments-view-details.md).

For more options, see [Managing on-premises instances operations in CodeDeploy](on-premises-instances-operations.md).

# Use the register-on-premises-instance command (IAM user ARN) to register an on-premises instance
<a name="register-on-premises-instance-iam-user-arn"></a>

**Important**  
Registering an instance using an IAM user is not recommended because it uses static (permanent) credentials for authentication. For improved security, we recommend registering an instance using temporary credentials for authentication. For more information, see [Use the register-on-premises-instance command (IAM Session ARN) to register an on-premises instance](register-on-premises-instance-iam-session-arn.md).

**Important**  
Make sure you have a plan in place to rotate the IAM user's access keys (permanent credentials). For more information, see [Rotating access keys](https://docs.aws.amazon.com//IAM/latest/UserGuide/id_credentials_access-keys.html#Using_RotateAccessKey).

Follow these instructions to configure an on-premises instance and register and tag it with CodeDeploy mostly on your own, using static IAM user credentials for authentication.

**Topics**
+ [

## Step 1: Create an IAM user for the on-premises instance
](#register-on-premises-instance-iam-user-arn-1)
+ [

## Step 2: Assign permissions to the IAM user
](#register-on-premises-instance-iam-user-arn-2)
+ [

## Step 3: Get the IAM user credentials
](#register-on-premises-instance-iam-user-arn-3)
+ [

## Step 4: Add a configuration file to the on-premises instance
](#register-on-premises-instance-iam-user-arn-4)
+ [

## Step 5: Install and configure the AWS CLI
](#register-on-premises-instance-iam-user-arn-5)
+ [

## Step 6: Set the AWS\$1REGION environment variable (Ubuntu Server and RHEL only)
](#register-on-premises-instance-iam-user-arn-6)
+ [

## Step 7: Install the CodeDeploy agent
](#register-on-premises-instance-iam-user-arn-7)
+ [

## Step 8: Register the on-premises instance with CodeDeploy
](#register-on-premises-instance-iam-user-arn-8)
+ [

## Step 9: Tag the on-premises instance
](#register-on-premises-instance-iam-user-arn-9)
+ [

## Step 10: Deploy application revisions to the on-premises instance
](#register-on-premises-instance-iam-user-arn-10)
+ [

## Step 11: Track deployments to the on-premises instance
](#register-on-premises-instance-iam-user-arn-11)

## Step 1: Create an IAM user for the on-premises instance
<a name="register-on-premises-instance-iam-user-arn-1"></a>

Create an IAM user that the on-premises instance will use to authenticate and interact with CodeDeploy. 

**Important**  
You must create a separate IAM user for each participating on-premises instance. If you try to reuse an individual IAM user for multiple on-premises instances, you might not be able to successfully register or tag those on-premises instances with CodeDeploy. Deployments to those on-premises instances might be stuck in a perpetual pending state or fail altogether.

We recommend that you assign the IAM user a name that identifies its purpose, such as CodeDeployUser-OnPrem.

You can use the AWS CLI or the IAM console to create an IAM user. For information, see [Creating an IAM user in your AWS account](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html). 

**Important**  
Whether you use the AWS CLI or the IAM console to create a new IAM user, make a note of the user ARN provided for the user. You will need this information later in [Step 4: Add a configuration file to the on-premises instance](#register-on-premises-instance-iam-user-arn-4) and [Step 8: Register the on-premises instance with CodeDeploy](#register-on-premises-instance-iam-user-arn-8).

## Step 2: Assign permissions to the IAM user
<a name="register-on-premises-instance-iam-user-arn-2"></a>

If your on-premises instance will be deploying application revisions from Amazon S3 buckets, you must assign to the IAM user the permissions to interact with those buckets. You can use the AWS CLI or the IAM console to assign permissions.

**Note**  
If you will be deploying application revisions only from GitHub repositories, skip this step and go directly to [Step 3: Get the IAM user credentials](#register-on-premises-instance-iam-user-arn-3). (You will still need information about the IAM user you created in [Step 1: Create an IAM user for the on-premises instance](#register-on-premises-instance-iam-user-arn-1). It will be used in later steps.)

**To assign permissions (CLI)**

1. Create a file with the following policy contents on the Amazon EC2 instance or device you are using to call the AWS CLI. Name the file something like **CodeDeploy-OnPrem-Permissions.json**, and then save the file.

   ```
   {
       "Version": "2012-10-17",		 	 	 
       "Statement": [
           {
               "Action": [
                   "s3:Get*",
                   "s3:List*"
               ],
               "Effect": "Allow",
               "Resource": "*"
           }
       ]
   }
   ```
**Note**  
We recommend that you restrict this policy to only those Amazon S3 buckets your on-premises instance needs to access. If you restrict this policy, make sure to also give access to the Amazon S3 buckets that contain the AWS CodeDeploy agent. Otherwise, an error might occur whenever the CodeDeploy agent is installed or updated on the associated on-premises instance.  
For example:  

   ```
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Action": [
           "s3:Get*",
           "s3:List*"
         ],
         "Resource": [
           "arn:aws:s3:::amzn-s3-demo-bucket/*",
           "arn:aws:s3:::aws-codedeploy-us-east-2/*",
           "arn:aws:s3:::aws-codedeploy-us-east-1/*",
           "arn:aws:s3:::aws-codedeploy-us-west-1/*",
           "arn:aws:s3:::aws-codedeploy-us-west-2/*",
           "arn:aws:s3:::aws-codedeploy-ca-central-1/*",
           "arn:aws:s3:::aws-codedeploy-eu-west-1/*",
           "arn:aws:s3:::aws-codedeploy-eu-west-2/*",
           "arn:aws:s3:::aws-codedeploy-eu-west-3/*",
           "arn:aws:s3:::aws-codedeploy-eu-central-1/*",
           "arn:aws:s3:::aws-codedeploy-eu-central-2/*",
           "arn:aws:s3:::aws-codedeploy-eu-north-1/*",
           "arn:aws:s3:::aws-codedeploy-eu-south-1/*",
           "arn:aws:s3:::aws-codedeploy-eu-south-2/*",
           "arn:aws:s3:::aws-codedeploy-il-central-1/*",
           "arn:aws:s3:::aws-codedeploy-ap-east-1/*",
           "arn:aws:s3:::aws-codedeploy-ap-northeast-1/*",
           "arn:aws:s3:::aws-codedeploy-ap-northeast-2/*",
           "arn:aws:s3:::aws-codedeploy-ap-northeast-3/*",
           "arn:aws:s3:::aws-codedeploy-ap-southeast-1/*",        
           "arn:aws:s3:::aws-codedeploy-ap-southeast-2/*",
           "arn:aws:s3:::aws-codedeploy-ap-southeast-3/*",
           "arn:aws:s3:::aws-codedeploy-ap-southeast-4/*",
           "arn:aws:s3:::aws-codedeploy-ap-south-1/*",
           "arn:aws:s3:::aws-codedeploy-ap-south-2/*",
           "arn:aws:s3:::aws-codedeploy-me-central-1/*",
           "arn:aws:s3:::aws-codedeploy-me-south-1/*",
           "arn:aws:s3:::aws-codedeploy-sa-east-1/*"
         ]
       }
     ]
   }
   ```

1. Call the [put-user-policy](https://docs.aws.amazon.com/cli/latest/reference/iam/put-user-policy.html) command, specifying the name of the IAM user (with the `--user-name` option), a name for the policy (with the `--policy-name` option), and the path to the newly created policy document (with the `--policy-document` option). For example, assuming that the **CodeDeploy-OnPrem-Permissions.json** file is in the same directory (folder) from which you're calling this command:
**Important**  
Be sure to include `file://` before the file name. It is required in this command.

   ```
   aws iam put-user-policy --user-name CodeDeployUser-OnPrem --policy-name CodeDeploy-OnPrem-Permissions --policy-document file://CodeDeploy-OnPrem-Permissions.json
   ```

**To assign permissions (console)**

1. Open the IAM console at [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/).

1. In the navigation pane, choose **Policies**, and then choose **Create Policy**. (If a **Get Started** button appears, choose it, and then choose **Create Policy**.)

1. Next to **Create Your Own Policy**, choose **Select**.

1. In the **Policy Name** box, type a name for this policy (for example, **CodeDeploy-OnPrem-Permissions**).

1. In the **Policy Document** box, type or paste the following permissions expression, which allows AWS CodeDeploy to deploy application revisions from any Amazon S3 bucket specified in the policy to the on-premises instance on behalf of the IAM user:

   ```
   {
       "Version": "2012-10-17",		 	 	 
       "Statement": [
           {
               "Action": [
                   "s3:Get*",
                   "s3:List*"
               ],
               "Effect": "Allow",
               "Resource": "*"
           }
       ]
   }
   ```

1. Choose **Create Policy**.

1. In the navigation pane, choose **Users**.

1. In the list of users, browse to and choose the name of the IAM user you created in [Step 1: Create an IAM user for the on-premises instance](#register-on-premises-instance-iam-user-arn-1). 

1. On the **Permissions** tab, in **Managed Policies**, choose **Attach Policy**.

1. Select the policy named **CodeDeploy-OnPrem-Permissions**, and then choose **Attach Policy**. 

## Step 3: Get the IAM user credentials
<a name="register-on-premises-instance-iam-user-arn-3"></a>

Get the secret key ID and the secret access key for the IAM user. You will need them for [Step 4: Add a configuration file to the on-premises instance](#register-on-premises-instance-iam-user-arn-4). You can use the AWS CLI or the IAM console to get the secret key ID and the secret access key.

**Note**  
If you already have the secret key ID and the secret access key, skip this step and go directly to [Step 4: Add a configuration file to the on-premises instance](#register-on-premises-instance-iam-user-arn-4).  
Users need programmatic access if they want to interact with AWS outside of the AWS Management Console. The way to grant programmatic access depends on the type of user that's accessing AWS.  
To grant users programmatic access, choose one of the following options.  


****  

| Which user needs programmatic access? | To | By | 
| --- | --- | --- | 
| IAM | (Recommended) Use console credentials as temporary credentials to sign programmatic requests to the AWS CLI, AWS SDKs, or AWS APIs. |  Following the instructions for the interface that you want to use. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/codedeploy/latest/userguide/register-on-premises-instance-iam-user-arn.html)  | 
|  Workforce identity (Users managed in IAM Identity Center)  | Use temporary credentials to sign programmatic requests to the AWS CLI, AWS SDKs, or AWS APIs. |  Following the instructions for the interface that you want to use. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/codedeploy/latest/userguide/register-on-premises-instance-iam-user-arn.html)  | 
| IAM | Use temporary credentials to sign programmatic requests to the AWS CLI, AWS SDKs, or AWS APIs. | Following the instructions in [Using temporary credentials with AWS resources](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html) in the IAM User Guide. | 
| IAM | (Not recommended)Use long-term credentials to sign programmatic requests to the AWS CLI, AWS SDKs, or AWS APIs. |  Following the instructions for the interface that you want to use. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/codedeploy/latest/userguide/register-on-premises-instance-iam-user-arn.html)  | 

**To get the credentials (CLI)**

1. Call the [list-access-keys](https://docs.aws.amazon.com/cli/latest/reference/iam/list-access-keys.html) command, specifying the name of the IAM user (with the `--user-name` option) and querying for just the access key IDs (with the `--query` and `--output` options). For example:

   ```
   aws iam list-access-keys --user-name CodeDeployUser-OnPrem --query "AccessKeyMetadata[*].AccessKeyId" --output text
   ```

1. If no keys appear in the output or information about only one key appears in the output, call the [create-access-key](https://docs.aws.amazon.com/cli/latest/reference/iam/create-access-key.html) command, specifying the name of the IAM user (with the `--user-name` option):

   ```
   aws iam create-access-key --user-name CodeDeployUser-OnPrem
   ```

   In the output of the call to the **create-access-key** command, note the value of the `AccessKeyId` and `SecretAccessKey` fields. You will need this information in [Step 4: Add a configuration file to the on-premises instance](#register-on-premises-instance-iam-user-arn-4).
**Important**  
This will be the only time you will have access to this secret access key. If you forget or lose access to this secret access key, you will need to generate a new one by following the steps in [Step 3: Get the IAM user credentials](#register-on-premises-instance-iam-user-arn-3).

1. If two access keys are already listed, you must delete one of them by calling the [delete-access-key](https://docs.aws.amazon.com/cli/latest/reference/iam/delete-access-key.html) command, specifying the name of the IAM user (with the `--user-name` option), and the ID of the access key to delete (with the `--access-key-id` option). Then call the **create-access-key** command, as described earlier in this step. Here's an example of calling the **delete-access-key** command:

   ```
   aws iam delete-access-key --user-name CodeDeployUser-OnPrem --access-key-id access-key-ID
   ```
**Important**  
If you call the **delete-access-key** command to delete one of these access keys, and an on-premises instance is already using this access key as described in [Step 4: Add a configuration file to the on-premises instance](#register-on-premises-instance-iam-user-arn-4), you will need to follow the instructions in [Step 4: Add a configuration file to the on-premises instance](#register-on-premises-instance-iam-user-arn-4) again to specify a different access key ID and secret access key associated with this IAM user. Otherwise, any deployments to that on-premises instance might be stuck in a perpetual pending state or fail altogether.

**To get the credentials (console)**

1. 

   1. Open the IAM console at [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/).

   1. If the list of users is not displayed, in the navigation pane, choose **Users**.

   1. In the list of users, browse to and choose the name of the IAM user you created in [Step 1: Create an IAM user for the on-premises instance](#register-on-premises-instance-iam-user-arn-1). 

1. On the **Security credentials** tab, if no keys or only one key is listed, choose **Create access key**.

   If two access keys are listed, you must delete one of them. Choose **Delete** next to one of the access keys, and then choose **Create access key**.
**Important**  
If you choose **Delete** next to one of these access keys, and an on-premises instance is already using this access key as described in [Step 4: Add a configuration file to the on-premises instance](#register-on-premises-instance-iam-user-arn-4), you will need to follow the instructions in [Step 4: Add a configuration file to the on-premises instance](#register-on-premises-instance-iam-user-arn-4) again to specify a different access key ID and secret access key associated with this IAM user. Otherwise, deployments to that on-premises instance might be stuck in a perpetual pending state or fail altogether.

1. Choose **Show** and note the access key ID and secret access key. You will need this information for the next step. Alternatively, you can choose **Download .csv file** to save a copy of the access key ID and the secret access key.
**Important**  
Unless you make a note of or download the credentials, this will be the only time you will have access to this secret access key. If you forget or lose access to this secret access key, you will need to generate a new one by following the steps in [Step 3: Get the IAM user credentials](#register-on-premises-instance-iam-user-arn-3).

1. Choose **Close** to return to the **Users > *IAM User Name*** page.

## Step 4: Add a configuration file to the on-premises instance
<a name="register-on-premises-instance-iam-user-arn-4"></a>

Add a configuration file to the on-premises instance, using root or administrator permissions. This configuration file will be used to declare the IAM user credentials and the target AWS region to be used for CodeDeploy. The file must be added to a specific location on the on-premises instance. The file must include the IAM user's ARN, secret key ID, secret access key, and the target AWS region. The file must follow a specific format.

1. Create a file named `codedeploy.onpremises.yml` (for an Ubuntu Server or RHEL on-premises instance) or `conf.onpremises.yml` (for a Windows Server on-premises instance) in the following location on the on-premises instance:
   + For Ubuntu Server: `/etc/codedeploy-agent/conf`
   + For Windows Server: `C:\ProgramData\Amazon\CodeDeploy`

1. Use a text editor to add the following information to the newly created `codedeploy.onpremises.yml` or `conf.onpremises.yml` file:

   ```
   ---
   aws_access_key_id: secret-key-id
   aws_secret_access_key: secret-access-key
   iam_user_arn: iam-user-arn
   region: supported-region
   ```

   Where:
   + *secret-key-id* is the corresponding IAM user's secret key ID you noted in [Step 1: Create an IAM user for the on-premises instance](#register-on-premises-instance-iam-user-arn-1) or [Step 3: Get the IAM user credentials](#register-on-premises-instance-iam-user-arn-3).
   + *secret-access-key* is the corresponding IAM user's secret access key you noted in [Step 1: Create an IAM user for the on-premises instance](#register-on-premises-instance-iam-user-arn-1) or [Step 3: Get the IAM user credentials](#register-on-premises-instance-iam-user-arn-3).
   + *iam-user-arn* is the IAM user's ARN you noted earlier in [Step 1: Create an IAM user for the on-premises instance](#register-on-premises-instance-iam-user-arn-1). 
   + *supported-region* is the identifier of a region supported by CodeDeploy where your CodeDeploy applications, deployment groups, and application revisions are located (for example, `us-west-2`). For a list of regions, see [Region and endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html#codedeploy_region) in the *AWS General Reference*.

    
**Important**  
If you chose **Delete** next to one of the access keys in [Step 3: Get the IAM user credentials](#register-on-premises-instance-iam-user-arn-3), and your on-premises instance is already using the associated access key ID and secret access key, you will need to follow the instructions in [Step 4: Add a configuration file to the on-premises instance](#register-on-premises-instance-iam-user-arn-4) to specify a different access key ID and secret access key associated with this IAM user. Otherwise, any deployments to your on-premises instance might be stuck in a perpetual pending state or fail altogether.

## Step 5: Install and configure the AWS CLI
<a name="register-on-premises-instance-iam-user-arn-5"></a>

Install and configure the AWS CLI on the on-premises instance. (The AWS CLI will be used in [Step 7: Install the CodeDeploy agent](#register-on-premises-instance-iam-user-arn-7) to download and install the CodeDeploy agent on the on-premises instance.)

1. To install the AWS CLI on the on-premises instance, follow the instructions in [Getting set up with the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html) in the *AWS Command Line Interface User Guide*.
**Note**  
CodeDeploy commands for working with on-premises instances became available in version 1.7.19 of the AWS CLI. If you have a version of the AWS CLI already installed, you can check its version by calling **aws --version**.

1. To configure the AWS CLI on the on-premises instance, follow the instructions in [Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) in the *AWS Command Line Interface User Guide*.
**Important**  
As you configure the AWS CLI (for example, by calling the **aws configure** command), be sure to specify the secret key ID and secret access key of an IAM user that has, at minimum, the following AWS access permissions in addition to the access permissions specified in the [Prerequisites for configuring an on-premises instance](instances-on-premises-prerequisites.md). This makes it possible for you to download and install the CodeDeploy agent on the on-premises instance:  
   

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement" : [
       {
         "Effect" : "Allow",
         "Action" : [
           "codedeploy:*"
         ],
         "Resource" : "*"
       },
       {
         "Effect" : "Allow",
         "Action" : [
           "s3:Get*",
           "s3:List*"
         ],
         "Resource" : [
           "arn:aws:s3:::amzn-s3-demo-bucket/*",
           "arn:aws:s3:::amzn-s3-demo-bucket1/*"
         ]
       }     
     ]
   }
   ```

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement" : [
       {
         "Effect" : "Allow",
         "Action" : [
           "codedeploy:*"
         ],
         "Resource" : "*"
       },
       {
         "Effect" : "Allow",
         "Action" : [
           "s3:Get*",
           "s3:List*"
         ],
         "Resource" : [
           "*"
         ]
       }     
     ]
   }
   ```
These access permissions can be assigned to either the IAM user you created in [Step 1: Create an IAM user for the on-premises instance](#register-on-premises-instance-iam-user-arn-1) or to a different IAM user. To assign these permissions to an IAM user, follow the instructions in [Step 1: Create an IAM user for the on-premises instance](#register-on-premises-instance-iam-user-arn-1), using these access permissions instead of the ones in that step.

## Step 6: Set the AWS\$1REGION environment variable (Ubuntu Server and RHEL only)
<a name="register-on-premises-instance-iam-user-arn-6"></a>

If you are not running Ubuntu Server or RHEL on your on-premises instance, skip this step and go directly to [Step 7: Install the CodeDeploy agent](#register-on-premises-instance-iam-user-arn-7). 

Install the CodeDeploy agent on an Ubuntu Server or RHEL on-premises instance and enable the instance to update the CodeDeploy agent whenever a new version becomes available. You do this by setting the `AWS_REGION` environment variable on the instance to the identifier of one of the regions supported by CodeDeploy. We recommend that you set the value to the region where your CodeDeploy applications, deployment groups, and application revisions are located (for example, `us-west-2`). For a list of regions, see [Region and endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html#codedeploy_region) in the *AWS General Reference*.

To set the environment variable, call the following from the terminal:

```
export AWS_REGION=supported-region
```

Where *supported-region* is the region identifier (for example, `us-west-2`).

## Step 7: Install the CodeDeploy agent
<a name="register-on-premises-instance-iam-user-arn-7"></a>

Install the CodeDeploy agent on the on-premises instance:
+ For an Ubuntu Server on-premises instance, follow the instructions in [Install the CodeDeploy agent for Ubuntu Server](codedeploy-agent-operations-install-ubuntu.md), and then return to this page.
+ For a RHEL on-premises instance, follow the instructions in [Install the CodeDeploy agent for Amazon Linux or RHEL](codedeploy-agent-operations-install-linux.md), and then return to this page.
+ For a Windows Server on-premises instance, follow the instructions in [Install the CodeDeploy agent for Windows Server](codedeploy-agent-operations-install-windows.md), and then return to this page.

## Step 8: Register the on-premises instance with CodeDeploy
<a name="register-on-premises-instance-iam-user-arn-8"></a>

The instructions in this step assume you are registering the on-premises instance from the on-premises instance itself. You can register an on-premises instance from a separate device or instance that has the AWS CLI installed and configured, as described in [Step 5: Install and configure the AWS CLI](#register-on-premises-instance-iam-user-arn-5).

Use the AWS CLI to register the on-premises instance with CodeDeploy so that it can be used in deployments.

1. Before you can use the AWS CLI, you will need the user ARN of the IAM user you created in [Step 1: Create an IAM user for the on-premises instance](#register-on-premises-instance-iam-user-arn-1). If you don't already have the user ARN, call the [get-user](https://docs.aws.amazon.com/cli/latest/reference/iam/get-user.html) command, specifying the name of the IAM user (with the `--user-name` option) and querying for just the user ARN (with the `--query` and `--output` options):

   ```
   aws iam get-user --user-name CodeDeployUser-OnPrem --query "User.Arn" --output text
   ```

1. Call the [register-on-premises-instance](https://docs.aws.amazon.com/cli/latest/reference/deploy/register-on-premises-instance.html) command, specifying:
   + A name that uniquely identifies the on-premises instance (with the `--instance-name` option). 
**Important**  
To help identify the on-premises instance, especially for debugging purposes, we strongly recommend that you specify a name that maps to some unique characteristic of the on-premises instance (for example, the serial number or an internal asset identifier, if applicable). If you specify a MAC address as a name, be aware that MAC addresses contain characters that CodeDeploy does not allow, such as colon (`:`). For a list of allowed characters, see [CodeDeploy quotas](limits.md).
   + The user ARN of the IAM user you created in [Step 1: Create an IAM user for the on-premises instance](#register-on-premises-instance-iam-user-arn-1) (with the `--iam-user-arn` option).

     For example:

     ```
     aws deploy register-on-premises-instance --instance-name AssetTag12010298EX --iam-user-arn arn:aws:iam::444455556666:user/CodeDeployUser-OnPrem
     ```

## Step 9: Tag the on-premises instance
<a name="register-on-premises-instance-iam-user-arn-9"></a>

You can use either the AWS CLI or the CodeDeploy console to tag the on-premises instance. (CodeDeploy uses on-premises instance tags to identify the deployment targets during a deployment.)

**To tag the on-premises instance (CLI)**
+ Call the [add-tags-to-on-premises-instances](https://docs.aws.amazon.com/cli/latest/reference/deploy/add-tags-to-on-premises-instances.html) command, specifying:

   
  + The name that uniquely identifies the on-premises instance (with the `--instance-names` option). 
  + The name of the on-premises instance tag key and tag value you want to use (with the `--tags` option). You must specify both a name and value. CodeDeploy does not allow on-premises instance tags that have values only.

    For example:

    ```
    aws deploy add-tags-to-on-premises-instances --instance-names AssetTag12010298EX --tags Key=Name,Value=CodeDeployDemo-OnPrem
    ```

**To tag the on-premises instance (console)**

1. Sign in to the AWS Management Console and open the CodeDeploy console at [https://console.aws.amazon.com/codedeploy](https://console.aws.amazon.com/codedeploy).
**Note**  
Sign in with the same user that you set up in [Getting started with CodeDeploy](getting-started-codedeploy.md).

1. From the CodeDeploy menu, choose **On-premises instances**.

1. In the list of on-premises instances, choose the arrow next to the on-premises instance you want to tag.

1. In the list of tags, select or enter the desired tag key and tag value. After you enter the tag key and tag value, another row appears. You can repeat this for up to 10 tags. To remove a tag, choose the delete icon (![\[The delete icon.\]](http://docs.aws.amazon.com/codedeploy/latest/userguide/images/delete-triggers-x.png)).

1. After you have added tags, choose **Update Tags**.

## Step 10: Deploy application revisions to the on-premises instance
<a name="register-on-premises-instance-iam-user-arn-10"></a>

You are now ready to deploy application revisions to the registered and tagged on-premises instance. 

You deploy application revisions to on-premises instances in a way that's similar to deploying application revisions to Amazon EC2 instances. For instructions, see [Create a deployment with CodeDeploy](deployments-create.md). These instructions include a link to prerequisites, including creating an application, creating a deployment group, and preparing an application revision. If you need a simple sample application revision to deploy, you can create the one described in [Step 2: Create a sample application revision](tutorials-on-premises-instance-2-create-sample-revision.md) in the [Tutorial: Deploy an application to an on-premises instance with CodeDeploy (Windows Server, Ubuntu Server, or Red Hat Enterprise Linux)](tutorials-on-premises-instance.md).

**Important**  
If you reuse a CodeDeploy service role as part of creating a deployment group that targets on-premises instances, you must include `Tag:get*` to the `Action` portion of the service role's policy statement. For more information, see [Step 2: Create a service role for CodeDeploy](getting-started-create-service-role.md).

## Step 11: Track deployments to the on-premises instance
<a name="register-on-premises-instance-iam-user-arn-11"></a>

After you deploy an application revision to registered and tagged on-premises instances, you can track the deployment's progress.

You track deployments to on-premises instances in a way that's similar to tracking deployments to Amazon EC2 instances. For instructions, see [View CodeDeploy deployment details](deployments-view-details.md).

# Managing on-premises instances operations in CodeDeploy
<a name="on-premises-instances-operations"></a>

Follow the instructions in this section to manage operations on your on-premises instances after you have registered them with CodeDeploy, such as getting more information about, removing tags from, and uninstalling and deregistering on-premises instances.

**Topics**
+ [

# Get information about a single on-premises instance
](on-premises-instances-operations-view-details-single.md)
+ [

# Get information about multiple on-premises instances
](on-premises-instances-operations-view-details-multiple.md)
+ [

# Manually remove on-premises instance tags from an on-premises instance
](on-premises-instances-operations-remove-tags.md)
+ [

# Automatically uninstall the CodeDeploy agent and remove the configuration file from an on-premises instance
](on-premises-instances-operations-uninstall-agent.md)
+ [

# Automatically deregister an on-premises instance
](on-premises-instances-operations-deregister-automatically.md)
+ [

# Manually deregister an on-premises instance
](on-premises-instances-operations-deregister-manually.md)

# Get information about a single on-premises instance
<a name="on-premises-instances-operations-view-details-single"></a>

You can get information about a single on-premises instance by following the instructions in [View CodeDeploy deployment details](deployments-view-details.md). You can use the AWS CLI or the CodeDeploy console to get more information about a single on-premises instance.

**To get information about a single on-premises instance (CLI)**
+ Call the [get-on-premises-instance](https://docs.aws.amazon.com/cli/latest/reference/deploy/get-on-premises-instance.html) command, specifying the name that uniquely identifies the on-premises instance (with the `--instance-name` option):

  ```
  aws deploy get-on-premises-instance --instance-name AssetTag12010298EX
  ```

**To get information about a single on-premises instance (console)**

1. Sign in to the AWS Management Console and open the CodeDeploy console at [https://console.aws.amazon.com/codedeploy](https://console.aws.amazon.com/codedeploy).
**Note**  
Sign in with the same user that you set up in [Getting started with CodeDeploy](getting-started-codedeploy.md).

1. In the navigation pane, expand **Deploy**, and choose **On-premises instances**.

1. In the list of on-premises instances, choose the name of an on-premises instance to view its detail.

# Get information about multiple on-premises instances
<a name="on-premises-instances-operations-view-details-multiple"></a>

You can get information about on-premises instances by following the instructions in [View CodeDeploy deployment details](deployments-view-details.md). You can use the AWS CLI or the CodeDeploy console to get more information about on-premises instances.

**To get information about multiple on-premises instances (CLI)**

1. For a list of on-premises instance names, call the [list-on-premises-instances](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-on-premises-instances.html) command, specifying:
   + Whether to get information about all registered or deregistered on-premises instances (with the `--registration-status` option and `Registered` or `Deregistered`, respectively). If you omit this, then both registered and deregistered on-premises instance names are returned.
   + Whether to get information only about on-premises instances tagged with specific on-premises instance tags (with the `--tag-filters` option). For each on-premises instance tag, specify the `Key`, `Value`, and `Type` (which should always be `KEY_AND_VALUE`). Separate multiple on-premises instance tags with spaces between each `Key`, `Value`, and `Type` triplet.

   For example:

   ```
   aws deploy list-on-premises-instances --registration-status Registered --tag-filters Key=Name,Value=CodeDeployDemo-OnPrem,Type=KEY_AND_VALUE Key=Name,Value=CodeDeployDemo-OnPrem-Beta,Type=KEY_AND_VALUE
   ```

1. For more detailed information, call the [batch-get-on-premises-instances](https://docs.aws.amazon.com/cli/latest/reference/deploy/batch-get-on-premises-instances.html) command, with the names of the on-premises instances (with the `--instance-names` option): 

   ```
   aws deploy batch-get-on-premises-instances --instance-names AssetTag12010298EX AssetTag09920444EX
   ```

**To get information about multiple on-premises instances (console)**

1. Sign in to the AWS Management Console and open the CodeDeploy console at [https://console.aws.amazon.com/codedeploy](https://console.aws.amazon.com/codedeploy).
**Note**  
Sign in with the same user that you set up in [Getting started with CodeDeploy](getting-started-codedeploy.md).

1. In the navigation pane, expand **Deploy**, and choose **On-premises instances**.

   Information about the on-premises instances is displayed.

# Manually remove on-premises instance tags from an on-premises instance
<a name="on-premises-instances-operations-remove-tags"></a>

Typically, you remove an on-premises instance tag from an on-premises instance when that tag is no longer being used, or you want to remove the on-premises instance from any deployment groups that rely on that tag. You can use the AWS CLI or the AWS CodeDeploy console to remove on-premises instance tags from on-premises instances.

You do not need to remove the on-premises instance tags from an on-premises instance before you deregister it. 

Manually removing on-premises instance tags from an on-premises instance does not deregister the instance. It does not uninstall the CodeDeploy agent from the instance. It does not remove the configuration file from the instance. It does not delete the IAM user associated with the instance. 

To automatically deregister the on-premises instance, see [Automatically deregister an on-premises instance](on-premises-instances-operations-deregister-automatically.md).

To manually deregister the on-premises instance, see [Manually deregister an on-premises instance](on-premises-instances-operations-deregister-manually.md).

To automatically uninstall the CodeDeploy agent and remove the configuration file from the on-premises instance, see [Automatically uninstall the CodeDeploy agent and remove the configuration file from an on-premises instance](on-premises-instances-operations-uninstall-agent.md).

To manually uninstall just the CodeDeploy agent from the on-premises instance, see [Managing CodeDeploy agent operations](codedeploy-agent-operations.md).

To manually delete the associated IAM user, see [Deleting an IAM user from your AWS account](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_DeletingUserFromAccount.html). 

**To remove on-premises instance tags from an on-premises instance (CLI)**
+ Call the [remove-tags-from-on-premises-instances](https://docs.aws.amazon.com/cli/latest/reference/deploy/remove-tags-from-on-premises-instances.html), specifying:

   
  + The names that uniquely identify the on-premises instance (with the `--instance-names` option). 
  + The names and values of the tags you want to remove (with the `--tags` option).

    For example:

    ```
    aws deploy remove-tags-from-on-premises-instances --instance-names AssetTag12010298EX --tags Key=Name,Value=CodeDeployDemo-OnPrem
    ```

**To remove on-premises instance tags from an on-premises instance (console)**

1. Sign in to the AWS Management Console and open the CodeDeploy console at [https://console.aws.amazon.com/codedeploy](https://console.aws.amazon.com/codedeploy).
**Note**  
Sign in with the same user that you set up in [Getting started with CodeDeploy](getting-started-codedeploy.md).

1. In the navigation pane, expand **Deploy**, and choose **On-premises instances**.

1. In the list of on-premises instances, choose the name of the on-premises instance from which you want to remove tags.

1. In **Tags**, choose **Remove** next to each tag you want to remove.

1. After you have deleted the tags, choose **Update tags**.

# Automatically uninstall the CodeDeploy agent and remove the configuration file from an on-premises instance
<a name="on-premises-instances-operations-uninstall-agent"></a>

Typically, you uninstall the CodeDeploy agent and remove the configuration file from an on-premises instance after you're no longer planning to deploy to it.

**Note**  
Automatically uninstalling the CodeDeploy agent and removing the configuration file from an on-premises instance does not deregister an on-premises instance. It does not disassociate any on-premises instance tags associated with the on-premises instance. It does not delete the IAM user associated with the on-premises instance.   
To automatically deregister the on-premises instance, see [Automatically deregister an on-premises instance](on-premises-instances-operations-deregister-automatically.md).  
To manually deregister the on-premises instance, see [Manually deregister an on-premises instance](on-premises-instances-operations-deregister-manually.md).  
To manually disassociate any associated on-premises instance tags, see [Manually remove on-premises instance tags from an on-premises instance](on-premises-instances-operations-remove-tags.md).  
To manually uninstall the CodeDeploy agent from the on-premises instance, see [Managing CodeDeploy agent operations](codedeploy-agent-operations.md).  
To manually delete the associated IAM user, see [Deleting an IAM user from your AWS account](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_DeletingUserFromAccount.html). 

From the on-premises instance, use the AWS CLI to call the [uninstall](https://docs.aws.amazon.com/cli/latest/reference/deploy/uninstall.html) command.

For example:

```
aws deploy uninstall
```

The **uninstall** command does the following:

1. Stops the running CodeDeploy agent on the on-premises instance.

1. Uninstalls the CodeDeploy agent from the on-premises instance.

1. Removes the configuration file from the on-premises instance. (For Ubuntu Server and RHEL, this is `/etc/codedeploy-agent/conf`/`codedeploy.onpremises.yml`. For Windows Server, this is `C:\ProgramData\Amazon\CodeDeploy`\$1`conf.onpremises.yml`.)

# Automatically deregister an on-premises instance
<a name="on-premises-instances-operations-deregister-automatically"></a>

Typically, you deregister an on-premises instance after you're no longer planning to deploy to it. When you deregister an on-premises instance, even though the on-premises instance might be part of a deployment group's on-premises instance tags, the on-premises instance will not be included in any deployments. You can use the AWS CLI to deregister on-premises instances.

**Note**  
You cannot use the CodeDeploy console to deregister an on-premises instance. Also, deregistering an on-premises instance removes any on-premises instance tags that are associated with the on-premises instance. It does not uninstall the CodeDeploy agent from the on-premises instance. It does not remove the on-premises instance configuration file from the on-premises instance.  
To use the CodeDeploy console to perform some (but not all) of the activities in this section, see the CodeDeploy console section of [Manually deregister an on-premises instance](on-premises-instances-operations-deregister-manually.md).  
To manually disassociate any associated on-premises instance tags, see [Manually remove on-premises instance tags from an on-premises instance](on-premises-instances-operations-remove-tags.md).  
To automatically uninstall the CodeDeploy agent and remove the configuration file from the on-premises instance, see [Automatically uninstall the CodeDeploy agent and remove the configuration file from an on-premises instance](on-premises-instances-operations-uninstall-agent.md).  
To manually uninstall only the CodeDeploy agent from the on-premises instance, see [Managing CodeDeploy agent operations](codedeploy-agent-operations.md). 

Use the AWS CLI to call the [deregister](https://docs.aws.amazon.com/cli/latest/reference/deploy/deregister.html) command, specifying:
+ The name that uniquely identifies the on-premises instance to CodeDeploy (with the `--instance-name` option). 
+  Optionally, whether to delete the IAM user associated with the on-premises instance. The default behaviour is to delete the IAM user. If you do not want to delete the IAM user associated with the on-premises instance, specify the `--no-delete-iam-user` option in the command. 
+ Optionally, the AWS region where the on-premises instance was registered with CodeDeploy (with the `--region` option). This must be one of the supported regions listed in [Region and endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html#codedeploy_region) in the *AWS General Reference* (for example, `us-west-2`). If this option is not specified, the default AWS region associated with the calling IAM user will be used.

An example that degisters an instance and deletes the user:

```
aws deploy deregister --instance-name AssetTag12010298EX --region us-west-2
```

An example that degisters an instance and does not delete the user:

```
aws deploy deregister --instance-name AssetTag12010298EX --no-delete-iam-user --region us-west-2
```

The **deregister** command does the following:

1. Deregisters the on-premises instance with CodeDeploy.

1. If specified, deletes the IAM user associated with the on-premises instance.

After you deregister an on-premises instance:
+  It stops appearing in the console immediately. 
+  You can create another instance with the same name immediately. 

If this command encounters any errors, an error message appears, describing how you can manually complete the remaining steps. Otherwise, a success message appears, describing how to call the **uninstall** command.

# Manually deregister an on-premises instance
<a name="on-premises-instances-operations-deregister-manually"></a>

Typically, you deregister an on-premises instance after you're no longer planning to deploy to it. You use the AWS CLI to manually deregister on-premises instances.

Manually deregistering an on-premises instance does not uninstall the CodeDeploy agent. It does not remove the configuration file from the instance. It does not delete the IAM user associated with the instance. It does not remove any tags associated with the instance.

To automatically uninstall the CodeDeploy agent and remove the configuration file from the on-premises instance, see [Automatically uninstall the CodeDeploy agent and remove the configuration file from an on-premises instance](on-premises-instances-operations-uninstall-agent.md).

To manually uninstall only the CodeDeploy agent, see [Managing CodeDeploy agent operations](codedeploy-agent-operations.md). 

To manually delete the associated IAM user, see [Deleting an IAM user from your AWS account](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_DeletingUserFromAccount.html). 

To manually remove only the associated on-premises instance tags, see [Manually remove on-premises instance tags from an on-premises instance](on-premises-instances-operations-remove-tags.md).
+ Call the [deregister-on-premises-instance](https://docs.aws.amazon.com/cli/latest/reference/deploy/deregister-on-premises-instance.html) command, specifying the name that uniquely identifies the on-premises instance (with the `--instance-name` option):

  ```
  aws deploy deregister-on-premises-instance --instance-name AssetTag12010298EX
  ```

  After you deregister an on-premises instance:
  +  It stops appearing in the console immediately. 
  +  You can create another instance with the same name immediately. 