AWS::CodeDeploy::DeploymentGroup - AWS CloudFormation

AWS::CodeDeploy::DeploymentGroup

The AWS::CodeDeploy::DeploymentGroup resource creates an AWS CodeDeploy deployment group that specifies which instances your application revisions are deployed to, along with other deployment options. For more information, see CreateDeploymentGroup in the CodeDeploy API Reference.

Note

Amazon ECS blue/green deployments through CodeDeploy do not use the AWS::CodeDeploy::DeploymentGroup resource. To perform Amazon ECS blue/green deployments, use the AWS::CodeDeploy::BlueGreen hook. See Perform Amazon ECS blue/green deployments through CodeDeploy using AWS CloudFormation for more information.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

Properties

AlarmConfiguration

Information about the Amazon CloudWatch alarms that are associated with the deployment group.

Required: No

Type: AlarmConfiguration

Update requires: No interruption

ApplicationName

The name of an existing CodeDeploy application to associate this deployment group with.

Required: Yes

Type: String

Minimum: 1

Maximum: 100

Update requires: Replacement

AutoRollbackConfiguration

Information about the automatic rollback configuration that is associated with the deployment group. If you specify this property, don't specify the Deployment property.

Required: No

Type: AutoRollbackConfiguration

Update requires: No interruption

AutoScalingGroups

A list of associated Auto Scaling groups that CodeDeploy automatically deploys revisions to when new instances are created. Duplicates are not allowed.

Required: No

Type: Array of String

Update requires: No interruption

BlueGreenDeploymentConfiguration

Information about blue/green deployment options for a deployment group.

Required: No

Type: BlueGreenDeploymentConfiguration

Update requires: No interruption

Deployment

The application revision to deploy to this deployment group. If you specify this property, your target application revision is deployed as soon as the provisioning process is complete. If you specify this property, don't specify the AutoRollbackConfiguration property.

Required: No

Type: Deployment

Update requires: No interruption

DeploymentConfigName

A deployment configuration name or a predefined configuration name. With predefined configurations, you can deploy application revisions to one instance at a time (CodeDeployDefault.OneAtATime), half of the instances at a time (CodeDeployDefault.HalfAtATime), or all the instances at once (CodeDeployDefault.AllAtOnce). For more information and valid values, see Working with Deployment Configurations in the AWS CodeDeploy User Guide.

Required: No

Type: String

Minimum: 1

Maximum: 100

Update requires: No interruption

DeploymentGroupName

A name for the deployment group. If you don't specify a name, AWS CloudFormation generates a unique physical ID and uses that ID for the deployment group name. For more information, see Name Type.

Important

If you specify a name, you cannot perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name.

Required: No

Type: String

Minimum: 1

Maximum: 100

Update requires: Replacement

DeploymentStyle

Attributes that determine the type of deployment to run and whether to route deployment traffic behind a load balancer.

If you specify this property with a blue/green deployment type, don't specify the AutoScalingGroups, LoadBalancerInfo, or Deployment properties.

Note

For blue/green deployments, AWS CloudFormation supports deployments on Lambda compute platforms only. You can perform Amazon ECS blue/green deployments using AWS::CodeDeploy::BlueGreen hook. See Perform Amazon ECS blue/green deployments through CodeDeploy using AWS CloudFormation for more information.

Required: No

Type: DeploymentStyle

Update requires: No interruption

Ec2TagFilters

The Amazon EC2 tags that are already applied to Amazon EC2 instances that you want to include in the deployment group. CodeDeploy includes all Amazon EC2 instances identified by any of the tags you specify in this deployment group. Duplicates are not allowed.

You can specify EC2TagFilters or Ec2TagSet, but not both.

Required: No

Type: Array of EC2TagFilter

Update requires: No interruption

Ec2TagSet

Information about groups of tags applied to Amazon EC2 instances. The deployment group includes only Amazon EC2 instances identified by all the tag groups. Cannot be used in the same call as ec2TagFilter.

Required: No

Type: EC2TagSet

Update requires: No interruption

ECSServices

