AWS CloudFormation
User Guide (API Version 2010-05-15)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。请点击 Amazon AWS 入门,可查看中国地区的具体差异

AWS::CodeDeploy::DeploymentGroup

AWS::CodeDeploy::DeploymentGroup 资源创建 AWS CodeDeploy 部署组,该部署组指定应用程序修订版将部署到哪些实例以及其他部署选项。有关更多信息,请参阅 AWS CodeDeploy API Reference 中的 CreateDeploymentGroup

语法

要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:

属性

AlarmConfiguration

有关与部署组关联的 Amazon CloudWatch 警报的信息。

Required: No

Type: AWS CodeDeploy DeploymentGroup AlarmConfiguration

更新要求无需中断

ApplicationName

要与此部署组关联的现有 AWS CodeDeploy 应用程序的名称。

Required: Yes

Type: String

更新要求替换

AutoRollbackConfiguration

有关与部署组关联的自动回滚配置的信息。如果您指定了此属性,请勿指定 Deployment 属性。

必需:否

类型AWS CodeDeploy DeploymentGroup AutoRollbackConfiguration

更新要求无需中断

AutoScalingGroups

关联的 Auto Scaling 组的列表(创建新实例时,AWS CodeDeploy 将修订自动部署到这些组)。不允许重复项。

Required: No

Type: List of String values

更新要求无需中断

Deployment

部署到该部署组的应用程序版本。如果您指定此属性,您的目标应用程序修订版将在预配置过程完成后立即部署。如果您指定了此属性,请勿指定 AutoRollbackConfiguration 属性。

Required: No

Type: AWS CodeDeploy DeploymentGroup 部署

更新要求无需中断

DeploymentConfigName

部署配置名称或预定义的配置名称。借助预定义配置,您可以将应用程序修订一次部署到一个实例、一次部署到半数实例或一次部署到所有实例。有关更多信息及有效值,请参阅 AWS CodeDeploy User Guide 中的使用部署配置

Required: No

Type: String

更新要求无需中断

DeploymentGroupName

部署组的名称。如果不指定名称,则 AWS CloudFormation 生成一个唯一的物理 ID 并将此 ID 用作部署组的名称。有关更多信息,请参阅 名称类型

重要

如果指定一个名称,您将无法执行需要替换此资源的更新。您可以执行不需要或者只需要部分中断的更新。如果必须替换资源,请指定新名称。

Required: No

Type: String

更新要求替换

DeploymentStyle

确定部署类型的属性,包括指定是否路由 AWS CodeDeploy 部署组的负载均衡器后面的部署流量。

注意

目前,AWS CloudFormation 仅支持 IN_PLACE 部署类型。

必需:否

类型AWS CodeDeploy DeploymentGroup DeploymentStyle

更新要求无需中断

Ec2TagFilters

已经应用于要包含在部署组中的 EC2 实例的 EC2 标签。AWS CodeDeploy 包含您在此部署组中指定的任一标签标识的所有 EC2 实例。不允许重复项。

Required: No

类型: 的列表 AWS CodeDeploy DeploymentGroup Ec2TagFilters

更新要求无需中断

LoadBalancerInfo

有关就地部署中要使用的负载均衡器的信息。有关更多信息,请参阅 AWS CodeDeploy User Guide 中的将 AWS CodeDeploy 与 Elastic Load Balancing 集成

注意

目前,AWS CloudFormation 仅支持使用 传统负载均衡器 的 IN_PLACE 部署类型。

必需:否

类型AWS CodeDeploy DeploymentGroup LoadBalancerInfo

更新要求无需中断

OnPremisesInstanceTagFilters

本地实例标签已应用于您要包含在部署组中的本地实例。AWS CodeDeploy 包含您在此部署组中指定的任一标签标识的所有本地实例。要向 AWS CodeDeploy 注册本地实例,请参阅 AWS CodeDeploy User Guide 中的使用 AWS CodeDeploy 的本地实例。不允许重复项。

Required: No

类型: 的列表 AWS CodeDeploy DeploymentGroup OnPremisesInstanceTagFilters

更新要求无需中断

ServiceRoleArn

服务角色 Amazon 资源名称 (ARN)(用于授予 AWS CodeDeploy 代您调用 AWS 产品的权限)。有关更多信息,请参阅 AWS CodeDeploy User Guide 中的为 AWS CodeDeploy 创建服务角色

注意

在某些情况下,您可能需要添加对服务角色策略的依赖关系。有关更多信息,请参阅 DependsOn 属性 中的 IAM 角色策略。

Required: Yes

Type: String

更新要求无需中断

TriggerConfigurations

有关部署组通知触发器的信息。不允许重复项。

Required: No

类型: 的列表 AWS CodeDeploy DeploymentGroup TriggerConfig

更新要求无需中断

返回值

Ref

当您将 AWS::CodeDeploy::DeploymentGroup 资源的逻辑 ID 传递给内部函数 Ref 时,此函数返回部署组名称,例如 mydeploymentgroup-a123d0d1

有关使用 Ref 功能的更多信息,请参阅参考

示例

GitHub 中的修订

下面的示例创建与 Auto Scaling 组关联的部署组,并使用存储在 GitHub 存储库中的应用程序修订。您将存储库信息指定为输入参数。

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" : {"Ref" : "RoleArn"} } }

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: Ref: RoleArn

关联 EC2 实例

下面的示例创建一个使用实例标签将 EC2 实例关联到部署组的部署组。此部署组使用存储在 S3 存储桶中的应用程序修订。

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" : {"Ref" : "RoleArn"} } }

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: Ref: RoleArn

警报和触发器

下面的示例为部署组配置账单警报和通知触发器。

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": { "Ref": "CodeDeployServiceRole" }, "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: !Ref CodeDeployServiceRole 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": { "Ref": "CodeDeployServiceRole" }, "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: !Ref CodeDeployServiceRole TriggerConfigurations: - TriggerEvents: - DeploymentSuccess - DeploymentRollback TriggerName: MyTarget TriggerTargetArn: !Ref mySNSTopic

负载均衡器

以下示例为部署组配置 Elastic Load Balancing 负载均衡器。

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": { "Ref": "CodeDeployServiceRole" }, "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: !Ref CodeDeployServiceRole TriggerConfigurations: - TriggerEvents: - DeploymentSuccess - DeploymentFailure TriggerName: MyTarget TriggerTargetArn: !Ref mySNSTopic Outputs: ELB: Description: ELB for DeploymentGroup Value: !Ref myELB

本页内容: