

# Tutorial: Deploy a "hello, world\$1" application with CodeDeploy (Windows Server)
<a name="tutorials-windows"></a>

In this tutorial, you deploy a single webpage to a single Windows Server Amazon EC2 instance running Internet Information Services (IIS) as its web server. This webpage displays a simple "Hello, World\$1" message.

Not what you're looking for?
+ To practice deploying to an Amazon Linux or Red Hat Enterprise Linux (RHEL) Amazon EC2 instance instead, see [Tutorial: Deploy WordPress to an Amazon EC2 instance (Amazon Linux or Red Hat Enterprise Linux and Linux, macOS, or Unix)](tutorials-wordpress.md).
+ To practice deploying to an on-premises instance instead, 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).

This tutorial's steps are presented from a Windows perspective. Although you can complete most of these steps on a local machine running Linux, macOS, or Unix, you must adapt those that cover Windows-based directory paths such as `c:\temp`. Also, if you want to connect to the Amazon EC2 instance, you need a client application that can connect through Remote Desktop Protocol (RDP) to the Amazon EC2 instance running Windows Server. (Windows includes an RDP connection client application by default.)

Before you start this tutorial, you must complete the prerequisites in [Getting started with CodeDeploy](getting-started-codedeploy.md), including configuring your user, installing or upgrading the AWS CLI, and creating an IAM instance profile and a service role.

**Topics**
+ [Step 1: Launch a Windows Server Amazon EC2 instance](tutorials-windows-launch-instance.md)
+ [Step 2: Configure your source content to deploy to the Windows Server Amazon EC2 instance](tutorials-windows-configure-content.md)
+ [Step 3: Upload your "hello, world\$1" application to Amazon S3](tutorials-windows-upload-application.md)
+ [Step 4: Deploy your Hello World application](tutorials-windows-deploy-application.md)
+ [Step 5: Update and redeploy your "hello, world\$1" application](tutorials-windows-update-and-redeploy-application.md)
+ [Step 6: Clean up your "hello, world\$1" application and related resources](tutorials-windows-clean-up.md)

# Step 1: Launch a Windows Server Amazon EC2 instance
<a name="tutorials-windows-launch-instance"></a>

To deploy the Hello World application with CodeDeploy, you need an Amazon EC2 instance running Windows Server.

Follow the instructions in [Create an Amazon EC2 instance for CodeDeploy](instances-ec2-create.md). When you are ready to assign an Amazon EC2 instance tag to the instance, be sure to specify the tag key of **Name** and the tag value of **CodeDeployDemo**. (If you specify a different tag key or tag value, then the instructions in [Step 4: Deploy your Hello World application](tutorials-windows-deploy-application.md) might produce unexpected results.)

After you've launched the Amazon EC2 instance, return to this page, and continue to the next section. Do not continue on to [Create an application with CodeDeploy](applications-create.md) as a next step.

## Connect to your Amazon EC2 instance
<a name="tutorials-windows-launch-instance-connect"></a>

After your Amazon EC2 instance is launched, follow these instructions to practice connecting to it. 

**Note**  
In these instructions, we assume you are running Windows and the Windows Desktop Connection client application. For information, see [Connecting to your Windows instance using RDP](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/connecting_to_windows_instance.html). You might need to adapt these instructions for other operating systems or other RDP connection client applications.

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. Browse to and choose your Windows Server instance in the list.

1. Choose **Connect**.

1. Choose **Get Password**, and then choose **Choose File**.

1. Browse to and choose the Amazon EC2 instance key pair file associated with the Windows Server Amazon EC2 instance, and then choose **Open**.

1. Choose **Decrypt Password**. Make a note of the password that is displayed. You need it in step 10.

1. Choose **Download Remote Desktop File**, and then open the file.

1. If you are prompted to connect even though the publisher of the remote connection can't be identified, proceed.

1. Type the password you noted in step 7, and then proceed. (If your RDP connection client application prompts you for a user name, type **Administrator**.)

1. If you are prompted to connect even though the identity of the remote computer cannot be verified, proceed. 

1. After you are connected, the desktop of the Amazon EC2 instance running Windows Server is displayed.

1. You can now disconnect from the Amazon EC2 instance.
**Warning**  
Do not stop or terminate the instance. Otherwise, CodeDeploy can't deploy to it.

## Add an inbound rule that allows HTTP traffic to your Windows Server Amazon EC2 instance
<a name="tutorials-windows-launch-instance-add-inbound-rule"></a>