The target Amazon ECS services in the deployment group. This applies only to deployment groups that use the Amazon ECS compute platform. A target Amazon ECS service is specified as an Amazon ECS cluster and service name pair using the format <clustername>:<servicename>.

Required: No

Type: Array of ECSService

Update requires: No interruption

LoadBalancerInfo

Information about the load balancer to use in a deployment. For more information, see Integrating CodeDeploy with Elastic Load Balancing in the AWS CodeDeploy User Guide.

Required: No

Type: LoadBalancerInfo

Update requires: No interruption

OnPremisesInstanceTagFilters

The on-premises instance tags already applied to on-premises instances that you want to include in the deployment group. CodeDeploy includes all on-premises instances identified by any of the tags you specify in this deployment group. To register on-premises instances with CodeDeploy, see Working with On-Premises Instances for CodeDeploy in the AWS CodeDeploy User Guide. Duplicates are not allowed.

You can specify OnPremisesInstanceTagFilters or OnPremisesInstanceTagSet, but not both.

Required: No

Type: Array of TagFilter

Update requires: No interruption

OnPremisesTagSet

Information about groups of tags applied to on-premises instances. The deployment group includes only on-premises instances identified by all the tag groups.

You can specify OnPremisesInstanceTagFilters or OnPremisesInstanceTagSet, but not both.

Required: No

Type: OnPremisesTagSet

Update requires: No interruption

OutdatedInstancesStrategy

Indicates what happens when new Amazon EC2 instances are launched mid-deployment and do not receive the deployed application revision.

If this option is set to UPDATE or is unspecified, CodeDeploy initiates one or more 'auto-update outdated instances' deployments to apply the deployed application revision to the new Amazon EC2 instances.

If this option is set to IGNORE, CodeDeploy does not initiate a deployment to update the new Amazon EC2 instances. This may result in instances having different revisions.

Required: No

Type: String

Allowed values: UPDATE | IGNORE

Update requires: No interruption

ServiceRoleArn

A service role Amazon Resource Name (ARN) that grants CodeDeploy permission to make calls to AWS services on your behalf. For more information, see Create a Service Role for AWS CodeDeploy in the AWS CodeDeploy User Guide.

Note

In some cases, you might need to add a dependency on the service role's policy. For more information, see IAM role policy in DependsOn Attribute.

Required: Yes

Type: String

Update requires: No interruption

Tags

The metadata that you apply to CodeDeploy deployment groups to help you organize and categorize them. Each tag consists of a key and an optional value, both of which you define.

Required: No

Type: Array of Tag

Update requires: No interruption

TerminationHookEnabled

Indicates whether the deployment group was configured to have CodeDeploy install a termination hook into an Auto Scaling group.

For more information about the termination hook, see How Amazon EC2 Auto Scaling works with CodeDeploy in the AWS CodeDeploy User Guide.

Required: No

Type: Boolean

Update requires: No interruption

TriggerConfigurations

Information about triggers associated with the deployment group. Duplicates are not allowed

Required: No

Type: Array of TriggerConfig

Update requires: No interruption

Return values

Ref

When you pass the logical ID of an AWS::CodeDeploy::DeploymentGroup resource to the intrinsic Ref function, the function returns the deployment group name, such as mydeploymentgroup-a123d0d1.

For more information about using the Ref function, see Ref.

Fn::GetAtt

Examples

Revision in GitHub

The following example creates a deployment group that is associated with Auto Scaling groups and uses an application revision that is stored in a GitHub repository. You specify the repository information as input parameters.

JSON

"DeploymentGroup" : { "Type" : "AWS::CodeDeploy::DeploymentGroup", "Properties" : { "ApplicationName" : {"Ref" : "ApplicationName"}, "AutoScalingGroups" : [{"Ref" : "CodeDeployAutoScalingGroups" } ], "Deployment" : { "Description" : "A sample deployment", "IgnoreApplicationStopFailures" : "true", "Revision" : { "RevisionType" : "GitHub", "GitHubLocation" : { "CommitId" : {"Ref" : "CommitId"}, "Repository" : {"Ref" : "Repository"} } } }, "ServiceRoleArn" : { "Fn::GetAtt" : [ "RoleArn", "Arn" ] } } }

