

# Create a deployment with CodeDeploy
<a name="deployments-create"></a>

You can use the CodeDeploy console, the AWS CLI, or the CodeDeploy APIs to create a deployment that installs application revisions you have already pushed to Amazon S3 or, if your deployment is to an EC2/On-Premises compute platform, GitHub, on the instances in a deployment group.

The process for creating a deployment depends on the compute platform used by your deployment. 

**Topics**
+ [Deployment prerequisites](deployments-create-prerequisites.md)
+ [Create an Amazon ECS Compute Platform deployment (console)](deployments-create-console-ecs.md)
+ [Create an AWS Lambda Compute Platform deployment (console)](deployments-create-console-lambda.md)
+ [Create an EC2/On-Premises Compute Platform deployment (console)](deployments-create-console.md)
+ [Create an Amazon ECS Compute Platform deployment (CLI)](deployments-create-ecs-cli.md)
+ [Create an AWS Lambda Compute Platform deployment (CLI)](deployments-create-lambda-cli.md)
+ [Create an EC2/On-Premises Compute Platform deployment (CLI)](deployments-create-cli.md)
+ [Create an Amazon ECS blue/green deployment through CloudFormation](deployments-create-ecs-cfn.md)

# Deployment prerequisites
<a name="deployments-create-prerequisites"></a>

Make sure the following steps are complete before you start a deployment.

## Deployment prerequisites on an AWS Lambda compute platform
<a name="deployment-prerequisites-lambda"></a>
+ Create an application that includes at least one deployment group. For information, see [Create an application with CodeDeploy](applications-create.md) and [Create a deployment group with CodeDeploy](deployment-groups-create.md).
+ Prepare the application revision, also known as the AppSpec file, that specifies the Lambda function version you want to deploy. The AppSpec file can also specify Lambda functions to validate your deployment. For more information see [Working with application revisions for CodeDeploy](application-revisions.md).
+ If you want to use a custom deployment configuration for your deployment, create it before you start the deployment process. For information, see [Create a deployment configuration with CodeDeploy](deployment-configurations-create.md).

## Deployment prerequisites on an EC2/on-premises compute platform
<a name="deployment-prerequisites-server"></a>
+ For an in-place deployment, create or configure the instances you want to deploy to. For information, see [Working with instances for CodeDeploy](instances.md). For a blue/green deployment, you either have an existing Amazon EC2 Auto Scaling group to use as a template for your replacement environment, or you have one or more instances or Amazon EC2 Auto Scaling groups that you specify as your original environment. For more information, see [Tutorial: Use CodeDeploy to deploy an application to an Auto Scaling group](tutorials-auto-scaling-group.md) and [Integrating CodeDeploy with Amazon EC2 Auto Scaling](integrations-aws-auto-scaling.md). 
+ Create an application that includes at least one deployment group. For information, see [Create an application with CodeDeploy](applications-create.md) and [Create a deployment group with CodeDeploy](deployment-groups-create.md).
+ Prepare the application revision that you want to deploy to the instances in your deployment group. For information, see [Working with application revisions for CodeDeploy](application-revisions.md).
+ If you want to use a custom deployment configuration for your deployment, create it before you start the deployment process. For information, see [Create a deployment configuration with CodeDeploy](deployment-configurations-create.md).
+ If you are deploying your application revision from an Amazon S3 bucket, the bucket is in the same AWS Region as the instances in your deployment group. 
+ If you are deploying your application revision from an Amazon S3 bucket, an Amazon S3 bucket policy has been applied to the bucket. This policy grants your instances the permissions required to download the application revision.

  For example, the following Amazon S3 bucket policy allows any Amazon EC2 instance with an attached IAM instance profile containing the ARN `arn:aws:iam::444455556666:role/CodeDeployDemo` to download from anywhere 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"
                  ]
              }
          }
      ]
  }
  ```

  The following Amazon S3 bucket policy allows any on-premises instance with an associated IAM user containing the ARN `arn:aws:iam::444455556666:user/CodeDeployUser` to download from anywhere 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:user/CodeDeployUser"
                  ]
              }
          }
      ]
  }
  ```

  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).
