AWS CloudFormation
User Guide (API Version 2010-05-15)

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 AWS CodeDeploy API Reference.

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: AWS CodeDeploy DeploymentGroup AlarmConfiguration

Update requires: No interruption

ApplicationName

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

Required: Yes

Type: String

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 AWS CodeDeploy automatically deploys revisions to when new instances are created. Duplicates are not allowed.

Required: No

Type: List of String values

Update requires: No interruption

Deployment

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

Required: No

Type: AWS CodeDeploy DeploymentGroup 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, half of the instances at a time, or all the instances at once. For more information and valid values, see Working with Deployment Configurations in the AWS CodeDeploy User Guide.

Required: No

Type: String

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

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 AWS Lambda compute platforms only.

Required: No

Type: DeploymentStyle

Update requires: No interruption

Ec2TagFilters

The EC2 tags that are already applied to EC2 instances that you want to include in the deployment group. AWS CodeDeploy includes all 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: List of AWS CodeDeploy DeploymentGroup Ec2TagFilters

Update requires: No interruption

Ec2TagSet

Specifies information about groups of tags applied to EC2 instances. The deployment group will include only EC2 instances identified by all the tag groups.

You can specify EC2TagFilters or Ec2TagSet, but not both.

Required: No

Type: EC2TagSet

Update requires: No interruption

LoadBalancerInfo

Information about the load balancer used in the deployment. For more information, see Integrating AWS 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. AWS CodeDeploy includes all on-premises instances identified by any of the tags you specify in this deployment group. To register on-premises instances with AWS CodeDeploy, see Working with On-Premises Instances for AWS CodeDeploy in the AWS CodeDeploy User Guide. Duplicates are not allowed.

You can specify OnPremisesInstanceTagFilters or OnPremisesInstanceTagSet, but not both.

Required: No

Type: List of AWS CodeDeploy DeploymentGroup TagFilters

Update requires: No interruption

OnPremisesInstanceTagSet

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

You can specify OnPremisesInstanceTagFilters or OnPremisesInstanceTagSet, but not both.

Required: No

Type:AWS CodeDeploy DeploymentGroup OnPremisesTagSet

Update requires: No interruption

ServiceRoleArn

A service role Amazon Resource Name (ARN) that grants AWS 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

TriggerConfigurations

Information about the notification triggers for the deployment group. Duplicates are not allowed.

Required: No

Type: List of AWS CodeDeploy DeploymentGroup TriggerConfig

Update requires: No interruption

Return Value

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.

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 EC2 Instances

The following example creates a deployment group that uses instance tags to associate EC2 instances with the deployment group. The deployment group uses an application revision that is stored in an 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 ]

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" } } ] } } } }

YAML

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: !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.

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" } } ] } } } }

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

Load Balancer

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

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" } } } }

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

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.

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" } } } }

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'