YAML

DeploymentGroup: Type: AWS::CodeDeploy::DeploymentGroup Properties: ApplicationName: Ref: "ApplicationName" AutoScalingGroups: Ref: CodeDeployAutoScalingGroups Deployment: Description: "A sample deployment" IgnoreApplicationStopFailures: true Revision: RevisionType: GitHub GitHubLocation: CommitId: Ref: CommitId Repository: Ref: Repository ServiceRoleArn: Fn::GetAtt: [ RoleArn, Arn ]

Associate Amazon EC2 Instances

The following example creates a deployment group that uses instance tags to associate Amazon EC2 instances with the deployment group. The deployment group uses an application revision that is stored in an Amazon S3 bucket.

JSON

"DeploymentGroup": { "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "Application" }, "Deployment": { "Description": "First time", "IgnoreApplicationStopFailures": "true", "Revision": { "RevisionType": "S3", "S3Location": { "Bucket": { "Ref": "Bucket" }, "Key": { "Ref": "Key" }, "BundleType": "Zip", "ETag": { "Ref": "ETag" }, "Version": { "Ref": "Version" } } } }, "Ec2TagFilters": [ { "Key": { "Ref": "TagKey" }, "Value": { "Ref": "TagValue" }, "Type": "KEY_AND_VALUE" } ], "ServiceRoleArn": { "Fn::GetAtt": [ "RoleArn", "Arn" ] } } }

YAML

DeploymentGroup: Type: AWS::CodeDeploy::DeploymentGroup Properties: ApplicationName: Ref: "Application" Deployment: Description: "First time" IgnoreApplicationStopFailures: true Revision: RevisionType: S3 S3Location: Bucket: Ref: Bucket Key: Ref: Key BundleType: Zip ETag: Ref: ETag Version: Ref: Version Ec2TagFilters: - Key: Ref: TagKey Value: Ref: TagValue Type: "KEY_AND_VALUE" ServiceRoleArn: Fn::GetAtt: [ RoleArn, Arn ]

Deployment Style

The following example creates deployment group with a BLUE_GREEN deployment type.

JSON

"CodeDeployDeploymentGroup": { "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "CodeDeployApplication" }, "DeploymentConfigName": "CodeDeployDefault.LambdaCanary10Percent5Minutes", "DeploymentStyle": { "DeploymentType": "BLUE_GREEN", "DeploymentOption": "WITH_TRAFFIC_CONTROL" }, "ServiceRoleArn": { "Fn::GetAtt": [ "CodeDeployServiceRole", "Arn" ] } } }

YAML

CodeDeployDeploymentGroup: Type: 'AWS::CodeDeploy::DeploymentGroup' Properties: ApplicationName: Ref: CodeDeployApplication DeploymentConfigName: CodeDeployDefault.LambdaCanary10Percent5Minutes DeploymentStyle: DeploymentType: BLUE_GREEN DeploymentOption: WITH_TRAFFIC_CONTROL ServiceRoleArn: Fn::GetAtt: [ CodeDeployServiceRole, Arn ]

Alarm and Trigger

The following example configures a billing alarm and a notification trigger for the deployment group.

JSON

{ "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { "EC2TagKey0": { "Type": "String", "Default": "ec2TagKey0" }, "EC2TagValue0": { "Type": "String", "Default": "ec2TagValue0" }, "EC2TagKey1": { "Type": "String", "Default": "ec2TagKey1" }, "EC2TagValue1": { "Type": "String", "Default": "ec2TagValue1" }, "CodeDeployServiceRole": { "Type": "String" }, "DeploymentGroupName": { "Type": "String" } }, "Resources": { "myAlarm": { "Type": "AWS::CloudWatch::Alarm", "Properties": { "Namespace": "AWS/Billing", "MetricName": "EstimatedCharges", "Statistic": "Maximum", "Period": "21600", "EvaluationPeriods": "1", "Threshold": 1000, "ComparisonOperator": "GreaterThanThreshold" } }, "mySNSTopic": { "Type": "AWS::SNS::Topic", "Properties": {} }, "Application": { "Type": "AWS::CodeDeploy::Application" }, "DeploymentConfig": { "Type": "AWS::CodeDeploy::DeploymentConfig", "Properties": { "MinimumHealthyHosts": { "Type": "FLEET_PERCENT", "Value": "25" } } }, "DeploymentGroup": { "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "AlarmConfiguration": { "Alarms": [ { "Name": { "Ref": "myAlarm" } } ] }, "ApplicationName": { "Ref": "Application" }, "DeploymentConfigName": { "Ref": "DeploymentConfig" }, "DeploymentGroupName": { "Ref": "DeploymentGroupName" }, "Ec2TagFilters": [ { "Key": { "Ref": "EC2TagKey0" }, "Value": { "Ref": "EC2TagValue0" }, "Type": "KEY_AND_VALUE" }, { "Key": { "Ref": "EC2TagKey1" }, "Type": "KEY_ONLY" }, { "Value": { "Ref": "EC2TagValue1" }, "Type": "VALUE_ONLY" } ], "ServiceRoleArn": { "Fn::GetAtt": [ "CodeDeployServiceRole", "Arn" ] }, "TriggerConfigurations": [ { "TriggerEvents": [ "DeploymentSuccess", "DeploymentRollback" ], "TriggerName": "MyTarget", "TriggerTargetArn": { "Ref": "mySNSTopic" } } ] } } } }

