

# Tutorial: Use CodeDeploy to deploy an application from GitHub
<a name="tutorials-github"></a>

In this tutorial, you use CodeDeploy to deploy a sample application revision from GitHub to a single Amazon EC2 instance running Amazon Linux, a single Red Hat Enterprise Linux (RHEL) instance, or a single Windows Server instance. For information about GitHub integration with CodeDeploy, see [Integrating CodeDeploy with GitHub](integrations-partners-github.md).

**Note**  
You can also use CodeDeploy to deploy an application revision from GitHub to an Ubuntu Server instance. You can use the sample revision described in [Step 2: Create a sample application revision](tutorials-on-premises-instance-2-create-sample-revision.md) in [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), or you can create a revision compatible with an Ubuntu Server instance and CodeDeploy. To create your own revision, see [Plan a revision for CodeDeploy](application-revisions-plan.md) and [Add an application specification file to a revision for CodeDeploy](application-revisions-appspec-file.md).

**Topics**
+ [Prerequisites](tutorials-github-prerequisites.md)
+ [Step 1: Set up a GitHub account](tutorials-github-create-github-account.md)
+ [Step 2: Create a GitHub repository](tutorials-github-create-github-repository.md)
+ [Step 3: Upload a sample application to your GitHub repository](tutorials-github-upload-sample-revision.md)
+ [Step 4: Provision an instance](tutorials-github-provision-instance.md)
+ [Step 5: Create an application and deployment group](tutorials-github-create-application.md)
+ [Step 6: Deploy the application to the instance](tutorials-github-deploy-application.md)
+ [Step 7: Monitor and verify the deployment](tutorials-github-verify.md)
+ [Step 8: Clean up](tutorials-github-clean-up.md)

# Prerequisites
<a name="tutorials-github-prerequisites"></a>

