

# Create an application with CodeDeploy
<a name="applications-create"></a>

An *application* is simply a name or container used by CodeDeploy to ensure that the correct revision, deployment configuration, and deployment group are referenced during a deployment. You can use the CodeDeploy console, the AWS CLI, the CodeDeploy APIs, or an CloudFormation template to create applications.

Your code, or application revision, is installed to instances through a process called a deployment. CodeDeploy supports two types of deployments: 
+ **In-place deployment**: The application on each instance in the deployment group is stopped, the latest application revision is installed, and the new version of the application is started and validated. You can use a load balancer so that each instance is deregistered during its deployment and then restored to service after the deployment is complete. Only deployments that use the EC2/On-Premises compute platform can use in-place deployments. For more information about in-place deployments, see [Overview of an in-place deployment](welcome.md#welcome-deployment-overview-in-place).
+ **Blue/green deployment**: The behavior of your deployment depends on which compute platform you use:
  + **Blue/green on an EC2/On-Premises compute platform**: The instances in a deployment group (the original environment) are replaced by a different set of instances (the replacement environment) using these steps:
    + Instances are provisioned for the replacement environment.
    + The latest application revision is installed on the replacement instances.
    + An optional wait time occurs for activities such as application testing and system verification.
    + Instances in the replacement environment are registered with one or more Elastic Load Balancing load balancers, causing traffic to be rerouted to them. Instances in the original environment are deregistered and can be terminated or kept running for other uses.
**Note**  
If you use an EC2/On-Premises compute platform, be aware that blue/green deployments work with Amazon EC2 instances only.
  + **Blue/green on an AWS Lambda or Amazon ECS compute platform**: Traffic is shifted in increments according to a **canary**, **linear**, or **all-at-once** deployment configuration.
  + **Blue/green deployments through CloudFormation**: Traffic is shifted from your current resources to your updated resources as part of an CloudFormation stack update. Currently, only ECS blue/green deployments are supported. 

  For more information about blue/green deployments, see [Overview of a blue/green deployment](welcome.md#welcome-deployment-overview-blue-green).

When you use the CodeDeploy console to create an application, you configure its first deployment group at the same time. When you use the AWS CLI to create an application, you create its first deployment group in a separate step.

To view a list of applications already registered to your AWS account, see [View application details with CodeDeploy](applications-view-details.md). For information about using an CloudFormation template to create an application, see [CloudFormation templates for CodeDeploy reference](reference-cloudformation-templates.md).

 Both deployment types do not apply to all destinations. The following table lists which deployment types work with deployments to the three types of deployment destinations.


****  

| Deployment destination | In-place | Blue/green | 
| --- | --- | --- | 
| Amazon EC2  | Yes | Yes | 
| On-premises | Yes | No | 
| Serverless AWS Lambda functions | No | Yes | 
| Amazon ECS applications | No | Yes | 



**Topics**
+ [Create an application for an in-place deployment (console)](applications-create-in-place.md)
+ [Create an application for a blue/green deployment (console)](applications-create-blue-green.md)
+ [Create an application for an Amazon ECS service deployment (console)](applications-create-ecs.md)
+ [Create an application for an AWS Lambda function deployment (console)](applications-create-lambda.md)
+ [Create an application (CLI)](applications-create-cli.md)

# Create an application for an in-place deployment (console)
<a name="applications-create-in-place"></a>

To use the CodeDeploy console to create an application for an in-place deployment:

 

**Warning**  
Do not follow these steps if:  
You have not prepared your instances to be used in CodeDeploy deployments. To set up your instances, follow the instructions in [Working with instances for CodeDeploy](instances.md), and then follow the steps in this topic.
You want to create an application that uses a custom deployment configuration, but you have not yet created the deployment configuration. Follow the instructions in [Create a deployment configuration with CodeDeploy](deployment-configurations-create.md), and then follow the steps in this topic. 
You do not have a service role that trusts CodeDeploy with the minimum required trust and permissions. To create and configure a service role with the required permissions, follow the instructions in [Step 2: Create a service role for CodeDeploy](getting-started-create-service-role.md), and then return to the steps in this topic.
You want to select a Classic Load Balancer, Application Load Balancer, or Network Load Balancer in Elastic Load Balancing for the in-place deployment, but have not yet created it.

To create an application for an in-place deployment 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. In the navigation pane, expand **Deploy**, and then choose **Getting started**.

1. Choose **Create application**.

1. In **Application name**, enter the name of your application .

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

1. Choose **Create application**.

1. On your application page, from the **Deployment groups** tab, choose **Create deployment group**.

1. In **Deployment group name**, enter a name that describes the deployment group.
**Note**  
If you want to use the same settings used in another deployment group (including the deployment group name; tags, Amazon EC2 Auto Scaling group names, or both; and the deployment configuration), specify those settings on this page. Although this new deployment group and the existing deployment group have the same name, CodeDeploy treats them as separate deployment groups, because they are each associated with separate applications.

1. In **Service role**, choose a service role that grants CodeDeploy access to your target instance.

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

1. In **Environment configuration**, select any of the following: 

   1. **Amazon EC2 Auto Scaling groups**: Enter or choose the name of an Amazon EC2 Auto Scaling group to deploy your application revision to. When new Amazon EC2 instances are launched as part of an Amazon EC2 Auto Scaling group, CodeDeploy can deploy your revisions to the new instances automatically. You can add up to 10 Amazon EC2 Auto Scaling groups to a deployment group.

   1. **Amazon EC2 instances** or **On-premises instances**: In the **Key** and **Value** fields, enter the values of the key-value pair you used to tag the instances. You can tag up to 10 key-value pairs in a single tag group.

      1. You can use wildcards in the **Value** field to identify all instances tagged in certain patterns, such as similar Amazon EC2 instance, cost center, and group names, and so on. For example, if you choose **Name** in the **Key** field and enter **GRP-\$1a** in the **Value** field, CodeDeploy identifies all instances that fit that pattern, such as **GRP-1a**, **GRP-2a**, and **GRP-XYZ-a**.

      1. The **Value** field is case sensitive. 

      1. To remove a key-value pair from the list, choose **Remove tag**.

      As CodeDeploy finds instances that match each specified key-value pair or Amazon EC2 Auto Scaling group name, it displays the number of matching instances. Choose the number to see more information about the instances.

      If you want to refine the criteria for the deployed-to instances, choose **Add tag group** to create an tag group. You can create up to three tag groups with up to ten key-value pairs each. When you use multiple tag groups in a deployment group, only instances that are identified by all the tag groups are included in the deployment group. That means an instance must match at least one of the tags in each of the groups to be included in the deployment group.

      For information about using tag groups to refine your deployment group, see [Tagging instances for deployment groups in CodeDeploy](instances-tagging.md).

1. In **Deployment settings**, choose a deployment configuration to control the rate your application is deployed to instances, such as one at a time or all at once. For more information about deployment configurations, see [Working with deployment configurations in CodeDeploy](deployment-configurations.md).

1. (Optional) In **Load balancer**, select **Enable load balancing**, and then from the lists, select the Classic Load Balancers, Application Load Balancer target groups, and Network Load Balancer target groups to manage traffic to the instances during the CodeDeploy deployment. You can select up to 10 Classic Load Balancers and 10 target groups, for a total of 20 items. Make sure that the Amazon EC2 instances that you want to deploy to are registered with the selected load balancers (Classic Load Balancers) or target groups (Application Load Balancers and Network Load Balancers).

   During a deployment, the original instances are deregistered from the selected load balancers and target groups to prevent traffic from being routed to these instances during the deployment. When the deployment is complete, each instance is re-registered with *all* the selected Classic Load Balancers and target groups.

   For more information about load balancers for CodeDeploy deployments, see [Integrating CodeDeploy with Elastic Load Balancing](integrations-aws-elastic-load-balancing.md).

1. (Optional) Expand **Advanced**, and configure any options you want to include in the deployment, such as Amazon SNS notification triggers, Amazon CloudWatch alarms, or automatic rollbacks.

   For more information, see [Configure advanced options for a deployment group](deployment-groups-configure-advanced-options.md). 

1. Choose **Create deployment group**. 

The next step is to prepare a revision to deploy to the application and deployment group. For instructions, see [Working with application revisions for CodeDeploy](application-revisions.md).

# Create an application for a blue/green deployment (console)
<a name="applications-create-blue-green"></a>

To use the CodeDeploy console to create an application for a blue/green deployment:

**Note**  
A deployment to the AWS Lambda compute platform is always a blue/green deployment. You do not specify a deployment type option.

**Warning**  
Do not follow these steps if:  
You do not have instances with the CodeDeploy agent installed that you want to replace during the blue/green deployment process. To set up your instances, follow the instructions in [Working with instances for CodeDeploy](instances.md), and then follow the steps in this topic.
You want to create an application that uses a custom deployment configuration, but you have not yet created the deployment configuration. Follow the instructions in [Create a deployment configuration with CodeDeploy](deployment-configurations-create.md), and then follow the steps in this topic. 
You do not have a service role that trusts CodeDeploy with, at minimum, the trust and permissions described in [Step 2: Create a service role for CodeDeploy](getting-started-create-service-role.md). To create and configure a service role, follow the instructions in [Step 2: Create a service role for CodeDeploy](getting-started-create-service-role.md), and then follow the steps in this topic.
You have not created a Classic Load Balancer, Application Load Balancer, or Network Load Balancer in Elastic Load Balancing for the registration of the instances in your replacement environment. For more information, see [Set up a load balancer in Elastic Load Balancing for CodeDeploy Amazon EC2 deployments](deployment-groups-create-load-balancer.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. In the navigation pane, expand **Deploy**, and then choose **Getting started**.

1. In **Application name**, enter the name of your application .

1. From **Compute platform**, choose **EC2/On-Premises**.

1. Choose **Create application**.

1. On your application page, from the **Deployment groups** tab, choose **Create deployment group**.

1. In **Deployment group name**, enter a name that describes the deployment group.
**Note**  
If you want to use the same settings used in another deployment group (including the deployment group name tags, Amazon EC2 Auto Scaling group names, and the deployment configuration), choose those settings on this page. Although this new deployment group and the existing deployment group have the same name, CodeDeploy treats them as separate deployment groups, because each is associated with a separate application.

1. In **Service role**, choose a service role that grants CodeDeploy access to your target instance.

1. In **Deployment type** choose **Blue/green**.

1. In **Environment configuration**, choose the method to use to provide instances for your replacement environment:

   1. **Automatically copy Amazon EC2 Auto Scaling group**: CodeDeploy creates an Amazon EC2 Auto Scaling group by copying one you specify.

   1. **Manually provision instances**: You won't specify the instances for your replacement environment until you create a deployment. You must create the instances before you start the deployment. Instead, here you specify the instances you want to replace.

1. Depending on your choice in step 10, do one of the following:
   + If you chose **Automatically copy Amazon EC2 Auto Scaling group**: In **Amazon EC2 Auto Scaling group**, choose or enter the name of the Amazon EC2 Auto Scaling group you want to use as a template for the Amazon EC2 Auto Scaling group for the instances in your replacement environment. The number of currently healthy instances in the Amazon EC2 Auto Scaling group you choose is created in your replacement environment.
   + If you chose **Manually provision instances**: Enable **Amazon EC2 Auto Scaling groups**, **Amazon EC2 instances**, or both to specify instances to add to this deployment group. Enter Amazon EC2 tag values or Amazon EC2 Auto Scaling group names to identify the instances in your original environment (that is, the instances you want to replace or that are running the current application revision). 

1. In **Load balancer**, select **Enable load balancing**, and then from the lists, select the Classic Load Balancers, Application Load Balancer target groups, and Network Load Balancer target groups that you want to register your replacement Amazon EC2 instances with. Each replacement instance will be registered with *all* the selected Classic Load Balancers and target groups. You can select up to 10 Classic Load Balancers and 10 target groups, for a total of 20 items.

   Traffic will be rerouted from the original to the replacement instances according to your chosen **Traffic rerouting** and **Deployment configuration** settings.

   For more information about load balancers for CodeDeploy deployments, see [Integrating CodeDeploy with Elastic Load Balancing](integrations-aws-elastic-load-balancing.md).

1. In **Deployment settings**, review the default options for rerouting traffic to the replacement environment, which deployment configuration to use for the deployment, and how instances in the original environment are handled after the deployment.

   If you want to change the settings, continue to the next step. Otherwise, skip to step 15.

1. To change the deployment settings for the blue/green deployment, change any of the following settings.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/codedeploy/latest/userguide/applications-create-blue-green.html)

1. (Optional) In **Advanced**, configure options you want to include in the deployment, such as Amazon SNS notification triggers, Amazon CloudWatch alarms, or automatic rollbacks.

   For information about specifying advanced options in deployment groups, see [Configure advanced options for a deployment group](deployment-groups-configure-advanced-options.md). 

1. Choose **Create deployment group**. 

The next step is to prepare a revision to deploy to the application and deployment group. For instructions, see [Working with application revisions for CodeDeploy](application-revisions.md).

# Create an application for an Amazon ECS service deployment (console)
<a name="applications-create-ecs"></a>

 You can use the CodeDeploy console to create an application for an Amazon ECS service deployment. 

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**, and choose **Getting started**.

1. On the **Create application** page, choose **Use CodeDeploy**.

1. In **Application name**, enter the name of your application.

1. From **Compute platform**, choose **Amazon ECS**.

1. Choose **Create application**.

1. On your application page, from the **Deployment groups** tab, choose **Create deployment group**. For more information about what you need to create a deployment group for an Amazon ECS deployment, see [Before you begin an Amazon ECS deployment](deployment-steps-ecs.md#deployment-steps-prerequisites-ecs). 

1. In **Deployment group name**, enter a name that describes the deployment group.
**Note**  
If you want to use the same settings used in another deployment group (including the deployment group name and the deployment configuration), choose those settings on this page. Although this new group and the existing group might have the same name, CodeDeploy treats them as separate deployment groups, because each is associated with a separate application.

1. In **Service role**, choose a service role that grants CodeDeploy access to Amazon ECS. For more information, see [Step 2: Create a service role for CodeDeploy](getting-started-create-service-role.md).

1.  From **Load balancer name**, choose the name of the load balancer that serves traffic to your Amazon ECS service. 

1.  From **Production listener port**, choose the port and protocol for the listener that serves production traffic to your Amazon ECS service. 

1.  (Optional) From **Test listener port**, choose the port and protocol of a test listener that serves traffic to the replacement task set in your Amazon ECS service during deployment. You can specify one or more Lambda funtions in the AppSpec file that run during the `AfterAllowTestTraffic` hook. The functions can run validation tests. If a validation test fails, a deployment rollback is triggered. If the validation tests succeed, the next hook in the deployment lifecycle, `BeforeAllowTraffic`, is triggered. If a test listener port is not specified, nothing happens during the `AfterAllowTestTraffic` hook. For more information, see [AppSpec 'hooks' section for an Amazon ECS deployment](reference-appspec-file-structure-hooks.md#appspec-hooks-ecs). 

1. From **Target group 1 name** and **Target group 2 name**, choose the target groups used to route traffic during your deployment. CodeDeploy binds one target group to your Amazon ECS service's original task set and the other to its replacement task set. For more information, see [Target Groups for Your Application Load Balancers](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html). 

1.  Choose **Reroute traffic immediately** or **Specify when to reroute traffic** to determine when to reroute traffic to your updated Amazon ECS service. 

    If you choose **Reroute traffic immediately**, then the deployment automatically reroutes traffic after the replacement task set is provisioned. 

    If you choose **Specify when to reroute traffic**, then choose the number of days, hours, and minutes to wait after the replacement task set is successfully provisioned. During this wait time, validation tests in Lambda functions specified in the AppSpec file are executed. If the wait time expires before traffic is rerouted, then the deployment status changes to `Stopped`. 

1.  For **Original revision termination**, choose the number of days, hours, and minutes to wait after a successful deployment before the original task set in your Amazon ECS service is terminated. 

1. (Optional) In **Advanced**, configure any options you want to include in the deployment, such as Amazon SNS notification triggers, Amazon CloudWatch alarms, or automatic rollbacks.

   For more information, see [Configure advanced options for a deployment group](deployment-groups-configure-advanced-options.md). 

# Create an application for an AWS Lambda function deployment (console)
<a name="applications-create-lambda"></a>

You can use the CodeDeploy console to create an application for an AWS Lambda function deployment.

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**, and choose **Getting started**.

1. On the **Create application** page, choose **Use CodeDeploy**.

1. Enter the name of your application in **Application name**.

1. From **Compute platform**, choose **AWS Lambda**.

1. Choose **Create application**.

1. On your application page, from the **Deployment groups** tab, choose **Create deployment group**.

1. In **Deployment group name**, enter a name that describes the deployment group.
**Note**  
If you want to use the same settings used in another deployment group (including the deployment group name and the deployment configuration), choose those settings on this page. Although this new deployment group and the existing deployment group might have the same name, CodeDeploy treats them as separate deployment groups, because each is associated with a separate application.

1. In **Service role**, choose a service role that grants CodeDeploy access to AWS Lambda. For more information, see [Step 2: Create a service role for CodeDeploy](getting-started-create-service-role.md).

1.  If you want to use a predefined deployment configuration, choose one from **Deployment configuration**, and then skip to step 12. To create a custom configuration, continue to the next step.

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

1. To create a custom configuration, choose **Create deployment configuration**, and then do the following:

   1. For **Deployment configuration name**, enter a name for the configuration.

   1. From **Type**, choose a configuration type. If you choose **Canary**, traffic is shifted in two increments. If you choose **Linear**, traffic is shifted in equal increments, with an equal number of minutes between each increment.

   1. For **Step**, enter a percentage of traffic, between 1 and 99, to be shifted. If your configuration type is **Canary**, this is the percentage of traffic that is shifted in the first increment. The remaining traffic is shifted after the selected interval in the second increment. If your configuration type is **Linear**, this is the percentage of traffic that is shifted at the start of each interval.

   1. In **Interval**, enter the number of minutes. If your configuration type is **Canary**, this is the number of minutes between the first and second traffic shift. If your configuration type is **Linear**, this is the number of minutes between each incremental shift.
**Note**  
The maximum length of an AWS Lambda deployment is two days, or 2,880 minutes. Therefore, the maximum value specified for **Interval** for a canary configuration is 2,800 minutes. The maximum value for a linear configuration depends on the value for **Step**. For example, if the step percentage of a linear traffic shift is 25%, then there are four traffic shifts. The maximum interval value is 2,880 divided by four, or 720 minutes.

   1. Choose **Create deployment configuration**.

1. (Optional) In **Advanced**, configure any options you want to include in the deployment, such as Amazon SNS notification triggers, Amazon CloudWatch alarms, or automatic rollbacks.

   For more information, see [Configure advanced options for a deployment group](deployment-groups-configure-advanced-options.md). 

1. Choose **Create deployment group**. 

# Create an application (CLI)
<a name="applications-create-cli"></a>

To use the AWS CLI to create an application, call the [create-application](https://docs.aws.amazon.com/cli/latest/reference/deploy/create-application.html) command, specifying a name that uniquely represents the application. (In an AWS account, a CodeDeploy application name can be used only once per region. You can reuse an application name in different regions.)

After you use the AWS CLI to create an application, the next step is to create a deployment group that specifies the instances to which to deploy revisions. For instructions, see [Create a deployment group with CodeDeploy](deployment-groups-create.md).

After you create the deployment group, the next step is to prepare a revision to deploy to the application and deployment group. For instructions, see [Working with application revisions for CodeDeploy](application-revisions.md).