Automatic Rollback Configuration

The following example configures automatic rollback for the deployment group.

YAML

Parameters: EC2TagKey0: Type: String Default: ec2TagKey0 EC2TagValue0: Type: String Default: ec2TagValue0 EC2TagKey1: Type: String Default: ec2TagKey1 EC2TagValue1: Type: String Default: ec2TagValue1 CodeDeployServiceRole: Type: String DeploymentGroupName: Type: String Resources: myAlarm: Type: AWS::CloudWatch::Alarm Properties: Namespace: AWS/Billing MetricName: EstimatedCharges Statistic: Maximum Period: '21600' EvaluationPeriods: '1' Threshold: 1000 ComparisonOperator: GreaterThanThreshold mySNSTopic: Type: AWS::SNS::Topic Properties: {} Application: Type: AWS::CodeDeploy::Application DeploymentConfig: Type: AWS::CodeDeploy::DeploymentConfig Properties: MinimumHealthyHosts: Type: FLEET_PERCENT Value: '25' DeploymentGroup: Type: AWS::CodeDeploy::DeploymentGroup Properties: AlarmConfiguration: Alarms: - Name: !Ref myAlarm ApplicationName: !Ref Application AutoRollbackConfiguration: Enabled: 'true' Events: - DEPLOYMENT_FAILURE DeploymentConfigName: !Ref DeploymentConfig DeploymentGroupName: !Ref DeploymentGroupName Ec2TagFilters: - Key: !Ref EC2TagKey0 Value: !Ref EC2TagValue0 Type: KEY_AND_VALUE - Key: !Ref EC2TagKey1 Type: KEY_ONLY - Value: !Ref EC2TagValue1 Type: VALUE_ONLY ServiceRoleArn: !GetAtt CodeDeployServiceRole.Arn TriggerConfigurations: - TriggerEvents: - DeploymentSuccess - DeploymentRollback TriggerName: MyTarget TriggerTargetArn: !Ref mySNSTopic

JSON

