Menu
AWS CodeDeploy
User Guide (API Version 2014-10-06)

Use the register-on-premises-instance Command (IAM User ARN) to Register an On-Premises Instance

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

Step 1: Create an IAM User for the On-Premises Instance

Create an IAM user that the on-premises instance will use to authenticate and interact with AWS 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 resister or tag those on-premises instances with AWS CodeDeploy. Deployments to those on-premises instances might be stuck in a perpetual pending state or fail altogether.

We recommed 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.

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 and Step 8: Register the On-Premises Instance with AWS CodeDeploy.

Step 2: Assign Permissions to the IAM User

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. (You will still need information about the IAM user you created in Step 1: Create an IAM User for the On-Premises Instance. 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.

    Copy
    { "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 AWS CodeDeploy agent is installed or updated on the associated on-premises instance. For example:

    Copy
    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:Get*", "s3:List*" ], "Resource": [ "arn:aws:s3:::codedeploydemobucket/*", "arn:aws:s3:::aws-codedeploy-us-east-1/*", "arn:aws:s3:::aws-codedeploy-us-east-2/*", "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-central-1/*", "arn:aws:s3:::aws-codedeploy-ap-northeast-1/*", "arn:aws:s3:::aws-codedeploy-ap-northeast-2/*", "arn:aws:s3:::aws-codedeploy-ap-southeast-1/*", "arn:aws:s3:::aws-codedeploy-ap-southeast-2/*", "arn:aws:s3:::aws-codedeploy-ap-south-1/*", "arn:aws:s3:::aws-codedeploy-sa-east-1/*" ] } ] }
  2. Call the put-user-policy 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.

    Copy
    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/.

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

  3. Next to Create Your Own Policy, choose Select.

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

  5. 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 account:

    Copy
    { "Version": "2012-10-17", "Statement": [ { "Action": [ "s3:Get*", "s3:List*" ], "Effect": "Allow", "Resource": "*" } ] }
  6. Choose Create Policy.

  7. In the navigation pane, choose Users.

  8. 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.

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

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

Step 3: Get the IAM User Credentials

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

To get the credentials (CLI)

  1. Call the list-access-keys 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:

    Copy
    aws iam list-access-keys --user-name CodeDeployUser-OnPrem --query "AccessKeyMetadata[*].AccessKeyId" --output text
  2. If no keys appear in the output or information about only one key appears in the output, call the create-access-key command, specifying the name of the IAM user (with the --user-name option):

    Copy
    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.

    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.

  3. If two access keys are already listed, you must delete one of them by calling the delete-access-key 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:

    Copy
    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, you will need to follow the instructions in Step 4: Add a Configuration File to the On-Premises Instance 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. Open the IAM console at https://console.aws.amazon.com/iam/.

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

    3. 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.

  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, you will need to follow the instructions in Step 4: Add a Configuration File to the On-Premises Instance 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.

  2. 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.

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

Step 4: Add a Configuration File to the On-Premises Instance

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 AWS 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

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

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

    Where:

    Important

    If you chose Delete next to one of the access keys in Step 3: Get the IAM User Credentials, 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 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

Install and configure the AWS CLI on the on-premises instance. (The AWS CLI will be used in Step 7: Install the AWS CodeDeploy Agent to download and install the AWS 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 Command Line Interface in the AWS Command Line Interface User Guide.

    Note

    AWS 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.

  2. To configure the AWS CLI on the on-premises instance, follow the instructions in Configuring the AWS Command Line Interface 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. This makes it possible for you to download and install the AWS CodeDeploy agent on the on-premises instance:

    Copy
    { "Version": "2012-10-17", "Statement" : [ { "Effect" : "Allow", "Action" : [ "codedeploy:*" ], "Resource" : "*" }, { "Effect" : "Allow", "Action" : [ "s3:Get*", "s3:List*" ], "Resource" : [ "arn:aws:s3:::aws-codedeploy-us-east-1/*", "arn:aws:s3:::aws-codedeploy-us-east-2/*", "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-central-1/*", "arn:aws:s3:::aws-codedeploy-ap-northeast-1/*", "arn:aws:s3:::aws-codedeploy-ap-northeast-2/*", "arn:aws:s3:::aws-codedeploy-ap-southeast-1/*", "arn:aws:s3:::aws-codedeploy-ap-southeast-2/*", "arn:aws:s3:::aws-codedeploy-ap-south-1/*", "arn:aws:s3:::aws-codedeploy-sa-east-1/*" ] } ] }

    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 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, using these access permissions instead of the ones in that step.

Step 6: Set the AWS_REGION 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 Step 7: Install the AWS CodeDeploy Agent .

Install the AWS CodeDeploy agent on an Ubuntu Server or RHEL on-premises instance and enable the instance to update the AWS 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 AWS CodeDeploy. We recommend that you set the value to the region where your AWS CodeDeploy applications, deployment groups, and application revisions are located (for example, us-west-2). For a list of regions, see Region and Endpoints in the AWS General Reference.

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

Copy
export AWS_REGION=supported-region

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

Step 7: Install the AWS CodeDeploy Agent

Install the AWS CodeDeploy agent on the on-premises instance:

Step 8: Register the On-Premises Instance with AWS CodeDeploy

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.

Use the AWS CLI to register the on-premises instance with AWS 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. If you don't already have the user ARN, call the get-user 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):

    Copy
    aws iam get-user --user-name CodeDeployUser-OnPrem --query "User.Arn" --output text
  2. Call the register-on-premises-instance 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 AWS CodeDeploy does not allow, such as colon (:). For a list of allowed characters, see Limits.

    • The user ARN of the IAM user you created in Step 1: Create an IAM User for the On-Premises Instance (with the --iam-user-arn option).

      For example:

      Copy
      aws deploy register-on-premises-instance --instance-name AssetTag12010298EX --iam-user-arn arn:aws:iam::80398EXAMPLE:user/CodeDeployUser-OnPrem

Step 9: Tag the On-Premises Instance

You can use either the AWS CLI or the AWS CodeDeploy console to tag the on-premises instance. (AWS 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 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. AWS CodeDeploy does not allow on-premises instance tags that have values only.

      For example:

      Copy
      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 AWS CodeDeploy console at https://console.aws.amazon.com/codedeploy.

    Note

    Sign in with the same account or IAM user information you used in Getting Started.

  2. From the AWS CodeDeploy menu, choose On-premises instances.

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

  4. In the list of tags, select or type the desired tag key and tag value. After you type 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 ( ).

  5. After you have added tags, choose Update Tags.

Step 10: Deploy Application Revisions to the On-Premises Instance

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. 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 in the Tutorial: Deploy an Application to an On-Premises Instance.

Important

If you reuse an AWS 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 3: Create a Service Role.

Step 11: Track Deployments to the On-Premises Instance

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 Deployment Details.