Before you start this tutorial, do the following:
+ Install Git on your local machine. To install Git, see [Git downloads](http://git-scm.com/downloads).
+ Complete the steps in [Getting started with CodeDeploy](getting-started-codedeploy.md), including installing and configuring the AWS CLI. This is especially important if you want to use the AWS CLI to deploy a revision from GitHub to the instance.

# Step 1: Set up a GitHub account
<a name="tutorials-github-create-github-account"></a>

You will need a GitHub account to create a GitHub repository where the revision will be stored. If you already have a GitHub account, skip ahead to [Step 2: Create a GitHub repository](tutorials-github-create-github-repository.md).

1. Go to [https://github.com/join](https://github.com).

1. Type a user name, your email address, and a password.

1. Choose **Sign up for GitHub**, and then follow the instructions.

# Step 2: Create a GitHub repository
<a name="tutorials-github-create-github-repository"></a>

You will need a GitHub repository to store the revision.

If you already have a GitHub repository, be sure to substitute its name for **CodeDeployGitHubDemo** throughout this tutorial, and then skip ahead to [Step 3: Upload a sample application to your GitHub repository](tutorials-github-upload-sample-revision.md). 

1. On the [GitHub home page](https://github.com/dashboard), do one of the following:
   + In **Your repositories**, choose **New repository**.
   + On the navigation bar, choose **Create new** (**\$1**), and then choose **New repository**.

1. In the **Create a new repository** page, do the following:
   + In the **Repository name** box, enter **CodeDeployGitHubDemo**.
   + Select **Public**.
**Note**  
Selecting the default **Public** option means that anyone can see this repository. You can select the **Private** option to limit who can see and commit to the repository. 
   + Clear the **Initialize this repository with a README** check box. You will create a `README.md` file manually in the next step instead.
   + Choose **Create repository**.

1. Follow the instructions for your local machine type to use the command line to create the repository.
**Note**  
If you have enabled two-factor authentication on GitHub, make sure you enter your personal access token instead of your GitHub login password if prompted for a password. For information, see [Providing your 2FA authentication code](https://help.github.com/articles/providing-your-2fa-authentication-code/).

**On local Linux, macOS, or Unix machines:**

1. From the terminal, run the following commands, one at a time, where *user-name* is your GitHub user name:

   ```
   mkdir /tmp/CodeDeployGitHubDemo
   ```

   ```
   cd /tmp/CodeDeployGitHubDemo
   ```

   ```
   touch README.md
   ```

   ```
   git init
   ```

   ```
   git add README.md
   ```

   ```
   git commit -m "My first commit"
   ```

   ```
   git remote add origin https://github.com/user-name/CodeDeployGitHubDemo.git
   ```

   ```
   git push -u origin master
   ```

1. Leave the terminal open in the `/tmp/CodeDeployGitHubDemo` location.

**On local Windows machines:**

1. From a command prompt running as an administrator, run the following commands, one at a time:

   ```
   mkdir c:\temp\CodeDeployGitHubDemo
   ```

   ```
   cd c:\temp\CodeDeployGitHubDemo
   ```

   ```
   notepad README.md
   ```

1. In Notepad, save the `README.md` file. Close Notepad. Run the following commands, one at a time, where *user-name* is your GitHub user name:

   ```
   git init
   ```

   ```
   git add README.md
   ```

   ```
   git commit -m "My first commit"
   ```

   ```
   git remote add origin https://github.com/user-name/CodeDeployGitHubDemo.git
   ```

   ```
   git push -u origin master
   ```

1. Leave the command prompt open in the `c:\temp\CodeDeployGitHubDemo` location.

# Step 3: Upload a sample application to your GitHub repository
<a name="tutorials-github-upload-sample-revision"></a>

In this step, you will copy a sample revision from a public Amazon S3 bucket to your GitHub repository. (For simplicity, the sample revisions provided for this tutorial are single web pages.)

**Note**  
If you use one of your revisions instead of our sample revision, your revision must:   
Follow the guidelines in [Plan a revision for CodeDeploy](application-revisions-plan.md) and [Add an application specification file to a revision for CodeDeploy](application-revisions-appspec-file.md).
Work with the corresponding instance type.
Be accessible from your GitHub dashboard.
If your revision meets these requirements, skip ahead to [Step 5: Create an application and deployment group](tutorials-github-create-application.md).  
If you're deploying to an Ubuntu Server instance, you'll need to upload to your GitHub repository a revision compatible with an Ubuntu Server instance and CodeDeploy. For more information, see [Plan a revision for CodeDeploy](application-revisions-plan.md) and [Add an application specification file to a revision for CodeDeploy](application-revisions-appspec-file.md).

**Topics**
+ [Push a sample revision from a local Linux, macOS, or Unix machine](#tutorials-github-upload-sample-revision-unixes)
+ [Push a sample revision from a local Windows machine](#tutorials-github-upload-sample-revision-windows)

## Push a sample revision from a local Linux, macOS, or Unix machine
<a name="tutorials-github-upload-sample-revision-unixes"></a>

With your terminal still open in, for example, the `/tmp/CodeDeployGitHubDemo` location, run the following commands one at a time: 

**Note**  
If you plan to deploy to a Windows Server instance, substitute `SampleApp_Windows.zip` for `SampleApp_Linux.zip` in the commands.

```
(Amazon S3 copy command)
```

```
unzip SampleApp_Linux.zip
```

```
rm SampleApp_Linux.zip
```

 

```
git add .
```

```
git commit -m "Added sample app"
```

```
git push
```

Where *(Amazon S3 copy command)* is one of the following: 
+ `aws s3 cp s3://aws-codedeploy-us-east-2/samples/latest/SampleApp_Linux.zip . --region us-east-2` for the US East (Ohio) region
+ `aws s3 cp s3://aws-codedeploy-us-east-1/samples/latest/SampleApp_Linux.zip . --region us-east-1` for the US East (N. Virginia) region
+ `aws s3 cp s3://aws-codedeploy-us-west-1/samples/latest/SampleApp_Linux.zip . --region us-west-1` for the US West (N. California) Region
+ `aws s3 cp s3://aws-codedeploy-us-west-2/samples/latest/SampleApp_Linux.zip . --region us-west-2` for the US West (Oregon) region
+ `aws s3 cp s3://aws-codedeploy-ca-central-1/samples/latest/SampleApp_Linux.zip . --region ca-central-1` for the Canada (Central) Region
+ `aws s3 cp s3://aws-codedeploy-eu-west-1/samples/latest/SampleApp_Linux.zip . --region eu-west-1` for the Europe (Ireland) region 
+ `aws s3 cp s3://aws-codedeploy-eu-west-2/samples/latest/SampleApp_Linux.zip . --region eu-west-2` for the Europe (London) region 
+ `aws s3 cp s3://aws-codedeploy-eu-west-3/samples/latest/SampleApp_Linux.zip . --region eu-west-3` for the Europe (Paris) region 
+ `aws s3 cp s3://aws-codedeploy-eu-central-1/samples/latest/SampleApp_Linux.zip . --region eu-central-1` for the Europe (Frankfurt) Region
+ `aws s3 cp s3://aws-codedeploy-il-central-1/samples/latest/SampleApp_Linux.zip . --region il-central-1` for the Israel (Tel Aviv) Region
+ `aws s3 cp s3://aws-codedeploy-ap-east-1/samples/latest/SampleApp_Linux.zip . --region ap-east-1` for the Asia Pacific (Hong Kong) region
+ `aws s3 cp s3://aws-codedeploy-ap-northeast-1/samples/latest/SampleApp_Linux.zip . --region ap-northeast-1` for the Asia Pacific (Tokyo) region
+ `aws s3 cp s3://aws-codedeploy-ap-northeast-2/samples/latest/SampleApp_Linux.zip . --region ap-northeast-2` for the Asia Pacific (Seoul) region
+ `aws s3 cp s3://aws-codedeploy-ap-southeast-1/samples/latest/SampleApp_Linux.zip . --region ap-southeast-1` for the Asia Pacific (Singapore) Region
+ `aws s3 cp s3://aws-codedeploy-ap-southeast-2/samples/latest/SampleApp_Linux.zip . --region ap-southeast-2` for the Asia Pacific (Sydney) region
+ `aws s3 cp s3://aws-codedeploy-ap-southeast-4/samples/latest/SampleApp_Linux.zip . --region ap-southeast-4` for the Asia Pacific (Melbourne) region
+ `aws s3 cp s3://aws-codedeploy-ap-south-1/samples/latest/SampleApp_Linux.zip . --region ap-south-1` for the Asia Pacific (Mumbai) region
+ `aws s3 cp s3://aws-codedeploy-sa-east-1/samples/latest/SampleApp_Linux.zip . --region sa-east-1` for the South America (São Paulo) Region

## Push a sample revision from a local Windows machine
<a name="tutorials-github-upload-sample-revision-windows"></a>

 With your command prompt still open in, for example, the `c:\temp\CodeDeployGitHubDemo` location , run the following commands one at a time:

**Note**  
If you plan to deploy to an Amazon Linux or RHEL instance, substitute `SampleApp_Linux.zip` for `SampleApp_Windows.zip` in the commands.

```
(Amazon S3 copy command)
```

Unzip the contents of `the` the ZIP file directly into the local directory (for example `c:\temp\CodeDeployGitHubDemo`), not into a new subdirectory.

```
git add .
```

```
git commit -m "Added sample app"
```

```
git push
```

Where *(Amazon S3 copy command)* is one of the following: 
+ `aws s3 cp s3://aws-codedeploy-us-east-2/samples/latest/SampleApp_Windows.zip . --region us-east-2` for the US East (Ohio) region
+ `aws s3 cp s3://aws-codedeploy-us-east-1/samples/latest/SampleApp_Windows.zip . --region us-east-1` for the US East (N. Virginia) region
+ `aws s3 cp s3://aws-codedeploy-us-west-1/samples/latest/SampleApp_Windows.zip . --region us-west-1` for the US West (N. California) Region
+ `aws s3 cp s3://aws-codedeploy-us-west-2/samples/latest/SampleApp_Windows.zip . --region us-west-2` for the US West (Oregon) region
+ `aws s3 cp s3://aws-codedeploy-ca-central-1/samples/latest/SampleApp_Windows.zip . --region ca-central-1` for the Canada (Central) Region
+ `aws s3 cp s3://aws-codedeploy-eu-west-1/samples/latest/SampleApp_Windows.zip . --region eu-west-1` for the Europe (Ireland) region
+ `aws s3 cp s3://aws-codedeploy-eu-west-2/samples/latest/SampleApp_Windows.zip . --region eu-west-2` for the Europe (London) region
+ `aws s3 cp s3://aws-codedeploy-eu-west-3/samples/latest/SampleApp_Windows.zip . --region eu-west-3` for the Europe (Paris) region
+ `aws s3 cp s3://aws-codedeploy-eu-central-1/samples/latest/SampleApp_Windows.zip . --region eu-central-1` for the Europe (Frankfurt) Region
+ `aws s3 cp s3://aws-codedeploy-il-central-1/samples/latest/SampleApp_Windows.zip . --region il-central-1` for the Israel (Tel Aviv) Region
+ `aws s3 cp s3://aws-codedeploy-ap-east-1/samples/latest/SampleApp_Windows.zip . --region ap-east-1` for the Asia Pacific (Hong Kong) region
+ `aws s3 cp s3://aws-codedeploy-ap-northeast-1/samples/latest/SampleApp_Windows.zip . --region ap-northeast-1` for the Asia Pacific (Tokyo) region
+ `aws s3 cp s3://aws-codedeploy-ap-northeast-2/samples/latest/SampleApp_Windows.zip . --region ap-northeast-2` for the Asia Pacific (Seoul) region
+ `aws s3 cp s3://aws-codedeploy-ap-southeast-1/samples/latest/SampleApp_Windows.zip . --region ap-southeast-1` for the Asia Pacific (Singapore) Region
+ `aws s3 cp s3://aws-codedeploy-ap-southeast-2/samples/latest/SampleApp_Windows.zip . --region ap-southeast-2` for the Asia Pacific (Sydney) region
+ `aws s3 cp s3://aws-codedeploy-ap-southeast-4/samples/latest/SampleApp_Windows.zip . --region ap-southeast-4` for the Asia Pacific (Melbourne) region
+ `aws s3 cp s3://aws-codedeploy-ap-south-1/samples/latest/SampleApp_Windows.zip . --region ap-south-1` for the Asia Pacific (Mumbai) region
+ `aws s3 cp s3://aws-codedeploy-sa-east-1/samples/latest/SampleApp_Windows.zip . --region sa-east-1` for the South America (São Paulo) Region

To push your own revision to an Ubuntu Server instance, copy your revision into your local repo, and then call the following:

```
git add .
git commit -m "Added Ubuntu app"
git push
```

# Step 4: Provision an instance
<a name="tutorials-github-provision-instance"></a>

In this step, you will create or configure the instance that you will deploy the sample application to. You can deploy to an Amazon EC2 instance or an on-premises instance that is running one of the operating systems supported by CodeDeploy. For information see [Operating systems supported by the CodeDeploy agent](codedeploy-agent.md#codedeploy-agent-supported-operating-systems). (If you already have an instance configured for use in CodeDeploy deployments, skip to the next step.)

**To provision an instance**

1. Follow the instructions in [Launch an Amazon EC2 instance (console)](instances-ec2-create.md#instances-ec2-create-console) to provision an instance.

1. When launching the instance, remember to specify a tag on the **Add tags** page. For details on how to specify the tag, see [Launch an Amazon EC2 instance (console)](instances-ec2-create.md#instances-ec2-create-console).

**To verify that the CodeDeploy agent is running on the instance**
+ Follow the instructions in [Verify the CodeDeploy agent is running](codedeploy-agent-operations-verify.md) to verify that the agent is running.

After you have successfully provisioned the instance and verified the CodeDeploy agent is running, go to the next step.

# Step 5: Create an application and deployment group
<a name="tutorials-github-create-application"></a>

In this step, you will use the CodeDeploy console or the AWS CLI to create an application and deployment group to use to deploy the sample revision from your GitHub repository.



## Create an application and deployment group (console)
<a name="tutorials-github-create-application-console"></a>

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**, then choose **Applications**.

   

1. Choose **Create application**, and then select **Custom application**.

1. In **Application name**, enter **CodeDeployGitHubDemo-App**.

1. In **Compute Platform**, choose **EC2/On-premises**.

1. Choose **Create application**.

1. On the **Deployment groups** tab, choose **Create deployment group**.

1. In **Deployment group name**, enter **CodeDeployGitHubDemo-DepGrp**.

1. In **Service role**, choose the name of your CodeDeploy service role that you created in [Create a service role for CodeDeploy](getting-started-create-service-role.md).

1. In **Deployment type**, choose **In-place**.

1. In **Environment configuration**, depending on the type of instance you are using, choose **Amazon EC2 instances** or **On-premises instances**. For **Key** and **Value**, enter the instance tag key and value that was applied to your instance as part of [Step 4: Provision an instance](tutorials-github-provision-instance.md).

1. In **Deployment configuration**, choose **CodeDeployDefault.AllatOnce**.

1. In **Load Balancer**, clear **Enable load balancing**.

1. Expand **Advanced**.

1. In **Alarms**, select **Ignore alarm configuration**.

1. Choose **Create deployment group**, and continue to the next step. 

## Create an application and deployment group (CLI)
<a name="tutorials-github-create-application-cli"></a>

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

   ```
   aws deploy create-application --application-name CodeDeployGitHubDemo-App
   ```

1. 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](tutorials-github-provision-instance.md).
   + 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](tutorials-github-provision-instance.md).
   + 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](tutorials-github-provision-instance.md).
   + 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](tutorials-github-provision-instance.md).
   + *service-role-arn* is the service role ARN for the service role that you created in [Create a service role for CodeDeploy](getting-started-create-service-role.md). (Follow the instructions in [Get the service role ARN (CLI)](getting-started-create-service-role.md#getting-started-get-service-role-cli) to find the service role ARN.)

   ```
   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](https://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment-group.html) 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 monitoring thresholds in Amazon CloudWatch alarms are met. Commands for these actions are not included in this tutorial.

# Step 6: Deploy the application to the instance
<a name="tutorials-github-deploy-application"></a>

In this step, you use the CodeDeploy console or the AWS CLI to deploy the sample revision from your GitHub repository to your instance. 



## To deploy the revision (console)
<a name="tutorials-github-deploy-application-console"></a>

1. On the **Deployment group details** page, choose **Create deployment**.

1. In **Deployment group**, choose **`CodeDeployGitHubDemo-DepGrp`**.

1. In **Revision type**, choose **GitHub**.

1. In **Connect to GitHub**, do one of the following:
   + To create a connection for CodeDeploy applications to a GitHub account, sign out of GitHub in a separate web browser tab. In **GitHub account**, enter a name to identify this connection, and then choose **Connect to GitHub**. The webpage prompts you to authorize CodeDeploy to interact with GitHub for the application named `CodeDeployGitHubDemo-App`. Continue to step 5.
   + To use a connection you have already created, in **GitHub account**, select its name, and then choose **Connect to GitHub**. Continue to step 7.
   + To create a connection to a different GitHub account, sign out of GitHub in a separate web browser tab. Choose **Connect to a different GitHub account**, and then choose **Connect to GitHub**. Continue to step 5.

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

1. On the **Authorize application** page, choose **Authorize application**. 

1. On the CodeDeploy **Create deployment** page, in **Repository name**, enter 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 enter, or if you want to specify a different repository:

   1. In a separate web browser tab, go to your [GitHub dashboard](https://github.com/dashboard).

   1. 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. Enter this value into **Repository name**.
**Note**  
If the target repository name is not displayed in **Your repositories**, use the **Search GitHub** box to find the target repository and GitHub user or organization name.

1. In the **Commit ID** box, enter the ID of the commit associated with the push of your application revision to GitHub.

   If you are unsure of the value to enter:

   1. In a separate web browser tab, go to your [GitHub dashboard](https://github.com/dashboard).

   1. In **Your repositories**, choose **CodeDeployGitHubDemo**.

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

   1. Paste the commit ID into the **Commit ID** box.

1. Choose **Deploy**, and continue to the next step. 

## To deploy the revision (CLI)
<a name="tutorials-github-deploy-application-cli"></a>

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 CodeDeploy permission to use your GitHub user account to interact with GitHub for the `CodeDeployGitHubDemo-App` application. Currently, you must use the CodeDeploy console to do this.

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**, then choose **Applications**.

   

1. Choose **CodeDeployGitHubDemo-App**.

1. On the **Deployments** tab, choose **Create deployment**.
**Note**  
You will not be creating a new deployment. This is currently the only way to give CodeDeploy permission to interact with GitHub on behalf of your GitHub user account.

1. From **Deployment group**, choose **CodeDeployGitHubDemo-DepGrp**.

1. In **Revision type**, choose **GitHub**.

1. In **Connect to GitHub**, do one of the following:
   + To create a connection for CodeDeploy applications to a GitHub account, sign out of GitHub in a separate web browser tab. In **GitHub account**, type a name to identify this connection, and then choose **Connect to GitHub**. The web page prompts you to authorize CodeDeploy to interact with GitHub for the application named `CodeDeployGitHubDemo-App`. Continue to step 8.
   + To use a connection you have already created, in **GitHub account**, select its name, and then choose **Connect to GitHub**. Continue to step 10.
   + To create a connection to a different GitHub account, sign out of GitHub in a separate web browser tab. Choose **Connect to a different GitHub account**, and then choose **Connect to GitHub**. Continue to step 8.

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

1. On the **Authorize application** page, choose **Authorize application**. 

1. On the CodeDeploy **Create deployment** page, choose **Cancel**.

1. 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](https://github.com/dashboard).

     1. 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](https://github.com/dashboard).

     1. In **Your repositories**, choose **CodeDeployGitHubDemo**.

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

   If you are working on a local Linux, macOS, or Unix machine:

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

   If you are working on a local Windows machine:

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

# Step 7: Monitor and verify the deployment
<a name="tutorials-github-verify"></a>

In this step, you will use the CodeDeploy console or the AWS CLI to verify the success of the deployment. You will use your web browser to view the web page that was deployed to the instance you created or configured.

**Note**  
If you're deploying to an Ubuntu Server instance, use your own testing strategy to determine whether the deployed revision works as expected on the instance, and then go to the next step.

**To monitor and verify the deployment (console)**

1. In the navigation pane, expand **Deploy**, and then choose **Deployments**.

   

1. In the list of deployments, look for the row with an **Application** value of **CodeDeployGitHubDemo-App** and a **Deployment Group** value of **CodeDeployGitHubDemo-DepGrp**. If **Succeeded** or **Failed** do not appear in the **Status** column, choose the **Refresh** button periodically.

1. If **Failed** appears in the **Status** column, follow the instructions in [View instance details (console)](instances-view-details.md#instances-view-details-console) to troubleshoot the deployment.

1. If **Succeeded** appears in the **Status** column, you can now verify the deployment through your web browser. Our sample revision deploys a single web page to the instance. If you're deploying to an Amazon EC2 instance, in your web browser, go to `http://public-dns` for the instance (for example, `http://ec2-01-234-567-890.compute-1.amazonaws.com`).

1. If you can see the web page, then congratulations\$1 Now that you've successfully used AWS CodeDeploy to deploy a revision from GitHub, you can skip ahead to [Step 8: Clean up](tutorials-github-clean-up.md).

**To monitor and verify the deployment (CLI)**

1. Call the **list-deployments** command to get the deployment ID for the application named `CodeDeployGitHubDemo-App` and the deployment group named `CodeDeployGitHubDemo-DepGrp`:

   ```
   aws deploy list-deployments --application-name CodeDeployGitHubDemo-App --deployment-group-name CodeDeployGitHubDemo-DepGrp --query "deployments" --output text
   ```

1. Call the **get-deployment** command, supplying the ID of the deployment in the output from the **list-deployments** command:

   ```
   aws deploy get-deployment --deployment-id deployment-id --query "deploymentInfo.[status, creator]" --output text
   ```

1. If **Failed** is returned, follow the instructions in [View instance details (console)](instances-view-details.md#instances-view-details-console) to troubleshoot the deployment.

1. If **Succeeded** is returned, you can now try verifying the deployment through your web browser. Our sample revision is a single web page deployed to the instance. If you're deploying to an Amazon EC2 instance, you can view this page in your web browser by going to `http://public-dns` for the Amazon EC2 instance (for example, `http://ec2-01-234-567-890.compute-1.amazonaws.com`).

1. If you can see the web page, then congratulations\$1 You have successfully used AWS CodeDeploy to deploy from your GitHub repository.

# Step 8: Clean up
<a name="tutorials-github-clean-up"></a>

To avoid further charges for resources you used during this tutorial, you must terminate the Amazon EC2 instance and its associated resources. Optionally, you can delete the CodeDeploy deployment component records associated with this tutorial. If you were using a GitHub repository just for this tutorial, you can delete it now, too.

## To delete a CloudFormation stack (if you used the CloudFormation template to create an Amazon EC2 instance)
<a name="tutorials-github-clean-up-cloudformation-template"></a>

1. Sign in to the AWS Management Console and open the CloudFormation console at [https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/).

1. In the **Stacks** column, choose the stack starting with `CodeDeploySampleStack`.

1. Choose **Delete**.

1. When prompted, choose **Delete stack**. The Amazon EC2 instance and the associated IAM instance profile and service role are deleted.

## To manually deregister and clean up an on-premises instance (if you provisioned an on-premises instance)
<a name="tutorials-github-clean-up-on-premises-instance"></a>

1. Use the AWS CLI to call the [deregister](https://docs.aws.amazon.com/cli/latest/reference/deploy/deregister.html) command against the on-premises instance represented here by *your-instance-name* and the associated region by *your-region*:

   ```
   aws deploy deregister --instance-name your-instance-name --no-delete-iam-user --region your-region
   ```

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

   ```
   aws deploy uninstall
   ```

## To manually terminate an Amazon EC2 instance (if you manually launched an Amazon EC2 instance)
<a name="tutorials-github-clean-up-ec2-instance"></a>

1. Sign in to the AWS Management Console and open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, under **Instances**, choose **Instances**.

1. Select the box next to the Amazon EC2 instance you want to terminate. In the **Actions** menu, point to **Instance State**, and then choose **Terminate**.

1. When prompted, choose **Yes, Terminate**. 

## To delete the CodeDeploy deployment component records
<a name="tutorials-github-clean-up-codedeploy-records"></a>

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**, then choose **Applications**.

   

1. Choose **CodeDeployGitHubDemo-App**.

1. Choose **Delete application**.

1. When prompted, enter **Delete**, and then choose **Delete**. 

## To delete your GitHub repository
<a name="tutorials-github-clean-up-github-repository"></a>

See [Deleting a repository](https://help.github.com/articles/deleting-a-repository/) in [GitHub help](https://help.github.com).