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

Step 5: Deploy the Application to the Instance

In this step, you will use the AWS CodeDeploy console or the AWS CLI to deploy the sample revision from your GitHub repository to your instance. If you're using one of our sample revisions to deploy to an Amazon EC2 instance running Amazon Linux, RHEL, or Windows Server, our sample revision is a single web page deployed to the instance.

To deploy the revision (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. If the Applications page is not displayed, on the AWS CodeDeploy menu, choose Applications.

  3. Choose Create application.

  4. In the Application name box, type CodeDeployGitHubDemo-App.

  5. In the Deployment group name box, type CodeDeployGitHubDemo-DepGrp.

  6. Choose a tag type for your instance.

    If you're deploying to an Amazon EC2 instance, choose Amazon EC2 from the Tag type drop-down list. In the Key and Value boxes, type the Amazon EC2 instance tag key and value that was applied to your Amazon EC2 instance as part of Step 4: Provision an Instance.

    If you're deploying to an on-premises instance, choose On-premises instance from the Tag type drop-down list. In the Key and Value boxes, type the on-premises instance tag key and value that was applied to your on-premises instance as part of Step 4: Provision an Instance.

  7. In the Deployment configuration drop-down list, leave the default of CodeDeployDefault.OneAtATime.

  8. In the Service role ARN drop-down list, choose the service role ARN. (Follow the instructions in Get the Service Role ARN (Console) to find the service role ARN.)

  9. Choose Create application.

  10. On the Application details page, in Deployment groups, choose the button next to CodeDeployGitHubDemo-DepGrp.

  11. In the Actions menu, choose Deploy new revision.

  12. On the Create deployment page, in the Revision type area, choose My application is stored in GitHub.

  13. Choose Connect with GitHub. The web page that appears will prompt you to authorize AWS CodeDeploy to interact with GitHub for the application named CodeDeployGitHubDemo-App.

    Note

    If you see a Reconnect with GitHub link instead of a Connect with GitHub button, this is expected behavior. Do not choose the link. Continue to the next step. For information about why this happens, see GitHub Authentication with Applications in AWS CodeDeploy.

    If you see a blank web page that briefly appears and then disappears, and you do not see a Reconnect with GitHub link or a Connect with GitHub button, this is also expected behavior. Continue to the next step. For information about why this happens, see GitHub Authentication with Applications in AWS CodeDeploy.

  14. Follow the instructions on the Sign in page to sign in with your GitHub account.

  15. On the Authorize application page, choose Authorize application.

  16. On the AWS CodeDeploy Create deployment page, in the Repository name box, type the GitHub user name you used to sign in, followed by a forward slash (/), followed by the name of the repository where you pushed your application revision (for example, my-github-user-name/CodeDeployGitHubDemo).

    If you are unsure of the value to type, or if you want to specify a different repository:

    1. In a separate web browser tab, go to your GitHub dashboard.

    2. In Your repositories, hover your mouse pointer over the target repository name. A tooltip appears, displaying the GitHub user or organization name, followed by a forward slash character (/), followed by the name of the repository. Type this displayed value into the Repository Name box.

      Note

      If the target repository name is not displayed in Your repositories, use the Search GitHub box to find the target repository and corresponding GitHub user or organization name.

  17. In the Commit ID box, type the ID of the commit associated with the push of your application revision to GitHub.

    If you are unsure of the value to type:

    1. In a separate web browser tab, go to your GitHub dashboard.

    2. In Your repositories, choose CodeDeployGitHubDemo.

    3. In the list of commits, find and copy the commit ID associated with the push of your application revision to GitHub. This ID is typically 40 characters in length and consists of both letters and numbers. (Do not use the shorter version of the commit ID, which is typically the first 10 characters of the longer version.)

    4. Paste the commit ID into the Commit ID box.

  18. Leave the Deployment description box blank.

  19. Leave the Deployment configuration drop-down list at the default of CodeDeployDefault.OneAtATime, and choose Deploy.

Now that you've used the AWS CodeDeploy console to deploy the revision to the instance, you can skip ahead to Step 6: Monitor and Verify the Deployment.

To deploy the revision (CLI)

  1. Call the create-application command to create an application in AWS CodeDeploy named CodeDeployGitHubDemo-App:

    Copy
    aws deploy create-application --application-name CodeDeployGitHubDemo-App
  2. Call the create-deployment-group command to create a deployment group named CodeDeployGitHubDemo-DepGrp:

    • If you're deploying to an Amazon EC2 instance, ec2-tag-key is the Amazon EC2 instance tag key that was applied to your Amazon EC2 instance as part of Step 4: Provision an Instance.

    • If you're deploying to an Amazon EC2 instance, ec2-tag-value is the Amazon EC2 instance tag value that was applied to your Amazon EC2 instance as part of Step 4: Provision an Instance.

    • If you're deploying to an on-premises instance, on-premises-tag-key is the on-premises instance tag key that was applied to your on-premises instance as part of Step 4: Provision an Instance.

    • If you're deploying to an on-premises instance, on-premises-tag-value is the on-premises instance tag value that was applied to your on-premises instance as part of Step 4: Provision an Instance.

    • service-role-arn is a service role ARN. (Follow the instructions in Get the Service Role ARN (CLI) to find the service role ARN.)

    Copy
    aws deploy create-deployment-group --application-name CodeDeployGitHubDemo-App --ec2-tag-filters Key=ec2-tag-key,Type=KEY_AND_VALUE,Value=ec2-tag-value --on-premises-tag-filters Key=on-premises-tag-key,Type=KEY_AND_VALUE,Value=on-premises-tag-value --deployment-group-name CodeDeployGitHubDemo-DepGrp --service-role-arn service-role-arn

    Note

    The create-deployment-group command provides support for creating triggers that result in the sending of Amazon SNS notifications to topic subscribers about specified events in deployments and instances. The command also supports options for automatically rolling back deployments and setting up alarms to stop deployments when certain monitoring thresholds are met in Amazon CloudWatch Alarms. Commands for these actions are excluded from the sample in this tutorial.

  3. Before you can call any AWS CLI commands that interact with GitHub (such as the create-deployment command, which you will call next), you must give AWS CodeDeploy permission to use your GitHub user account to interact with GitHub for the CodeDeployGitHubDemo-App application. Currently, you must use the AWS CodeDeploy console to do this.

    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.

  4. On the AWS CodeDeploy menu, choose Deployments.

  5. Choose Create deployment.

    Note

    You will not be creating a new deployment. This is currently the only way to give AWS CodeDeploy permission to interact with GitHub on behalf of your GitHub user account.

  6. From the Application drop-down list, choose CodeDeployGitHubDemo-App.

  7. From the Deployment group drop-down list, choose CodeDeployGitHubDemo-DepGrp.

  8. In the Revision type area, choose My application is stored in GitHub.

  9. Choose Connect With GitHub.

    Note

    If you see a Reconnect with GitHub link instead of a Connect with GitHub button, this is expected behavior. Do not choose the link. Continue to the next step. For information about why this happens, see GitHub Authentication with Applications in AWS CodeDeploy.

    If you see a blank web page that briefly appears and then disappears, and you don't see a Reconnect with GitHub link or a Connect with GitHub button, this also expected behavior. Continue to the next step. For information about why this happens, see GitHub Authentication with Applications in AWS CodeDeploy.

  10. Follow the instructions on the Sign in page to sign in with your GitHub user name or email and password.

  11. On the Authorize application page, choose Authorize application.

  12. On the AWS CodeDeploy Create deployment page, choose Cancel.

  13. Call the create-deployment command to deploy the revision from your GitHub repository to the instance, where:

    • repository is your GitHub account name, followed by a forward-slash (/), followed by the name of your repository (CodeDeployGitHubDemo), for example, MyGitHubUserName/CodeDeployGitHubDemo.

      If you are unsure of the value to use, or if you want to specify a different repository:

      1. In a separate web browser tab, go to your GitHub dashboard.

      2. In Your repositories, hover your mouse pointer over the target repository name. A tooltip appears, displaying the GitHub user or organization name, followed by a forward slash (/), followed by the name of the repository. This is the value to use.

        Note

        If the target repository name does not appear in Your repositories, use the Search GitHub box to find the target repository and corresponding GitHub user or organization name.

    • commit-id is the commit associated with the version of the application revision you pushed to your repository (for example, f835159a...528eb76f).

      If you are unsure of the value to use:

      1. In a separate web browser tab, go to your GitHub dashboard.

      2. In Your repositories, choose CodeDeployGitHubDemo.

      3. In the list of commits, find the commit ID associated with the push of your application revision to GitHub. This ID is typically 40 characters in length and consists of both letters and numbers. (Do not use the shorter version of the commit ID, which is typically the first 10 characters of the longer version.) Use this value.

    For Linux, macOS, or Unix:

    Copy
    aws deploy create-deployment \ --application-name CodeDeployGitHubDemo-App \ --deployment-config-name CodeDeployDefault.OneAtATime \ --deployment-group-name CodeDeployGitHubDemo-DepGrp \ --description "My GitHub deployment demo" \ --github-location repository=repository,commitId=commit-id

    For Windows:

    Copy
    aws deploy create-deployment --application-name CodeDeployGitHubDemo-App --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name CodeDeployGitHubDemo-DepGrp --description "My GitHub deployment demo" --github-location repository=repository,commitId=commit-id