+ If you are creating a blue/green deployment, or you have specified an optional Classic Load Balancer, Application Load Balancer, or Network Load Balancer in the deployment group for an in-place deployment, you have created a VPC using Amazon VPC that contains at least two subnets. (CodeDeploy uses Elastic Load Balancing, which requires all instances in a load balancer group to be in a single VPC.)

  If you have not created a VPC yet, see the [Amazon VPC Getting Started Guide](https://docs.aws.amazon.com/AmazonVPC/latest/GettingStartedGuide/ExerciseOverview.html).
+ If you are creating a blue/green deployment, you have configured at least one Classic Load Balancer, Application Load Balancer, or Network Load Balancer in Elastic Load Balancing and used it to register the instances that make up your original environment. 
**Note**  
The instances in your replacement environment will be registered with the load balancer later.

  For more information about configuring a load balancer, see [Set up a load balancer in Elastic Load Balancing for CodeDeploy Amazon EC2 deployments](deployment-groups-create-load-balancer.md), and [Set up a load balancer, target groups, and listeners for CodeDeploy Amazon ECS deployments](deployment-groups-create-load-balancer-for-ecs.md).

## Deployment prerequisites for a blue/green deployment through CloudFormation
<a name="deployment-prerequisites-cfn-bg"></a>
+ Your template does not need to model resources for a CodeDeploy application or deployment group.
+ Your template must include resources for a VPC using Amazon VPC that contains at least two subnets.
+ Your template must include resources for one or more Classic Load Balancers, Application Load Balancers, or Network Load Balancers in Elastic Load Balancing that are used to direct traffic to your target groups.

# Create an Amazon ECS Compute Platform deployment (console)
<a name="deployments-create-console-ecs"></a>

This topic shows you how to deploy an Amazon ECS service using the console. For more information, see [Tutorial: Deploy an application into Amazon ECS](tutorial-ecs-deployment.md) and [Tutorial: Deploy an Amazon ECS service with a validation test](tutorial-ecs-deployment-with-hooks.md).

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. Do one of the following:
   +  If you want to deploy an application, in the navigation pane, expand **Deploy**, and then choose **Applications**. Choose the name of the application you want to deploy. Make sure the **Compute platform** column for your application is **Amazon ECS**.
   +  If you want to redeploy a deployment, in the navigation pane, expand **Deploy**, and then choose **Deployments**. Choose the deployment you want to redeploy, and in the **Application** column, choose the name of its application. Make sure the **Compute platform** column for your deployment is **Amazon ECS**.

1. On the **Deployments** tab, choose **Create deployment**.
**Note**  
Your application must have a deployment group before it can be deployed. If your application does not have a deployment group, on the **Deployment groups** tab, choose **Create deployment group**. For more information, see [Create a deployment group with CodeDeploy](deployment-groups-create.md). 

1. In **Deployment group**, choose a deployment group to use for this deployment.

1. Next to **Revision location**, choose where your revision is located:
   + **My application is stored in Amazon S3** — For information, see [Specify information about a revision stored in an Amazon S3 bucket](deployments-create-console-s3.md), and then return to step 6. 
   + **Use AppSpec editor** — Select either JSON or YAML, and then enter your AppSpec file into the editor. You can save the AppSpec file by choosing **Save as text file**. When you choose **Deploy** at the end of these steps, you receive an error if your JSON or YAML is not valid. For more information about creating an AppSpec file, see [Add an application specification file to a revision for CodeDeploy](application-revisions-appspec-file.md). 

1. (Optional) In **Deployment description**, enter a description for this deployment.

1. (Optional) In **Rollback configuration overrides**, you can specify different automatic rollback options for this deployment than were specified for the deployment group, if any.

   For information about rollbacks in CodeDeploy, see [Redeployments and deployment rollbacks](deployment-steps-lambda.md#deployment-rollback-lambda) and [Redeploy and roll back a deployment with CodeDeploy](deployments-rollback-and-redeploy.md).

   Choose from the following:
   + **Roll back when a deployment fails** — CodeDeploy redeploys the last known good revision as a new deployment.
   + **Roll back when alarm thresholds are met** — If alarms were added to the deployment group, CodeDeploy redeploys the last known good revision when one or more of the specified alarms is activated.
   + **Disable rollbacks** — Do not perform rollbacks for this deployment.

1. Choose **Create deployment**. 

   To track the status of your deployment, see [View CodeDeploy deployment details](deployments-view-details.md).

# Create an AWS Lambda Compute Platform deployment (console)
<a name="deployments-create-console-lambda"></a>

This topic shows you how to deploy a Lambda function using the console.

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

1. Do one of the following:
   +  If you want to deploy an application, in the navigation pane, expand **Deploy**, and then choose **Applications**. Choose the name of the application you want to deploy. Make sure the **Compute platform** column for your application is **AWS Lambda**.
   +  If you want to redeploy a deployment, in the navigation pane, expand **Deploy**, and then choose **Deployments**. Choose the deployment you want to redeploy, and in the **Application** column, choose the name of its application. Make sure the **Compute platform** column for your deployment is **AWS Lambda**.

1. On the **Deployments** tab, choose **Create deployment**.
**Note**  
Your application must have a deployment group before it can be deployed. If your application does not have a deployment group, on the **Deployment groups** tab, choose **Create deployment group**. For more information, see [Create a deployment group with CodeDeploy](deployment-groups-create.md). 

1. In **Deployment group**, choose a deployment group to use for this deployment.

1. Next to **Revision location**, choose where your revision is located:
   + **My application is stored in Amazon S3** — For information, see [Specify information about a revision stored in an Amazon S3 bucket](deployments-create-console-s3.md), and then return to step 6. 
   + **Use AppSpec editor** — Select either JSON or YAML, and then enter your AppSpec file into the editor. You can save the AppSpec file by choosing **Save as text file**. When you choose **Deploy** at the end of these steps, you receive an error if your JSON or YAML is not valid. For more information about creating an AppSpec file, see [Add an application specification file to a revision for CodeDeploy](application-revisions-appspec-file.md). 

1. (Optional) In **Deployment description**, enter a description for this deployment.

1. (Optional) Expand **Deployment group overrides** to choose a deployment configuration to control how traffic is shifted to the Lambda function version that is different from the one specified in the deployment group.

   For more information, see [Deployment configurations on an AWS Lambda compute platform](deployment-configurations.md#deployment-configuration-lambda).

1. (Optional) In **Rollback configuration overrides**, you can specify different automatic rollback options for this deployment than were specified for the deployment group, if any.

   For information about rollbacks in CodeDeploy, see [Redeployments and deployment rollbacks](deployment-steps-lambda.md#deployment-rollback-lambda) and [Redeploy and roll back a deployment with CodeDeploy](deployments-rollback-and-redeploy.md).

   Choose from the following:
   + **Roll back when a deployment fails** — CodeDeploy redeploys the last known good revision as a new deployment.
   + **Roll back when alarm thresholds are met** — If alarms were added to the deployment group, CodeDeploy redeploys the last known good revision when one or more of the specified alarms is activated.
   + **Disable rollbacks** — Do not perform rollbacks for this deployment.

1. Choose **Create deployment**. 

   To track the status of your deployment, see [View CodeDeploy deployment details](deployments-view-details.md).

# Create an EC2/On-Premises Compute Platform deployment (console)
<a name="deployments-create-console"></a>

This topic shows you how to deploy an application to an Amazon EC2 or on-premises server using the console.

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

1. Do one of the following:
   +  If you want to deploy an application, in the navigation pane, expand **Deploy**, and then choose **Applications**. Choose the name of the application you want to deploy. Make sure the **Compute platform** column for your application is **EC2/On-Premises**.
   +  If you want to redeploy a deployment, in the navigation pane, expand **Deploy**, and then choose **Deployments**. Locate the deployment you want to redeploy, and then choose the name of its application in the **Application** column. Make sure the **Compute platform** column for your deployment is **EC2/On-Premises**.

1. On the **Deployments** tab, choose **Create deployment**.
**Note**  
Your application must have a deployment group before it can be deployed. If your application does not have a deployment group, on the **Deployment groups** tab, choose **Create deployment group**. For more information, see [Create a deployment group with CodeDeploy](deployment-groups-create.md). 

1. In **Deployment group**, choose a deployment group to use for this deployment.

1. Next to **Repository type**, choose the repository type your revision is stored in:
   + **My application is stored in Amazon S3** — For information, see [Specify information about a revision stored in an Amazon S3 bucket](deployments-create-console-s3.md), and then return to step 6. 
   + **My application is stored in GitHub** — For information, see [Specify information about a revision stored in a GitHub repository](deployments-create-console-github.md), and then return to step 6.

1. (Optional) In **Deployment description**, enter a description for this deployment.

1. (Optional) Expand **Override deployment configuration** to choose a deployment configuration to control how traffic is shifted to the Amazon EC2 or on-premises server that is different from the one specified in the deployment group.

   For more information, see [Working with deployment configurations in CodeDeploy](deployment-configurations.md).

1. 

   1. Select **Don't fail the deployment if the ApplicationStop lifecycle event fails** if you want a deployment to an instance to succeed if the `ApplicationStop` lifecycle event fails.

   1. Expand **Additional deployment behavior settings** to specify how CodeDeploy handles files in a deployment target location that weren't part of the previous successful deployment.

      Choose from the following:
      + **Fail the deployment** — An error is reported and the deployment status is changed to `Failed`.
      + **Overwrite the content** — If a file of the same name exists in the target location, the version from the application revision replaces it.
      + **Retain the content** — If a file of the same name exists in the target location, the file is kept and the version in the application revision is not copied to the instance.

      For more information, see [Rollback behavior with existing content](deployments-rollback-and-redeploy.md#deployments-rollback-and-redeploy-content-options). 

1. (Optional) In **Rollback configuration overrides**, you can specify different automatic rollback options for this deployment than were specified for the deployment group, if any.

   For information about rollbacks in CodeDeploy, see [Redeployments and deployment rollbacks](deployment-steps-server.md#deployment-rollback) and [Redeploy and roll back a deployment with CodeDeploy](deployments-rollback-and-redeploy.md).

   Choose from the following:
   + **Roll back when a deployment fails** — CodeDeploy redeploys the last known good revision as a new deployment.
   + **Roll back when alarm thresholds are met** — If alarms were added to the deployment group, CodeDeploy deploys the last known good revision when one or more of the specified alarms is activated.
   + **Disable rollbacks** — Do not perform rollbacks for this deployment.

1. Choose **Start deployment**. 

   To track the status of your deployment, see [View CodeDeploy deployment details](deployments-view-details.md).

**Topics**
+ [Specify information about a revision stored in an Amazon S3 bucket](deployments-create-console-s3.md)
+ [Specify information about a revision stored in a GitHub repository](deployments-create-console-github.md)

# Specify information about a revision stored in an Amazon S3 bucket
<a name="deployments-create-console-s3"></a>

If you are following the steps in [Create an EC2/On-Premises Compute Platform deployment (console)](deployments-create-console.md), follow these steps to add details about an application revision stored in an Amazon S3 bucket.

1. Copy your revision's Amazon S3 link into **Revision location**. To find the link value:

   1. In a separate browser tab:

      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 choose your revision.

   1. If the **Properties** pane is not visible, choose the **Properties** button.

   1. In the **Properties** pane, copy the value of the **Link** field into the **Revision location** box in the CodeDeploy console.

   To specify an ETag (a file checksum) as part of the revision location:
   + If the **Link** field value ends in **?versionId=*versionId***, add **&etag=** and the ETag to the end of the **Link** field value.
   + If the **Link** field value does not specify a version ID, add **?etag=** and the ETag to the end of the **Link** field value.
**Note**  
Although it's not as easy as copying the value of the **Link** field, you can also type the revision location in one of the following formats:  
**s3://*bucket-name*/*folders*/*objectName***  
**s3://*bucket-name*/*folders*/*objectName*?versionId=*versionId***  
**s3://*bucket-name*/*folders*/*objectName*?etag=*etag***  
**s3://*bucket-name*/*folders*/*objectName*?versionId=*versionId*&etag=*etag***  
***bucket-name*.s3.amazonaws.com/*folders*/*objectName***

1. If a message appears in the **File type** list that says the file type could not be detected, choose the revision's file type. Otherwise, accept the detected file type.

# Specify information about a revision stored in a GitHub repository
<a name="deployments-create-console-github"></a>

If you are following the steps in [Create an EC2/On-Premises Compute Platform deployment (console)](deployments-create-console.md), follow these steps to add details about an application revision stored in a GitHub repository.

1. In **Connect to GitHub**, do one of the following:
   + To create a connection for CodeDeploy applications to a GitHub account, in a different web browser tab, sign out of GitHub. 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 your application. Continue to step 2.
   + To use a connection you have already created, in **GitHub account**, select its name, and then choose **Connect to GitHub**. Continue to step 4.
   + To create a connection to a different GitHub account, in a different web browser tab, sign out of GitHub. Choose **Connect to a different GitHub account**, and then choose **Connect to GitHub**. Continue to step 2.

1. If you are prompted to sign in to GitHub, follow the instructions on the **Sign in** page. Sign in with your GitHub user name or email and password.

1. If an **Authorize application** page appears, choose **Authorize application**. 

1. On the **Create deployment** page, in the **Repository name** box, enter the GitHub user or organization name that contains the revision, followed by a forward slash (`/`), followed by the name of the repository that contains the revision. If you are unsure of the value to type:

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

1. In **Commit ID**, enter the ID of the commit that refers to the revision in the repository. If you are unsure of the value to type:

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

   1. In **Your repositories**, choose the repository name that contains the target commit.

   1. In the list of commits, find and copy the commit ID that refers to the revision in the repository. 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 of the commit ID.)

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

# Create an Amazon ECS Compute Platform deployment (CLI)
<a name="deployments-create-ecs-cli"></a>

After you have created the application and revision (in Amazon ECS deployments, this is the AppSpec file):

Call the [create-deployment](https://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html) command, specifying:
+ An application name. To view a list of application names, call the [list-applications](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-applications.html) command.
+ A deployment group name. To view a list of deployment group names, call the [list-deployment-groups](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-deployment-groups.html) command.
+ Information about the revision to be deployed:

  For revisions stored in Amazon S3:
  + The Amazon S3 bucket name that contains the revision.
  + The name of the uploaded revision.
  + (Optional) The Amazon S3 version identifier for the revision. (If the version identifier is not specified, CodeDeploy uses the most recent version.)
  + (Optional) The ETag for the revision. (If the ETag is not specified, CodeDeploy skips object validation.)

  For revisions stored in a file that is not in Amazon S3, you need the file name and its path. Your revision file is written using JSON or YAML, so it most likely has a .json or .yaml extension.
+ (Optional) A description for the deployment.

The revision file can be specified as a file uploaded to an Amazon S3 bucket or as a string. The syntax for each when used as part of the **create-deployment** command is:
+ Amazon S3 bucket:

  The `version` and `eTag` are optional.

  ```
  --s3-location bucket=string,key=string,bundleType=JSON|YAML,version=string,eTag=string
  ```
+ String:

  ```
  --revision '{"revisionType": "String", "string": {"content":"revision-as-string"}}'
  ```

**Note**  
The **create-deployment** command can load a revision from a file. For more information, see [Loading parameters from a file](https://docs.aws.amazon.com/cli/latest/userguide/cli-using-param.html#cli-using-param-file). 

For AWS Lambda deployment revision templates, see [Add an AppSpec file for an AWS Lambda deployment](application-revisions-appspec-file.md#add-appspec-file-lambda). For an example revision, see [AppSpec File example for an AWS Lambda deployment](reference-appspec-file-example.md#appspec-file-example-lambda).

To track the status of your deployment, see [View CodeDeploy deployment details](deployments-view-details.md).

# Create an AWS Lambda Compute Platform deployment (CLI)
<a name="deployments-create-lambda-cli"></a>



After you have created the application and revision (in AWS Lambda deployments, this is the AppSpec file):

Call the [create-deployment](https://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html) command, specifying:
+ An application name. To view a list of application names, call the [list-applications](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-applications.html) command.
+ A deployment group name. To view a list of deployment group names, call the [list-deployment-groups](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-deployment-groups.html) command.
+ Information about the revision to be deployed:

  For revisions stored in Amazon S3:
  + The Amazon S3 bucket name that contains the revision.
  + The name of the uploaded revision.
  + (Optional) The Amazon S3 version identifier for the revision. (If the version identifier is not specified, CodeDeploy uses the most recent version.)
  + (Optional) The ETag for the revision. (If the ETag is not specified, CodeDeploy skips object validation.)

  For revisions stored in a file that is not in Amazon S3, you need the file name and its path. Your revision file is written using JSON or YAML, so it most likely has a .json or .yaml extension.
+ (Optional) The name of a deployment configuration to use. To view a list of deployment configurations, call the [list-deployment-configs](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-deployment-configs.html) command. (If not specified, CodeDeploy uses a specific default deployment configuration.)
+ (Optional) A description for the deployment.

The revision file can be specified as a file uploaded to an Amazon S3 bucket or as a string. The syntax for each when used as part of the **create-deployment** command is:
+ Amazon S3 bucket:

  The `version` and `eTag` are optional.

  ```
  --s3-location bucket=string,key=string,bundleType=JSON|YAML,version=string,eTag=string
  ```
+ String:

  ```
  --revision '{"revisionType": "String", "string": {"content":"revision-as-string"}}'
  ```

**Note**  
The **create-deployment** command can load a revision from a file. For more information, see [Loading parameters from a file](https://docs.aws.amazon.com/cli/latest/userguide/cli-using-param.html#cli-using-param-file). 

For AWS Lambda deployment revision templates, see [Add an AppSpec file for an AWS Lambda deployment](application-revisions-appspec-file.md#add-appspec-file-lambda). For an example revision, see [AppSpec File example for an AWS Lambda deployment](reference-appspec-file-example.md#appspec-file-example-lambda).

To track the status of your deployment, see [View CodeDeploy deployment details](deployments-view-details.md).

# Create an EC2/On-Premises Compute Platform deployment (CLI)
<a name="deployments-create-cli"></a>

To use the AWS CLI to deploy a revision to the EC2/On-Premises compute platform:

1. After you have prepared the instances, created the application, and pushed the revision, do one of the following: 
   + If you want to deploy a revision from an Amazon S3 bucket, continue to step 2 now.
   + If you want to deploy a revision from a GitHub repository, first complete the steps in [Connect a CodeDeploy application to a GitHub repository](deployments-create-cli-github.md), and then continue to step 2. 

1. Call the [create-deployment](https://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html) command, specifying:
   + `--application-name`: An application name. To view a list of application names, call the [list-applications](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-applications.html) command.
   + `--deployment-group-name`: An Amazon EC2 deployment group name. To view a list of deployment group names, call the [list-deployment-groups](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-deployment-groups.html) command.
   + `--revision`: Information about the revision to be deployed:

     For revisions stored in Amazon S3:
     + `s3Location`: The Amazon S3 bucket name that contains the revision.
     + `s3Location --> key`: The name of the uploaded revision.
     + `s3Location --> bundleType`: The file type of the uploaded revision.
**Note**  
The tar and compressed tar archive file formats (.tar and .tar.gz) are not supported for Windows Server instances.
     + `s3Location --> version`: (Optional) The Amazon S3 version identifier for the revision. (If the version identifier is not specified, CodeDeploy uses the most recent version.)
     + `s3Location --> eTag`: (Optional) The ETag for the revision. (If the ETag is not specified, CodeDeploy skips object validation.)

     For revisions stored in GitHub:
     + `gitHubLocation --> repository`: The GitHub user or group name assigned to the repository that contains the revision, followed by a forward slash (`/`), followed by the repository name.
     + `gitHubLocation --> commitId`: The commit ID for the revision.
   + `--deployment-config-name`: (Optional) The name of a deployment configuration to use. To view a list of deployment configurations, call the [list-deployment-configs](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-deployment-configs.html) command. (If not specified, CodeDeploy uses a specific default deployment configuration.)
   + `--ignore-application-stop-failures | --no-ignore-application-stop-failures`: (Optional) Whether you want the deployment to an instance to continue to the `BeforeInstall` deployment lifecycle event if the `ApplicationStop` deployment lifecycle event fails. 
   + `--description`: (Optional) A description for the deployment.
   + `--file-exists-behavior`: (Optional) As part of the deployment process, the CodeDeploy agent removes from each instance all the files installed by the most recent deployment. Choose what happens when files that weren’t part of a previous deployment appear in target deployment locations.
   + `--target-instances`: For blue/green deployments, information about the instances that belong to the replacement environment in a blue/green deployment, including the names of one or more Amazon EC2 Auto Scaling groups, or the tag filter key, type, and value used to identify Amazon EC2 instances.

**Note**  
Use this syntax as part of the **create-deployment** call to specify information about a revision in Amazon S3 directly on the command line. (The `version` and `eTag` are optional.)  

```
--s3-location bucket=string,key=string,bundleType=tar|tgz|zip,version=string,eTag=string
```
Use this syntax as part of the **create-deployment** call to specify information about a revision in GitHub directly on the command line:  

```
--github-location repository=string,commitId=string
```
To get information about revisions that have been pushed already, call the [list-application-revisions](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-application-revisions.html) command.

To track the status of your deployment, see [View CodeDeploy deployment details](deployments-view-details.md).

## create-deployment command reference
<a name="deployments-create-cli-reference"></a>

Below is the command structure and options for the `create-deployment` command. For more information, see the [create-deployment](https://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html) reference in the *AWS CLI Command Reference*.

```
create-deployment
--application-name <value>
[--deployment-group-name <value>]
[--revision <value>]
[--deployment-config-name <value>]
[--description <value>]
[--ignore-application-stop-failures | --no-ignore-application-stop-failures]
[--target-instances <value>]
[--auto-rollback-configuration <value>]
[--update-outdated-instances-only | --no-update-outdated-instances-only]
[--file-exists-behavior <value>]
[--s3-location <value>]
[--github-location <value>]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
```

# Connect a CodeDeploy application to a GitHub repository
<a name="deployments-create-cli-github"></a>

Before you can deploy an application from a GitHub repository for the first time using the AWS CLI, you must first give CodeDeploy permission to interact with GitHub on behalf of your GitHub account. This step must be completed once for each application using the CodeDeploy console.

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

1. Choose **Applications**.

1. From **Applications**, choose the application you want to link to your GitHub user account and choose **Deploy application**.
**Note**  
You are not creating a deployment. This is currently the only way to give CodeDeploy permission to interact with GitHub on behalf of your GitHub user account.

1. Next to **Repository type**, choose **My application revision is stored in GitHub**.

1. Choose **Connect to GitHub**.
**Note**  
If you see a **Connect to a different GitHub account** link:  
You might have already authorized CodeDeploy to interact with GitHub on behalf of a different GitHub account for the application.  
You might have revoked authorization for CodeDeploy to interact with GitHub on behalf of the signed-in GitHub account for all applications linked to in CodeDeploy.  
For more information, see [GitHub authentication with applications in CodeDeploy](integrations-partners-github.md#behaviors-authentication).

1. If you are not already signed in to GitHub, follow the instructions on the **Sign in** page.

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

1. Now that CodeDeploy has permission, choose **Cancel**, and continue with the steps in [Create an EC2/On-Premises Compute Platform deployment (CLI)](deployments-create-cli.md).

# Create an Amazon ECS blue/green deployment through CloudFormation
<a name="deployments-create-ecs-cfn"></a>

You can use AWS CloudFormation to manage Amazon ECS blue/green deployments through CodeDeploy. You generate your deployment by defining your green and blue resources and specifying the traffic routing and stabilization settings to use in CloudFormation. This topic covers the differences between Amazon ECS blue/green deployments that are managed by CodeDeploy and deployments that are managed by CloudFormation.

For step-by-step instructions on using CloudFormation to manage your Amazon ECS blue/green deployments, see [Automate ECS blue/green deployments through CodeDeploy using AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/blue-green.html) in the *AWS CloudFormation User Guide*.

**Note**  
Managing Amazon ECS blue/green deployments with CloudFormation is not available in the Asia Pacific (Osaka) region.

## Differences between Amazon ECS blue/green deployments through CodeDeploy and CloudFormation
<a name="differences-ecs-bg-cfn"></a>

The CloudFormation stack template models Amazon ECS task-related resources and infrastructure, and also the conﬁguration options for deployments. So there are differences between the standard Amazon ECS blue/green deployments and blue/green deployments that are created through CloudFormation.

Unlike standard Amazon ECS blue/green deployments, you don't model or manually create the following:
+ You don't create an AWS CodeDeploy application by specifying a name that uniquely represents what you want to deploy.
+ You don't create an AWS CodeDeploy deployment group.
+ You don't specify an *application specification file* (AppSpec file). The information normally managed with the AppSpec file, such as the weighted configuration options or lifecycle events, is managed by the `AWS::CodeDeploy::BlueGreen` hook.

 This table summarizes the differences in the high-level workflow between deployment types.


****  

| Function | Standard blue/green deployments | Blue/green deployments through CloudFormation | 
| --- | --- | --- | 
| Specify the Amazon ECS cluster, Amazon ECS service, Application Load Balancer or Network Load Balancer, Production listener, test listener, and two target groups. | Create a CodeDeploy deployment group that specifies these resources. | Create an CloudFormation template to model these resources. | 
| Specify the change to be deployed. | Create a CodeDeploy application. | Create an CloudFormation template that specifies the container image. | 
| Specify the Amazon ECS task definition, container name, and container port. | Create an AppSpec file that specifies these resources. | Create an CloudFormation template to model these resources. | 
| Specify the deployment traffic shifting options and lifecycle event hooks. | Create an AppSpec file that specifies these options. | Create an CloudFormation template that uses the AWS::CodeDeploy::BlueGreen hook parameters to specify these options. | 
|  CloudWatch alarms.  |  Create a CloudWatch alarm that triggers a rollback.  |  Configure a CloudWatch alarm at the CloudFormation stack level that triggers a rollback.  | 
| Rollback/redeployment. | Specify rollback and redeployment options. | Cancel the stack update in CloudFormation. | 

## Monitoring Amazon ECS blue/green deployments through CloudFormation
<a name="monitoring-ecs-bg-cfn"></a>

You can monitor blue/green deployments through CloudFormation and CodeDeploy. For information about monitoring through CloudFormation, see [Monitoring blue/green events in CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/blue-green.html#blue-green-events) in the *AWS CloudFormation User Guide*.

**To view deployment status of blue/green deployments in 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 **Deployments**, the deployment that was triggered by the CloudFormation stack update appears. Choose the deployment to view the **Deployment history**.  
![\[Console screenshot showing the Deployments section and deployment history.\]](http://docs.aws.amazon.com/codedeploy/latest/userguide/images/cfn-cd-bg-deplhist.png)

1. Choose the deployment to view the traffic shifting status. Note that the application and deployment group are not created.  
![\[Console screenshot showing the deployment details with deployment status completed.\]](http://docs.aws.amazon.com/codedeploy/latest/userguide/images/cfn-cd-bg-deplstatus.png)

1. The following apply for rolling back or stopping the deployment:
   + The successful deployment appears in CodeDeploy and shows that the deployment was initiated by CloudFormation.
   + If you want to stop and roll back the deployment, you must cancel the stack update in CloudFormation.