{ "Parameters": { "EC2TagKey0": { "Type": "String", "Default": "ec2TagKey0" }, "EC2TagValue0": { "Type": "String", "Default": "ec2TagValue0" }, "EC2TagKey1": { "Type": "String", "Default": "ec2TagKey1" }, "EC2TagValue1": { "Type": "String", "Default": "ec2TagValue1" }, "CodeDeployServiceRole": { "Type": "String" }, "DeploymentGroupName": { "Type": "String" } }, "Resources": { "myAlarm": { "Type": "AWS::CloudWatch::Alarm", "Properties": { "Namespace": "AWS/Billing", "MetricName": "EstimatedCharges", "Statistic": "Maximum", "Period": "21600", "EvaluationPeriods": "1", "Threshold": 1000, "ComparisonOperator": "GreaterThanThreshold" } }, "mySNSTopic": { "Type": "AWS::SNS::Topic", "Properties": {} }, "Application": { "Type": "AWS::CodeDeploy::Application" }, "DeploymentConfig": { "Type": "AWS::CodeDeploy::DeploymentConfig", "Properties": { "MinimumHealthyHosts": { "Type": "FLEET_PERCENT", "Value": "25" } } }, "DeploymentGroup": { "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "AlarmConfiguration": { "Alarms": [ { "Name": { "Ref": "myAlarm" } } ] }, "ApplicationName": { "Ref": "Application" }, "AutoRollbackConfiguration": { "Enabled": "true", "Events": [ "DEPLOYMENT_FAILURE" ] }, "DeploymentConfigName": { "Ref": "DeploymentConfig" }, "DeploymentGroupName": { "Ref": "DeploymentGroupName" }, "Ec2TagFilters": [ { "Key": { "Ref": "EC2TagKey0" }, "Value": { "Ref": "EC2TagValue0" }, "Type": "KEY_AND_VALUE" }, { "Key": { "Ref": "EC2TagKey1" }, "Type": "KEY_ONLY" }, { "Value": { "Ref": "EC2TagValue1" }, "Type": "VALUE_ONLY" } ], "ServiceRoleArn": { "Fn::GetAtt": [ "CodeDeployServiceRole", "Arn" ] }, "TriggerConfigurations": [ { "TriggerEvents": [ "DeploymentSuccess", "DeploymentRollback" ], "TriggerName": "MyTarget", "TriggerTargetArn": { "Ref": "mySNSTopic" } } ] } } } }

Load Balancer

The following example configures an Elastic Load Balancing load balancer for the deployment group.

YAML

Parameters: EC2TagKey0: Type: String Default: ec2TagKey0 EC2TagValue0: Type: String Default: ec2TagValue0 EC2TagKey1: Type: String Default: ec2TagKey1 EC2TagValue1: Type: String Default: ec2TagValue1 CodeDeployServiceRole: Type: String DeploymentGroupName: Type: String VpcCidr: Type: String SubnetCidr: Type: String Resources: myVpc: Type: AWS::EC2::VPC Properties: CidrBlock: !Ref VpcCidr mySubnet: Type: AWS::EC2::Subnet Properties: VpcId: !Ref myVpc CidrBlock: !Ref SubnetCidr InternetGateway: Type: AWS::EC2::InternetGateway AttachGateway: Type: AWS::EC2::VPCGatewayAttachment Properties: VpcId: !Ref myVpc InternetGatewayId: !Ref InternetGateway myELB: Type: AWS::ElasticLoadBalancing::LoadBalancer Properties: Listeners: - InstancePort: '8000' LoadBalancerPort: '80' Protocol: HTTP Subnets: - !Ref mySubnet mySNSTopic: Type: AWS::SNS::Topic Properties: {} Application: Type: AWS::CodeDeploy::Application DeploymentConfig: Type: AWS::CodeDeploy::DeploymentConfig Properties: MinimumHealthyHosts: Type: FLEET_PERCENT Value: '25' DeploymentGroup: Type: AWS::CodeDeploy::DeploymentGroup Properties: ApplicationName: !Ref Application DeploymentConfigName: !Ref DeploymentConfig DeploymentGroupName: !Ref DeploymentGroupName Ec2TagFilters: - Key: !Ref EC2TagKey0 Value: !Ref EC2TagValue0 Type: KEY_AND_VALUE - Key: !Ref EC2TagKey1 Type: KEY_ONLY LoadBalancerInfo: ElbInfoList: - Name: !Ref myELB DeploymentStyle: DeploymentOption: WITH_TRAFFIC_CONTROL ServiceRoleArn: !GetAtt CodeDeployServiceRole.Arn TriggerConfigurations: - TriggerEvents: - DeploymentSuccess - DeploymentFailure TriggerName: MyTarget TriggerTargetArn: !Ref mySNSTopic Outputs: ELB: Description: ELB for DeploymentGroup Value: !Ref myELB

JSON

{ "Parameters": { "EC2TagKey0": { "Type": "String", "Default": "ec2TagKey0" }, "EC2TagValue0": { "Type": "String", "Default": "ec2TagValue0" }, "EC2TagKey1": { "Type": "String", "Default": "ec2TagKey1" }, "EC2TagValue1": { "Type": "String", "Default": "ec2TagValue1" }, "CodeDeployServiceRole": { "Type": "String" }, "DeploymentGroupName": { "Type": "String" }, "VpcCidr": { "Type": "String" }, "SubnetCidr": { "Type": "String" } }, "Resources": { "myVpc": { "Type": "AWS::EC2::VPC", "Properties": { "CidrBlock": { "Ref": "VpcCidr" } } }, "mySubnet" : { "Type" : "AWS::EC2::Subnet", "Properties" : { "VpcId" : { "Ref" : "myVpc" }, "CidrBlock" : { "Ref": "SubnetCidr" } } }, "InternetGateway" : { "Type" : "AWS::EC2::InternetGateway" }, "AttachGateway" : { "Type" : "AWS::EC2::VPCGatewayAttachment", "Properties" : { "VpcId" : { "Ref" : "myVpc" }, "InternetGatewayId" : { "Ref" : "InternetGateway" } } }, "myELB": { "Type": "AWS::ElasticLoadBalancing::LoadBalancer", "Properties": { "Listeners": [{ "InstancePort": "8000", "LoadBalancerPort": "80", "Protocol": "HTTP" }], "Subnets": [ { "Ref" : "mySubnet" } ] } }, "mySNSTopic": { "Type": "AWS::SNS::Topic", "Properties": {} }, "Application": { "Type": "AWS::CodeDeploy::Application" }, "DeploymentConfig": { "Type": "AWS::CodeDeploy::DeploymentConfig", "Properties": { "MinimumHealthyHosts": { "Type": "FLEET_PERCENT", "Value": "25" } } }, "DeploymentGroup": { "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "Application" }, "DeploymentConfigName": { "Ref": "DeploymentConfig" }, "DeploymentGroupName": { "Ref": "DeploymentGroupName" }, "Ec2TagFilters": [ { "Key": { "Ref": "EC2TagKey0" }, "Value": { "Ref": "EC2TagValue0" }, "Type": "KEY_AND_VALUE" }, { "Key": { "Ref": "EC2TagKey1" }, "Type": "KEY_ONLY" } ], "LoadBalancerInfo": { "ElbInfoList": [{ "Name": { "Ref" : "myELB" } }] }, "DeploymentStyle": { "DeploymentOption": "WITH_TRAFFIC_CONTROL" }, "ServiceRoleArn": { "Fn::GetAtt": [ "CodeDeployServiceRole", "Arn" ] }, "TriggerConfigurations": [ { "TriggerEvents": [ "DeploymentSuccess", "DeploymentFailure" ], "TriggerName": "MyTarget", "TriggerTargetArn": { "Ref": "mySNSTopic" } } ] } } }, "Outputs": { "ELB": { "Description": "ELB for DeploymentGroup", "Value" : { "Ref" : "myELB" } } } }

Target Group Info

The following example specifies the target group to use in a deployment. Instances are registered as targets in a target group, and traffic is routed to the target group.

YAML

AWSTemplateFormatVersion: 2010-09-09 Resources: AppDeploymentGroup: Type: AWS::CodeDeploy::DeploymentGroup Properties: ApplicationName: MyApp DeploymentStyle: DeploymentOption: WITH_TRAFFIC_CONTROL LoadBalancerInfo: TargetGroupInfoList: - Name: !GetAtt MyTargetGroup.TargetGroupName ServiceRoleArn: 'arn:aws:iam::12345678:role/CodeDeployServiceRole'

JSON

{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "AppDeploymentGroup": { "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": "MyApp", "DeploymentStyle": { "DeploymentOption": "WITH_TRAFFIC_CONTROL" }, "LoadBalancerInfo": { "TargetGroupInfoList": [ { "Name": { "Fn::GetAtt": ["MyTargetGroup", "TargetGroupName"] } } ] }, "ServiceRoleArn": "arn:aws:iam::12345678:role/CodeDeployServiceRole" } } } }