The next step confirms your Amazon EC2 instance has an open HTTP port so you can see the deployed webpage on your Windows Server Amazon EC2 instance in a browser. 

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. Choose **Instances**, and then choose your instance. 

1. On the **Description** tab, under **Security groups**, choose **view inbound rules**. 

   You should see a list of rules in your security group like the following:

   ```
   Security Groups associated with i-1234567890abcdef0
    Ports     Protocol     Source     launch-wizard-N
    22        tcp          0.0.0.0/0          ✔
   ```

1.  Under **Security groups**, choose the security group for your Amazon EC2 instance. It might be named **launch-wizard-*N***. The ***N*** in the name is a number assigned to your security group when your instance was created. 

    Choose the **Inbound** tab. If the security group for your instance is configured correctly, you should see a rule with the following values: 
   + **Type**: HTTP
   + **Protocol**: TCP
   + **Port Range**: 80
   + **Source**: 0.0.0.0/0

1.  If you do not see a rule with these values, use the procedures in [Adding Rules to a Security Group](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-network-security.html#adding-security-group-rule) to add them to a new security rule. 

# Step 2: Configure your source content to deploy to the Windows Server Amazon EC2 instance
<a name="tutorials-windows-configure-content"></a>

Now it's time to configure your application's source content so you have something you can deploy to the Amazon EC2 instance. For this tutorial, you'll deploy a single web page to the Amazon EC2 instance running Windows Server, which will run Internet Information Services (IIS) as its web server. This web page will display a simple "Hello, World\$1" message.

**Topics**
+ [Create the web page](#tutorials-windows-configure-content-download-code)
+ [Create a script to run your application](#tutorials-windows-configure-content-create-scripts)
+ [Add an application specification file](#tutorials-windows-configure-content-add-appspec-file)

## Create the web page
<a name="tutorials-windows-configure-content-download-code"></a>

1. Create a subdirectory (subfolder) named `HelloWorldApp` in your `c:\temp` folder, and then switch to that folder.

   ```
   mkdir c:\temp\HelloWorldApp
   cd c:\temp\HelloWorldApp
   ```
**Note**  
You don't have to use the location of `c:\temp` or the subfolder name of `HelloWorldApp`. If you use a different location or subfolder name, be sure to use it throughout this tutorial.

1. Use a text editor to create a file inside of the folder. Name the file `index.html`.

   ```
   notepad index.html
   ```

1. Add the following HTML code to the file, and then save the file.

   ```
   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
   <html>
   <head>
     <title>Hello, World!</title>
     <style>
       body {
         color: #ffffff;
         background-color: #0188cc;
         font-family: Arial, sans-serif;  
         font-size:14px;
       }
     </style>
   </head>
   <body>
     <div align="center"><h1>Hello, World!</h1></div>
     <div align="center"><h2>You have successfully deployed an application using CodeDeploy</h2></div>
     <div align="center">
       <p>What to do next? Take a look through the <a href="https://aws.amazon.com/codedeploy">CodeDeploy Documentation</a>.</p>
     </div>
   </body>
   </html>
   ```

## Create a script to run your application
<a name="tutorials-windows-configure-content-create-scripts"></a>

Next, you will create a script that CodeDeploy will use to set up the web server on the target Amazon EC2 instance.

1. In the same subfolder where the `index.html` file is saved, use a text editor to create another file. Name the file `before-install.bat`.

   ```
   notepad before-install.bat
   ```

1. Add the following batch script code to the file, and then save the file.

   ```
   REM Install Internet Information Server (IIS).
   c:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe -Command Import-Module -Name ServerManager
   c:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe -Command Install-WindowsFeature Web-Server
   ```

## Add an application specification file
<a name="tutorials-windows-configure-content-add-appspec-file"></a>

Next, you will add an application specification file (AppSpec file) in addition to the web page and batch script file. The AppSpec file is a [YAML](http://www.yaml.org)-formatted file used by CodeDeploy to: 
+ Map the source files in your application revision to their destinations on the instance.
+ Specify scripts to be run on the instance during the deployment.

The AppSpec file must be named `appspec.yml`. It must be placed in the application source code's root folder.

1. In the same subfolder where the `index.html` and `before-install.bat` files are saved, use a text editor to create another file. Name the file `appspec.yml`.

   ```
   notepad appspec.yml
   ```

1. Add the following YAML code to the file, and then save the file.

   ```
   version: 0.0
   os: windows
   files:
     - source: \index.html
       destination: c:\inetpub\wwwroot
   hooks:
     BeforeInstall:
       - location: \before-install.bat
         timeout: 900
   ```

CodeDeploy will use this AppSpec file to copy the `index.html` file in the application source code's root folder to the `c:\inetpub\wwwroot` folder on the target Amazon EC2 instance. During the deployment, CodeDeploy will run the `before-install.bat` batch script on the target Amazon EC2 instance during the **BeforeInstall** deployment lifecycle event. If this script takes longer than 900 seconds (15 minutes) to run, CodeDeploy will stop the deployment and mark the deployment to the Amazon EC2 instance as failed.

For more information about these settings, see the [CodeDeploy AppSpec file reference](reference-appspec-file.md).

**Important**  
The locations and numbers of spaces between each of the items in this file are important. If the spacing is incorrect, CodeDeploy will raise an error that may be difficult to debug. For more information, see [AppSpec File spacing](reference-appspec-file.md#reference-appspec-file-spacing).

# Step 3: Upload your "hello, world\$1" application to Amazon S3
<a name="tutorials-windows-upload-application"></a>

Now you will prepare and upload your source content to a location from which CodeDeploy can deploy it. The following instructions show you how to provision an Amazon S3 bucket, prepare the application revision's files for the bucket, bundle the revision's files, and then push the revision to the bucket.

**Note**  
Although it's not covered in this tutorial, you can use CodeDeploy to deploy applications from GitHub repositories to instances. For more information, see [Integrating CodeDeploy with GitHub](integrations-partners-github.md).

**Topics**
+ [Provision an Amazon S3 bucket](#tutorials-windows-upload-application-create-s3-bucket)
+ [Prepare the application's files for the bucket](#tutorials-windows-upload-application-prepare-application-files)
+ [Bundle the application's files into a single archive file and push the archive file](#tutorials-windows-upload-application-bundle-and-push-archive)

## Provision an Amazon S3 bucket
<a name="tutorials-windows-upload-application-create-s3-bucket"></a>

Create a storage container or *bucket* in Amazon S3—or use an existing bucket. Make sure you can upload the revision to the bucket and that Amazon EC2 instances used in deployments can download the revision from the bucket.

You can use the AWS CLI, the Amazon S3 console, or the Amazon S3 APIs to create an Amazon S3 bucket. After you create the bucket, make sure to give access permissions to the bucket and your CodeDeploy user.

**Note**  
Bucket names must be unique across Amazon S3 for all AWS accounts. If you aren't able to use **amzn-s3-demo-bucket**, try a different bucket name, such as **amzn-s3-demo-bucket** followed by a dash and your initials or some other unique identifier. Then be sure to substitute your bucket name for **amzn-s3-demo-bucket** wherever you see it throughout this tutorial.  
The Amazon S3 bucket must be created in the same AWS region in which your target Amazon EC2 instances are launched. For example, if you create the bucket in the US East (N. Virginia) Region, then your target Amazon EC2 instances must be launched in the US East (N. Virginia) Region.

**Topics**
+ [To create an Amazon S3 bucket (CLI)](#tutorials-windows-upload-application-create-s3-bucket-cli)
+ [To create an Amazon S3 bucket (console)](#tutorials-windows-upload-application-create-s3-bucket-console)
+ [Give permissions to the Amazon S3 bucket and your AWS account](#tutorials-windows-upload-application-create-s3-bucket-grant-permission)

### To create an Amazon S3 bucket (CLI)
<a name="tutorials-windows-upload-application-create-s3-bucket-cli"></a>

Call the **mb** command to create an Amazon S3 bucket named **amzn-s3-demo-bucket**:

```
aws s3 mb s3://amzn-s3-demo-bucket --region region
```

### To create an Amazon S3 bucket (console)
<a name="tutorials-windows-upload-application-create-s3-bucket-console"></a>

1. Open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. In the Amazon S3 console, choose **Create bucket**.

1. In the **Bucket name** box, type a name for the bucket.

1. In the **Region** list, choose the target region, and then choose **Create**.

### Give permissions to the Amazon S3 bucket and your AWS account
<a name="tutorials-windows-upload-application-create-s3-bucket-grant-permission"></a>

You must have permissions to upload to the Amazon S3 bucket. You can specify these permissions through an Amazon S3 bucket policy. For example, in the following Amazon S3 bucket policy, using the wildcard character (\$1) allows AWS account `111122223333` to upload files to any directory in the Amazon S3 bucket named `amzn-s3-demo-bucket`:

```
{
    "Statement": [
        {
            "Action": [
                "s3:PutObject"
            ],
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
            "Principal": {
                "AWS": [
                    "111122223333"
                ]
            }
        }
    ]
}
```

To view your AWS account ID, see [Finding Your AWS account ID](https://docs.aws.amazon.com/IAM/latest/UserGuide/console_account-alias.html#FindingYourAWSId).

Now is a good time to verify the Amazon S3 bucket will allow download requests from each participating Amazon EC2 instance. You can specify this through an Amazon S3 bucket policy. For example, in the following Amazon S3 bucket policy, using the wildcard character (\$1) allows any Amazon EC2 instance with an attached IAM instance profile containing the ARN `arn:aws:iam::444455556666:role/CodeDeployDemo` to download files from any directory in the Amazon S3 bucket named `amzn-s3-demo-bucket`:

```
{
    "Statement": [
        {
            "Action": [
                "s3:Get*",
                "s3:List*"
            ],
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::444455556666:role/CodeDeployDemo"
                ]
            }
        }
    ]
}
```

For information about how to generate and attach an Amazon S3 bucket policy, see [Bucket policy examples](https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies.html).

The CodeDeploy adminstrative user that you created in [Step 1: Setting up](getting-started-setting-up.md) must also have permission to upload the revision to the Amazon S3 bucket. One way to specify this is through an IAM policy, which you add to the user's permission set, or to an IAM role (which you allow the user to assume). The following IAM policy allows the user to upload revisions anywhere in the Amazon S3 bucket named `amzn-s3-demo-bucket`:

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

****  

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

------

For information about how to create an IAM policy, see [Creating IAM policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html) in the *IAM User Guide*. For information on adding a policy to a permission set, see [Create a permission set](https://docs.aws.amazon.com/singlesignon/latest/userguide/howtocreatepermissionset.html) in the *AWS IAM Identity Center User Guide*.

## Prepare the application's files for the bucket
<a name="tutorials-windows-upload-application-prepare-application-files"></a>

Make sure the web page, the AppSpec file, and the script are organized on your development machine like this:

```
c:\
  |-- temp\
        |--HelloWorldApp\
             |-- appspec.yml
             |-- before-install.bat
             |-- index.html
```

## Bundle the application's files into a single archive file and push the archive file
<a name="tutorials-windows-upload-application-bundle-and-push-archive"></a>

Bundle the files into an archive file (known as an application *revision*).

**Note**  
You may be charged for storing objects in a bucket and for transferring application revisions into and out of a bucket. For more information, see [Amazon S3 pricing](https://aws.amazon.com/s3/pricing/). 

1. On the development machine, switch to the folder where the files are stored: 

   ```
   cd c:\temp\HelloWorldApp
   ```
**Note**  
If you don't switch to this folder, then the file bundling will start at your current folder. For example, if your current folder is `c:\temp` instead of `c:\temp\HelloWorldApp`, the bundling will start with files and subfolders in the `c:\temp` folder, which may include more than the `HelloWorldApp` subfolder.

1. Call the **create-application** command to register a new application named **HelloWorld\$1App** with CodeDeploy:

   ```
   aws deploy create-application --application-name HelloWorld_App
   ```

1. Call the CodeDeploy [push](https://docs.aws.amazon.com/cli/latest/reference/deploy/push.html) command to bundle the files together, upload the revisions to Amazon S3, and register information with CodeDeploy about the uploaded revision, all in one action. 

   ```
   aws deploy push --application-name HelloWorld_App --s3-location s3://amzn-s3-demo-bucket/HelloWorld_App.zip --ignore-hidden-files
   ```

   This command bundles the files from the current directory (excluding any hidden files) into a single archive file named `HelloWorld_App.zip`, uploads the revision to the **amzn-s3-demo-bucket** bucket, and registers information with CodeDeploy about the uploaded revision.

# Step 4: Deploy your Hello World application
<a name="tutorials-windows-deploy-application"></a>

Now you deploy the sample Hello World application revision you uploaded to Amazon S3. You use the AWS CLI or the CodeDeploy console to deploy the revision and monitor the deployment's progress. After the application revision is successfully deployed, you check the results.

**Topics**
+ [Deploy your application revision with CodeDeploy](#tutorials-windows-deploy-application-create-deployment)
+ [Monitor and troubleshoot your deployment](#tutorials-windows-deploy-application-monitor)
+ [Verify your deployment](#tutorials-windows-deploy-application-verify)

## Deploy your application revision with CodeDeploy
<a name="tutorials-windows-deploy-application-create-deployment"></a>

 You can deploy your application using the CLI or the console. 

**Topics**
+ [To deploy your application revision (CLI)](#tutorials-windows-deploy-application-create-deployment-cli)
+ [To deploy your application revision (console)](#tutorials-windows-deploy-application-create-deployment-console)

### To deploy your application revision (CLI)
<a name="tutorials-windows-deploy-application-create-deployment-cli"></a>

1. First, the deployment needs a deployment group. However, before you create the deployment group, you need a service role ARN. A service role is an IAM role that gives a service permission to act on your behalf. In this case, the service role gives CodeDeploy permission to access your Amazon EC2 instances to expand (read) their Amazon EC2 instance tags.

   You should have already followed the instructions in [Create a service role (CLI)](getting-started-create-service-role.md#getting-started-create-service-role-cli) to create a service role. To get the ARN of the service role, see [Get the service role ARN (CLI)](getting-started-create-service-role.md#getting-started-get-service-role-cli).

1. Now that you have the ARN, call the **create-deployment-group** command to create a deployment group named **HelloWorld\$1DepGroup**, associated with the application named **HelloWorld\$1App**, using the Amazon EC2 instance tag named **CodeDeployDemo** and deployment configuration named **CodeDeployDefault.OneAtATime**, with the service role ARN:

   ```
   aws deploy create-deployment-group --application-name HelloWorld_App --deployment-group-name HelloWorld_DepGroup --deployment-config-name CodeDeployDefault.OneAtATime --ec2-tag-filters Key=Name,Value=CodeDeployDemo,Type=KEY_AND_VALUE --service-role-arn serviceRoleARN
   ```
**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.

1. Before you create a deployment, the instances in your deployment group must have the CodeDeploy agent installed. You can install the agent from the command line with AWS Systems Manager with the following command:

   ```
   aws ssm create-association --name AWS-ConfigureAWSPackage --targets Key=tag:Name,Values=CodeDeployDemo --parameters action=Install,name=AWSCodeDeployAgent --schedule-expression "cron(0 2 ? * SUN *)" 
   ```

   This command creates an association in Systems Manager State Manager that will install the CodeDeploy agent and then attempt to update it at 2:00 every Sunday morning. For more information about the CodeDeploy agent, see [ Working with the CodeDeploy agent](https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent.html). For more information about Systems Manager, see [What is AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html).

1. Now call the **create-deployment** command to create a deployment associated with the application named **HelloWorld\$1App**, the deployment configuration named **CodeDeployDefault.OneAtATime**, and the deployment group named **HelloWorld\$1DepGroup**, using the application revision named **HelloWorld\$1App.zip** in the bucket named **amzn-s3-demo-bucket**:

   ```
   aws deploy create-deployment --application-name HelloWorld_App --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name HelloWorld_DepGroup --s3-location bucket=amzn-s3-demo-bucket,bundleType=zip,key=HelloWorld_App.zip
   ```

### To deploy your application revision (console)
<a name="tutorials-windows-deploy-application-create-deployment-console"></a>

1. Before you use the CodeDeploy console to deploy your application revision, you need a service role ARN. A service role is an IAM role that gives a service permission to act on your behalf. In this case, the service role gives CodeDeploy permission to access your Amazon EC2 instances to expand (read) their Amazon EC2 instance tags.

   You should have already followed the instructions in [Create a service role (console)](getting-started-create-service-role.md#getting-started-create-service-role-console) to create a service role. To get the ARN of the service role, see [Get the service role ARN (console)](getting-started-create-service-role.md#getting-started-get-service-role-console).

1. Now that you have the ARN, you can use the CodeDeploy console to deploy your application revision.

   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 **HelloWorld\$1App**.

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

1. In **Deployment group name**, enter **HelloWorld\$1DepGroup**.

1. In **Service Role**, choose the name of the service role.

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

1. In **Environment configuration**, select **Amazon EC2 instances**.

1. In **Agent configuration with AWS Systems Manager**, keep the defaults.

1. In **Key**, enter **Name**.

1. In **Value**, enter **CodeDeployDemo**.

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

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

1. Choose **Create deployment group**.

1. Choose **Create deployment**.

1. In **Deployment group**, choose **HelloWorld\$1DepGroup**

1. In **Revision type**, choose **My application is stored in Amazon S3**, and then in **Revision location**, enter the location of the sample Hello World application revision you previously uploaded to Amazon S3. To get the location:

   1. Open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

   1. In the list of buckets, choose **amzn-s3-demo-bucket** (or the name of the bucket where you uploaded your application revision). 

   1. In the list of objects, choose **HelloWorld\$1App.zip**.

   1. In the **Overview** tab, choose **Copy path**.

   1. Return to the CodeDeploy console, and in **Revision Location**, paste the **Link** field value.

1. For **Revision file type**, choose **.zip**. 

1. (Optional) Enter a comment in **Deployment description**.

1. Choose **Create deployment**. Information about your newly created deployment appears on the **Deployments** page.

## Monitor and troubleshoot your deployment
<a name="tutorials-windows-deploy-application-monitor"></a>

Use the AWS CLI or the console to monitor and troubleshoot your deployment.

**Topics**
+ [To monitor and troubleshoot your deployment (CLI)](#tutorials-windows-deploy-application-monitor-cli)
+ [To monitor and troubleshoot your deployment (console)](#tutorials-windows-deploy-application-monitor-console)

### To monitor and troubleshoot your deployment (CLI)
<a name="tutorials-windows-deploy-application-monitor-cli"></a>

1. Get the deployment's ID by calling the **list-deployments** command against the application named **HelloWorld\$1App** and the deployment group named **HelloWorld\$1DepGroup**:

   ```
   aws deploy list-deployments --application-name HelloWorld_App --deployment-group-name HelloWorld_DepGroup --query "deployments" --output text
   ```

1. Call the **get-deployment** command with the deployment ID:

   ```
   aws deploy get-deployment --deployment-id deploymentID --query "deploymentInfo.status" --output text
   ```

1. The command returns the deployment's overall status. If successful, the value is `Succeeded`.

   If the overall status is `Failed`, you can call commands such as [list-deployment-instances](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-deployment-instances.html) and [get-deployment-instance](https://docs.aws.amazon.com/cli/latest/reference/deploy/get-deployment-instance.html) to troubleshoot. For more troubleshooting options, see [Analyzing log files to investigate deployment failures on instances](troubleshooting-ec2-instances.md#troubleshooting-deploy-failures).

### To monitor and troubleshoot your deployment (console)
<a name="tutorials-windows-deploy-application-monitor-console"></a>

On the **Deployments** page in the CodeDeploy console, you can monitor your deployment's status in the **Status** column.

To get more information about your deployment, especially if the **Status** column value has any value other than **Succeeded**:

1. In the **Deployments** table, choose your deployment ID. After a deployment fails, a message that describes the reason for the failure appears in the deployment's details page.

1. . More information about the deployment's instances is displayed. After a deployment fails, you might be able to determine on which Amazon EC2 instances and at which step the deployment failed.

1. If you want to do more troubleshooting, you can use a technique like [View instance details with CodeDeploy](instances-view-details.md). You can also analyze the deployment log files on an Amazon EC2 instance. For more information, see [Analyzing log files to investigate deployment failures on instances](troubleshooting-ec2-instances.md#troubleshooting-deploy-failures).

## Verify your deployment
<a name="tutorials-windows-deploy-application-verify"></a>

After your deployment is successful, verify your installation is working. Use the public DNS address of the Amazon EC2 instance to view the web page in a web browser. (To get the public DNS value, in the Amazon EC2 console, choose the Amazon EC2 instance, and on the **Description** tab, look for the value in **Public DNS**.)

For example, if the public DNS address of your Amazon EC2 instance is **ec2-01-234-567-890.compute-1.amazonaws.com**, you would use the following URL:

```
http://ec2-01-234-567-890.compute-1.amazonaws.com
```

If successful, you should see a Hello World webpage.

# Step 5: Update and redeploy your "hello, world\$1" application
<a name="tutorials-windows-update-and-redeploy-application"></a>

Now that you've successfully deployed your application revision, on the development machine, make an update to the webpage's code, and then use CodeDeploy to redeploy the site. After redeployment, you should be able to see the changes on the Amazon EC2 instance.

**Topics**
+ [Modify the webpage](#tutorials-windows-update-and-redeploy-application-modify-code)
+ [Redeploy the site](#tutorials-windows-update-and-redeploy-application-deploy-updates)

## Modify the webpage
<a name="tutorials-windows-update-and-redeploy-application-modify-code"></a>

1. Go to your `c:\temp\HelloWorldApp` subfolder and use a text editor to modify the `index.html` file:

   ```
   cd c:\temp\HelloWorldApp
   notepad index.html
   ```

1. Revise the contents of the `index.html` file to change the background color and some of the text on the webpage, and then save the file:

   ```
   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
   <html>
   <head>
     <title>Hello Again, World!</title>
     <style>
       body {
         color: #ffffff;
         background-color: #66cc00;
         font-family: Arial, sans-serif;  
         font-size:14px;
       }
     </style>
   </head>
   <body>
     <div align="center"><h1>Hello Again, World!</h1></div>
     <div align="center"><h2>You have successfully deployed a revision of an application using CodeDeploy</h2></div>
     <div align="center">
       <p>What to do next? Take a look through the <a href="https://aws.amazon.com/codedeploy">CodeDeploy Documentation</a>.</p>
     </div>
   </body>
   </html>
   ```

## Redeploy the site
<a name="tutorials-windows-update-and-redeploy-application-deploy-updates"></a>

Now that you've modified the code, use Amazon S3 and CodeDeploy to redeploy the webpage.

Bundle and upload the changes to Amazon S3 as described in [Bundle the application's files into a single archive file and push the archive file](tutorials-windows-upload-application.md#tutorials-windows-upload-application-bundle-and-push-archive). (As you follow those instructions, you do not need to create a new application.) Give the revision the same key as before (**HelloWorld\$1App.zip**). Upload it to the same Amazon S3 bucket you created earlier (for example, **amzn-s3-demo-bucket**).

Use the AWS CLI or the CodeDeploy console to redeploy the site.

**Topics**
+ [To redeploy the site (CLI)](#tutorials-windows-update-and-redeploy-application-deploy-updates-cli)
+ [To redeploy the site (console)](#tutorials-windows-update-and-redeploy-application-deploy-updates-console)

### To redeploy the site (CLI)
<a name="tutorials-windows-update-and-redeploy-application-deploy-updates-cli"></a>

Call the **create-deployment** command to create a deployment based on the uploaded revision, again using the application named **HelloWorld\$1App**, the deployment configuration named **CodeDeployDefault.OneAtATime**, the deployment group named **HelloWorld\$1DepGroup**, and the revision named **HelloWorld\$1App.zip** in the bucket named **amzn-s3-demo-bucket**:

```
 aws deploy create-deployment --application-name HelloWorld_App --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name HelloWorld_DepGroup --s3-location bucket=amzn-s3-demo-bucket,bundleType=zip,key=HelloWorld_App.zip
```

You can check the status of the new deployment, as described in [Monitor and troubleshoot your deployment](tutorials-windows-deploy-application.md#tutorials-windows-deploy-application-monitor).

When CodeDeploy has redeployed the site, revisit the site in your web browser to verify that the background color and text on the webpage have been changed. (You may need to refresh your browser.) If the background color and text has been changed, then congratulations\$1 You've modified and redeployed your site\$1

### To redeploy the site (console)
<a name="tutorials-windows-update-and-redeploy-application-deploy-updates-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. On the navigation pane, choose **Applications**.

1. In the **Applications** list, choose **HelloWorld\$1App**.

1. In the **Deployments** tab, choose **Create deployment**.

   1. In the **Deployment group** list, choose **HelloWorld\$1DepGroup**.

   1.  In **Revision location**, enter the Amazon S3 link for your revision.

      To find the link value:

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

         Browse to and open **amzn-s3-demo-bucket**, and then choose your revision, **HelloWorld\$1App.zip**, in the Amazon S3 console.

      1. If the **Properties** pane is not visible in the Amazon S3 console, choose the **Properties** button.

      1. In the **Properties** pane, copy the value of the **Link** field.

      1. Return to the CodeDeploy console, then paste the link into **Revision location**.

   1. In **Revision file type**, if a message appears stating that the file type could not be detected, choose **.zip**.

   1. Leave **Deployment description** blank.

   1. Expand **Deployment group overrides**In the **Deployment configuration** list, choose **CodeDeployDefault.OneAtATime**, and then choose **Create deployment**. 

      You can check the status of the deployment as described in [Monitor and troubleshoot your deployment](tutorials-windows-deploy-application.md#tutorials-windows-deploy-application-monitor).

      When CodeDeploy has redeployed the site, revisit the site in your web browser to verify that the background color and text on the webpage have been changed. (You may need to refresh your browser.) If the background color and text has been changed, congratulations\$1 You've modified and redeployed your site\$1

# Step 6: Clean up your "hello, world\$1" application and related resources
<a name="tutorials-windows-clean-up"></a>

You've now successfully made an update to the "Hello, World\$1" code and redeployed the site. To avoid ongoing charges for resources you created to complete this tutorial, you should delete:
+ Any CloudFormation stacks (or terminate any Amazon EC2 instances, if you created them outside of CloudFormation).
+ Any Amazon S3 buckets.
+ The `HelloWorld_App` application in CodeDeploy.
+ The AWS Systems Manager State Manager association for the CodeDeploy agent.

You can use the AWS CLI, the CloudFormation, Amazon S3, Amazon EC2, and CodeDeploy consoles, or the AWS APIs to perform the cleanup.

**Topics**
+ [To use clean up resources (CLI)](#tutorials-windows-clean-up-cli)
+ [To clean up resources (console)](#tutorials-windows-clean-up-console)
+ [What's next?](#tutorials-windows-clean-up-whats-next)

## To use clean up resources (CLI)
<a name="tutorials-windows-clean-up-cli"></a>

1. If you used the CloudFormation stack for this tutorial, delete the stack by calling the **delete-stack** command against the stack named **CodeDeployDemoStack**. This terminates all accompanying Amazon EC2 instances and delete all accompanying IAM roles originally created by the stack.

   ```
   aws cloudformation delete-stack --stack-name CodeDeployDemoStack
   ```

1. To delete the Amazon S3 bucket, call the **rm** command with the **--recursive** switch against the bucket named **amzn-s3-demo-bucket**. This deletes the bucket and all objects in the bucket.

   ```
   aws s3 rm s3://amzn-s3-demo-bucket --recursive --region region
   ```

1. To delete the `HelloWorld_App` application from CodeDeploy, call the **delete-application** command. This deletes all associated deployment group records and deployment records for the application.

   ```
   aws deploy delete-application --application-name HelloWorld_App
   ```

1. To delete the Systems Manager State Manager association, call the **delete-association** command.

   ```
   aws ssm delete-association --assocation-id association-id
   ```

   You can get the *association-id* by calling the **describe-association** command.

   ```
   aws ssm describe-association --name AWS-ConfigureAWSPackage --targets Key=tag:Name,Values=CodeDeployDemo
   ```

1. If you did not use the CloudFormation stack for this tutorial, call the **terminate-instances** command to terminate Amazon EC2 instances you manually created. Supply the ID of the Amazon EC2 instance to terminate.

   ```
   aws ec2 terminate-instances --instance-ids instanceId
   ```

## To clean up resources (console)
<a name="tutorials-windows-clean-up-console"></a>

If you used our CloudFormation template for this tutorial, delete the associated CloudFormation stack.

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 search box, type the CloudFormation stack name (for example, **CodeDeployDemoStack**).

1. Select the box beside the stack name.

1. In the **Actions** menu, choose **Delete Stack**. This deletes the stack, terminate all accompanying Amazon EC2 instances, and delete all accompanying IAM roles.

To terminate Amazon EC2 instances you created outside of an CloudFormation stack:

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 **Instances** area, choose **Instances**.

1. In the search box, type the name of Amazon EC2 instance you want to terminate, and then press **Enter**.

1. Choose the Amazon EC2 instance.

1. Choose **Actions**, point to **Instance State**, and then choose **Terminate**. When prompted, choose **Yes, Terminate**. Repeat these steps for any additional Amazon EC2 instances.

To delete the Amazon S3 bucket:

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

1. In the list of buckets, browse to and choose the name of the Amazon S3 bucket (for example, **amzn-s3-demo-bucket**).

1. Before you can delete a bucket, you must first delete its contents. Select all of the files in the bucket, such as **HelloWorld\$1App.zip**. In the **Actions** menu, choose **Delete**. When prompted to confirm the deletion, choose **OK**. 

1. After the bucket is empty, you can delete the bucket. In the list of buckets, choose the row of the bucket (but not the bucket name). Choose **Delete bucket**, and when prompted to confirm, choose **OK**. 

To delete the `HelloWorld_App` application from CodeDeploy:

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 **`HelloWorld_App`**.

1. Choose **Delete application**.

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

To delete the Systems Manager State Manager association:

1. Open the AWS Systems Manager console at https://console.aws.amazon.com/systems-manager.

1. In the navigation pane, choose **State Manager**.

1. Choose the association you created and choose **Delete**.

## What's next?
<a name="tutorials-windows-clean-up-whats-next"></a>

If you've arrived here, you have successfully completed a deployment with CodeDeploy. Congratulations\$1