diff --git a/packages/@aws-cdk/aws-codedeploy/README.md b/packages/@aws-cdk/aws-codedeploy/README.md index 2608c706022ea..3d960bcc2c64a 100644 --- a/packages/@aws-cdk/aws-codedeploy/README.md +++ b/packages/@aws-cdk/aws-codedeploy/README.md @@ -327,3 +327,75 @@ const deploymentGroup = codedeploy.LambdaDeploymentGroup.fromLambdaDeploymentGro deploymentGroupName: 'MyExistingDeploymentGroup', }); ``` + +## ECS Applications + +To create a new CodeDeploy Application that deploys to an ECS service: + +```ts +const application = new codedeploy.EcsApplication(this, 'CodeDeployApplication', { + applicationName: 'MyApplication', // optional property +}); +``` + +To import an already existing Application: + +```ts +const application = codedeploy.EcsApplication.fromEcsApplicationName( + this, + 'ExistingCodeDeployApplication', + 'MyExistingApplication', +); +``` + +## ECS Deployment Groups + +To enable traffic shifting deployments for ECS Services, CodeDeploy uses TaskSets and TargetGroups, which can balance incoming traffic between two different versions of your function. Before deployment, the listener sends 100% of requests to the production target group. When you publish a new version of the task definition to your stack, CodeDeploy will send a small percentage of traffic to the new task sets, monitor, and validate before shifting 100% of traffic to the new version. + +To create a new CodeDeploy Deployment Group that deploys to a ECS service: + +```ts +declare const myApplication: codedeploy.EcsApplication; +declare const service: ecs.FargateService; +declare const blueTargetGroup = elbv2.ITargetGroup; +declare const greenTargetGroup = elbv2.ITargetGroup; +declare const prodListener = elbv2.IApplicationListener; + +const deploymentGroup = new codedeploy.EcsDeploymentGroup(this, 'BlueGreenDeployment', { + application: myApplication, // optional property: one will be created for you if not provided + services: [ + service + ], + blueGreenDeploymentConfiguration: { + prodListener, + blueTargetGroup, + greenTargetGroup, + } + deploymentConfig: codedeploy.EcsDeploymentConfig.CANARY_10_PERCENT_5_MINUTES, +}); +``` + +### Create a custom ECS Deployment Config + +CodeDeploy for ECS comes with built-in configurations for traffic shifting. +If you want to specify your own strategy, +you can do so with the EcsDeploymentConfig construct, +letting you specify precisely how fast a new function version is deployed. + +```ts +const config = new codedeploy.EcsDeploymentConfig(this, 'CustomConfig', { + trafficRoutingConfig: new codeDeploy.TimeBasedCanaryTrafficRoutingConfig(5, 10); +}); +``` + +### Import an existing ECS Deployment Group + +To import an already existing Deployment Group: + +```ts +declare const application: codedeploy.EcsApplication; +const deploymentGroup = codedeploy.EcsDeploymentGroup.fromEcsDeploymentGroupAttributes(this, 'ExistingCodeDeployDeploymentGroup', { + application, + deploymentGroupName: 'MyExistingDeploymentGroup', +}); +``` diff --git a/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-config.ts b/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-config.ts index f9f41e12202a7..8aaacc3d4c9de 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-config.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-config.ts @@ -1,47 +1,92 @@ +import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; -import { arnForDeploymentConfig } from '../utils'; +import { CfnDeploymentConfig } from '../codedeploy.generated'; +import { ITrafficRoutingConfig } from '../traffic-routing-config'; +import { arnForDeploymentConfig, validateName } from '../utils'; /** * The Deployment Configuration of an ECS Deployment Group. * The default, pre-defined Configurations are available as constants on the {@link EcsDeploymentConfig} class * (for example, `EcsDeploymentConfig.AllAtOnce`). - * - * Note: CloudFormation does not currently support creating custom ECS configs outside - * of using a custom resource. You can import custom deployment config created outside the - * CDK or via a custom resource with {@link EcsDeploymentConfig#fromEcsDeploymentConfigName}. + * To create a custom Deployment Configuration, + * instantiate the {@link EcsDeploymentConfig} Construct. */ export interface IEcsDeploymentConfig { + /** + * @attribute + */ readonly deploymentConfigName: string; + /** + * @attribute + */ readonly deploymentConfigArn: string; } +/** + * Construction properties of {@link EcsDeploymentConfig}. + */ +export interface EcsDeploymentConfigProps { + /** + * The physical, human-readable name of the Deployment Configuration. + * + * @default a name will be auto-generated + */ + readonly deploymentConfigName?: string; + + /** + * The configuration that specifies how traffic is shifed from one + * Amazon ECS task set to another during an Amazon ECS deployment. + * + */ + readonly trafficRoutingConfig: ITrafficRoutingConfig; + +} + /** * A custom Deployment Configuration for an ECS Deployment Group. * - * Note: This class currently stands as namespaced container of the default configurations - * until CloudFormation supports custom ECS Deployment Configs. Until then it is closed - * (private constructor) and does not extend {@link Construct} - * * @resource AWS::CodeDeploy::DeploymentConfig */ -export class EcsDeploymentConfig { +export class EcsDeploymentConfig extends cdk.Resource implements IEcsDeploymentConfig { public static readonly ALL_AT_ONCE = deploymentConfig('CodeDeployDefault.ECSAllAtOnce'); + public static readonly LINEAR_10_PERCENT_1_MINUTES = deploymentConfig('CodeDeployDefault.ECSLinear10PercentEvery1Minutes'); + public static readonly LINEAR_10_PERCENT_3_MINUTES = deploymentConfig('CodeDeployDefault.ECSLinear10PercentEvery3Minutes'); + public static readonly CANARY_10_PERCENT_5_MINUTES = deploymentConfig('CodeDeployDefault.ECSCanary10Percent5Minutes'); + public static readonly CANARY_10_PERCENT_15_MINUTES = deploymentConfig('CodeDeployDefault.ECSCanary10Percent15Minutes'); /** * Import a custom Deployment Configuration for an ECS Deployment Group defined outside the CDK. * - * @param _scope the parent Construct for this new Construct - * @param _id the logical ID of this new Construct + * @param scope the parent Construct for this new Construct + * @param id the logical ID of this new Construct * @param ecsDeploymentConfigName the name of the referenced custom Deployment Configuration * @returns a Construct representing a reference to an existing custom Deployment Configuration */ - public static fromEcsDeploymentConfigName(_scope: Construct, _id: string, ecsDeploymentConfigName: string): IEcsDeploymentConfig { + public static fromEcsDeploymentConfigName(scope: Construct, id: string, ecsDeploymentConfigName: string): IEcsDeploymentConfig { + ignore(scope); + ignore(id); return deploymentConfig(ecsDeploymentConfigName); } - private constructor() { - // nothing to do until CFN supports custom ECS deployment configurations + public readonly deploymentConfigName: string; + public readonly deploymentConfigArn: string; + + constructor(scope: Construct, id: string, props: EcsDeploymentConfigProps) { + super(scope, id, { + physicalName: props.deploymentConfigName, + }); + const resource = new CfnDeploymentConfig(this, 'Resource', { + computePlatform: 'ECS', + deploymentConfigName: this.physicalName, + trafficRoutingConfig: props.trafficRoutingConfig?.renderTrafficRoutingConfig(), + }); + + this.deploymentConfigName = resource.ref; + this.deploymentConfigArn = arnForDeploymentConfig(this.deploymentConfigName); + + this.node.addValidation({ validate: () => validateName('Deployment config', this.physicalName) }); } + } function deploymentConfig(name: string): IEcsDeploymentConfig { @@ -50,3 +95,5 @@ function deploymentConfig(name: string): IEcsDeploymentConfig { deploymentConfigArn: arnForDeploymentConfig(name), }; } + +function ignore(_x: any) { return; } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-group.ts index 4a432631375e5..4ea33fc509f13 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-group.ts @@ -1,11 +1,24 @@ +import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; +import * as ecs from '@aws-cdk/aws-ecs'; +import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; +import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; -import { arnForDeploymentGroup } from '../utils'; -import { IEcsApplication } from './application'; +import { CfnDeploymentGroup } from '../codedeploy.generated'; +import { AutoRollbackConfig } from '../rollback-config'; +import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration, validateName } from '../utils'; +import { EcsApplication, IEcsApplication } from './application'; import { EcsDeploymentConfig, IEcsDeploymentConfig } from './deployment-config'; /** - * Interface for an ECS deployment group. + * Represents a reference to a CodeDeploy Deployment Group deploying to Amazon ECS. + * + * If you're managing the Deployment Group alongside the rest of your CDK resources, + * use the {@link EcsDeploymentGroup} class. + * + * If you want to reference an already existing Deployment Group, + * or one defined in a different CDK Stack, + * use the {@link EcsDeploymentGroup#fromEcsDeploymentGroupAttributes} method. */ export interface IEcsDeploymentGroup extends cdk.IResource { /** @@ -32,14 +45,85 @@ export interface IEcsDeploymentGroup extends cdk.IResource { } /** - * Note: This class currently stands as a namespaced container for importing an ECS - * Deployment Group defined outside the CDK app until CloudFormation supports provisioning - * ECS Deployment Groups. Until then it is closed (private constructor) and does not - * extend {@link Construct}. + * Construction properties for {@link EcsDeploymentGroup}. + */ +export interface EcsDeploymentGroupProps { + /** + * The reference to the ECS Services to deploy. + * + * [disable-awslint:ref-via-interface] because the service needs to have the deploy controller changed to Code Deploy + */ + readonly services: ecs.BaseService[]; + + /** + * The reference to the CodeDeploy ECS Application + * that this Deployment Group belongs to. + * + * @default - One will be created for you. + */ + readonly application?: IEcsApplication; + + /** + * The physical, human-readable name of the CodeDeploy ECS Deployment Group + * that we are referencing. + * + * @default an auto-generated name will be used + */ + readonly deploymentGroupName?: string; + + /** + * The Deployment Configuration this Deployment Group uses. + * + * @default EcsDeploymentConfig.ALL_AT_ONCE + */ + readonly deploymentConfig?: IEcsDeploymentConfig; + + /** + * The CloudWatch alarms associated with this Deployment Group. + * CodeDeploy will stop (and optionally roll back) + * a deployment if during it any of the alarms trigger. + * + * Alarms can also be added after the Deployment Group is created using the {@link #addAlarm} method. + * + * @default [] + * @see https://docs.aws.amazon.com/codedeploy/latest/userguide/monitoring-create-alarms.html + */ + readonly alarms?: cloudwatch.IAlarm[]; + + /** + * The service Role of this Deployment Group. + * + * @default - A new Role will be created. + */ + readonly role?: iam.IRole; + + + /** + * Whether to continue a deployment even if fetching the alarm status from CloudWatch failed. + * + * @default false + */ + readonly ignorePollAlarmsFailure?: boolean; + + /** + * The auto-rollback configuration for this Deployment Group. + * + * @default - default AutoRollbackConfig. + */ + readonly autoRollback?: AutoRollbackConfig; + + /** + * The blue/green deployment configuration + */ + readonly blueGreenDeploymentConfiguration: EcsBlueGreenDeploymentConfig; +} + +/** + * A CodeDeploy Deployment Group that deploys to an Amazon ECS service. * * @resource AWS::CodeDeploy::DeploymentGroup */ -export class EcsDeploymentGroup { +export class EcsDeploymentGroup extends cdk.Resource implements IEcsDeploymentGroup { /** * Import an ECS Deployment Group defined outside the CDK app. * @@ -55,8 +139,89 @@ export class EcsDeploymentGroup { return new ImportedEcsDeploymentGroup(scope, id, attrs); } - private constructor() { - // nothing to do until CFN supports ECS deployment groups + public readonly application: IEcsApplication; + public readonly deploymentGroupName: string; + public readonly deploymentGroupArn: string; + public readonly deploymentConfig: IEcsDeploymentConfig; + /** + * The role for this CodeDeploy to use when deploying to this deployment group. + */ + public readonly role: iam.IRole; + private readonly alarms: cloudwatch.IAlarm[]; + + constructor(scope: Construct, id: string, props: EcsDeploymentGroupProps) { + super(scope, id, { + physicalName: props.deploymentGroupName, + }); + + this.application = props.application || new EcsApplication(this, 'Application'); + this.alarms = props.alarms || []; + + this.role = props.role || new iam.Role(this, 'ServiceRole', { + assumedBy: new iam.ServicePrincipal('codedeploy.amazonaws.com'), + }); + this.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AWSCodeDeployRoleForECSLimited')); + this.deploymentConfig = props.deploymentConfig || EcsDeploymentConfig.ALL_AT_ONCE; + + // Change ECS Service deployment controller to codedeploy + for (const service of props.services) { + const cfnService = service.node.defaultChild as ecs.CfnService; + cfnService.deploymentController = { type: ecs.DeploymentControllerType.CODE_DEPLOY }; + + // Remove revision from ECS Service task definition to allow Blue/Green deploys to work + cfnService.taskDefinition = service.taskDefinition.family; + service.node.addDependency(service.taskDefinition); + } + + const resource = new CfnDeploymentGroup(this, 'Resource', { + applicationName: this.application.applicationName, + serviceRoleArn: this.role.roleArn, + deploymentGroupName: this.physicalName, + deploymentConfigName: this.deploymentConfig.deploymentConfigName, + deploymentStyle: { + deploymentType: 'BLUE_GREEN', + deploymentOption: 'WITH_TRAFFIC_CONTROL', + }, + ecsServices: props.services.map(s => { + return { + clusterName: s.cluster.clusterName, + serviceName: s.serviceName, + }; + }), + loadBalancerInfo: cdk.Lazy.any({ + produce: () => renderLoadBalancerInfo(props.blueGreenDeploymentConfiguration), + }), + blueGreenDeploymentConfiguration: cdk.Lazy.any({ + produce: () => renderBlueGreenDeploymentConfiguration( props.blueGreenDeploymentConfiguration ), + }), + alarmConfiguration: cdk.Lazy.any({ produce: () => renderAlarmConfiguration(this.alarms, props.ignorePollAlarmsFailure) }), + autoRollbackConfiguration: cdk.Lazy.any({ produce: () => renderAutoRollbackConfiguration(this.alarms, props.autoRollback) }), + }); + + this.deploymentGroupName = this.getResourceNameAttribute(resource.ref); + this.deploymentGroupArn = this.getResourceArnAttribute(arnForDeploymentGroup(this.application.applicationName, resource.ref), { + service: 'codedeploy', + resource: 'deploymentgroup', + resourceName: `${this.application.applicationName}/${this.physicalName}`, + arnFormat: cdk.ArnFormat.COLON_RESOURCE_NAME, + }); + + // If the deployment config is a construct, add a dependency to ensure the deployment config + // is created before the deployment group is. + if (this.deploymentConfig instanceof Construct) { + this.node.addDependency(this.deploymentConfig); + } + + this.node.addValidation({ validate: () => validateName('Deployment group', this.physicalName) }); + } + + /** + * Associates an additional alarm with this Deployment Group. + * + * @param alarm the alarm to associate with this Deployment Group + */ + public addAlarm(alarm: cloudwatch.IAlarm): void { + this.alarms.push(alarm); } } @@ -100,3 +265,90 @@ class ImportedEcsDeploymentGroup extends cdk.Resource implements IEcsDeploymentG this.deploymentConfig = props.deploymentConfig || EcsDeploymentConfig.ALL_AT_ONCE; } } + +/** + * Configuraiton for blue green deployments. + */ +export interface EcsBlueGreenDeploymentConfig { + /** + * The reference to the production listener for the deployment. + */ + readonly prodListener: elbv2.IApplicationListener | elbv2.INetworkListener; + + /** + * The reference to the test listener for the deployment. + * + * @default - No test listener will be used + */ + readonly testListener?: elbv2.IApplicationListener | elbv2.INetworkListener; + + /** + * The target group for the blue task set. + */ + readonly blueTargetGroup: elbv2.ITargetGroup; + + /** + * The target group for the green task set. + */ + readonly greenTargetGroup: elbv2.ITargetGroup; + + /** + * The time to wait for a ContinueDeployment after the deployment is ready. + * + * @default 0 - automatically continue once the deployment is ready. + */ + readonly waitTimeForContinueDeployment?: cdk.Duration; + + /** + * The time to wait before terminating old tasks. + * + * @default 0 - terminate immediately + */ + readonly waitTimeForTermination?: cdk.Duration; +} + +function renderBlueGreenDeploymentConfiguration( + blueGreenDeploymentConfig: EcsBlueGreenDeploymentConfig, +): CfnDeploymentGroup.BlueGreenDeploymentConfigurationProperty { + let deploymentReadyOption: CfnDeploymentGroup.DeploymentReadyOptionProperty; + if (blueGreenDeploymentConfig.waitTimeForContinueDeployment) { + deploymentReadyOption = { + actionOnTimeout: 'STOP_DEPLOYMENT', + waitTimeInMinutes: blueGreenDeploymentConfig.waitTimeForContinueDeployment.toMinutes(), + }; + } else { + deploymentReadyOption = { + actionOnTimeout: 'CONTINUE_DEPLOYMENT', + }; + } + let terminateBlueInstancesOnDeploymentSuccess = { + action: 'TERMINATE', + terminationWaitTimeInMinutes: blueGreenDeploymentConfig.waitTimeForTermination ? + blueGreenDeploymentConfig.waitTimeForTermination.toMinutes() : 0, + }; + return { + deploymentReadyOption, + terminateBlueInstancesOnDeploymentSuccess, + }; +} + +function renderLoadBalancerInfo( + blueGreenDeploymentConfig: EcsBlueGreenDeploymentConfig, +): CfnDeploymentGroup.LoadBalancerInfoProperty { + const targetGroupPairInfo: CfnDeploymentGroup.TargetGroupPairInfoProperty = { + targetGroups: [{ + name: blueGreenDeploymentConfig.blueTargetGroup.targetGroupName, + }, { + name: blueGreenDeploymentConfig.greenTargetGroup.targetGroupName, + }], + prodTrafficRoute: { + listenerArns: [blueGreenDeploymentConfig.prodListener.listenerArn], + }, + testTrafficRoute: blueGreenDeploymentConfig.testListener? { + listenerArns: [blueGreenDeploymentConfig.testListener.listenerArn], + } : undefined, + }; + return { + targetGroupPairInfoList: [targetGroupPairInfo], + }; +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/lib/index.ts b/packages/@aws-cdk/aws-codedeploy/lib/index.ts index 147f27580b874..8c9e8fa9f70d9 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/index.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/index.ts @@ -1,4 +1,5 @@ export * from './rollback-config'; +export * from './traffic-routing-config'; export * from './ecs'; export * from './lambda'; export * from './server'; diff --git a/packages/@aws-cdk/aws-codedeploy/lib/traffic-routing-config.ts b/packages/@aws-cdk/aws-codedeploy/lib/traffic-routing-config.ts new file mode 100644 index 0000000000000..a100675215338 --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/lib/traffic-routing-config.ts @@ -0,0 +1,91 @@ +import { CfnDeploymentConfig } from './codedeploy.generated'; + +/** + * Interface for traffic routing configs. + */ +export interface ITrafficRoutingConfig { + /** + * Abstract method on interface for subclasses to implement to render themselves as a TrafficRoutingConfigProperty. + */ + renderTrafficRoutingConfig(): CfnDeploymentConfig.TrafficRoutingConfigProperty +} + +/** + * Define a traffic routing config of type 'AllAtOnce'. + */ +export class AllAtOnceTrafficRoutingConfig implements ITrafficRoutingConfig { + constructor() {} + + /** + * Render a TrafficRoutingConfigProperty of type `AllAtOnce`. + */ + renderTrafficRoutingConfig(): CfnDeploymentConfig.TrafficRoutingConfigProperty { + return { + type: 'AllAtOnce', + }; + } +} + +/** + * Define a traffic routing config of type 'TimeBasedCanary'. + */ +export class TimeBasedCanaryTrafficRoutingConfig implements ITrafficRoutingConfig { + /** + * The amount of time between additional traffic shifts. + */ + readonly interval: number; + /** + * The percentage to increase traffic on each traffic shift. + */ + readonly percentage: number; + + constructor(interval: number, percentage: number) { + this.interval = interval; + this.percentage = percentage; + } + + /** + * Render a TrafficRoutingConfigProperty of type `TimeBasedCanary`. + */ + renderTrafficRoutingConfig(): CfnDeploymentConfig.TrafficRoutingConfigProperty { + return { + type: 'TimeBasedCanary', + timeBasedCanary: { + canaryInterval: this.interval, + canaryPercentage: this.percentage, + }, + }; + } +} + +/** + * Define a traffic routing config of type 'TimeBasedLinear'. + */ +export class TimeBasedLinearTrafficRoutingConfig implements ITrafficRoutingConfig { + /** + * The amount of time between additional traffic shifts. + */ + readonly interval: number; + /** + * The percentage to increase traffic on each traffic shift. + */ + readonly percentage: number; + + constructor(interval: number, percentage: number) { + this.interval = interval; + this.percentage = percentage; + } + + /** + * Render a TrafficRoutingConfigProperty of type `TimeBasedLinear`. + */ + renderTrafficRoutingConfig(): CfnDeploymentConfig.TrafficRoutingConfigProperty { + return { + type: 'TimeBasedLinear', + timeBasedLinear: { + linearInterval: this.interval, + linearPercentage: this.percentage, + }, + }; + } +} diff --git a/packages/@aws-cdk/aws-codedeploy/package.json b/packages/@aws-cdk/aws-codedeploy/package.json index 9077c1ba954d2..71a967efcf868 100644 --- a/packages/@aws-cdk/aws-codedeploy/package.json +++ b/packages/@aws-cdk/aws-codedeploy/package.json @@ -86,6 +86,7 @@ "@aws-cdk/assertions": "0.0.0", "@aws-cdk/cdk-build-tools": "0.0.0", "@aws-cdk/integ-runner": "0.0.0", + "@aws-cdk/integ-tests": "0.0.0", "@aws-cdk/cfn2ts": "0.0.0", "@aws-cdk/pkglint": "0.0.0", "@types/jest": "^27.5.2", @@ -95,6 +96,7 @@ "@aws-cdk/aws-autoscaling": "0.0.0", "@aws-cdk/aws-cloudwatch": "0.0.0", "@aws-cdk/aws-ec2": "0.0.0", + "@aws-cdk/aws-ecs": "0.0.0", "@aws-cdk/aws-elasticloadbalancing": "0.0.0", "@aws-cdk/aws-elasticloadbalancingv2": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", @@ -109,6 +111,7 @@ "@aws-cdk/aws-autoscaling": "0.0.0", "@aws-cdk/aws-cloudwatch": "0.0.0", "@aws-cdk/aws-ec2": "0.0.0", + "@aws-cdk/aws-ecs": "0.0.0", "@aws-cdk/aws-elasticloadbalancing": "0.0.0", "@aws-cdk/aws-elasticloadbalancingv2": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", @@ -171,9 +174,17 @@ "docs-public-apis:@aws-cdk/aws-codedeploy.IServerDeploymentGroup.deploymentGroupName", "docs-public-apis:@aws-cdk/aws-codedeploy.EcsApplication.applicationArn", "docs-public-apis:@aws-cdk/aws-codedeploy.EcsApplication.applicationName", + "docs-public-apis:@aws-cdk/aws-codedeploy.EcsDeploymentConfig.deploymentConfigName", + "docs-public-apis:@aws-cdk/aws-codedeploy.EcsDeploymentConfig.deploymentConfigArn", "docs-public-apis:@aws-cdk/aws-codedeploy.EcsDeploymentConfig.ALL_AT_ONCE", + "docs-public-apis:@aws-cdk/aws-codedeploy.EcsDeploymentConfig.CANARY_10_PERCENT_15_MINUTES", + "docs-public-apis:@aws-cdk/aws-codedeploy.EcsDeploymentConfig.CANARY_10_PERCENT_5_MINUTES", + "docs-public-apis:@aws-cdk/aws-codedeploy.EcsDeploymentConfig.LINEAR_10_PERCENT_1_MINUTES", + "docs-public-apis:@aws-cdk/aws-codedeploy.EcsDeploymentConfig.LINEAR_10_PERCENT_3_MINUTES", "docs-public-apis:@aws-cdk/aws-codedeploy.IEcsApplication.applicationArn", "docs-public-apis:@aws-cdk/aws-codedeploy.IEcsApplication.applicationName", + "construct-interface-extends-iconstruct:@aws-cdk/aws-codedeploy.IEcsDeploymentConfig", + "resource-interface-extends-resource:@aws-cdk/aws-codedeploy.IEcsDeploymentConfig", "docs-public-apis:@aws-cdk/aws-codedeploy.IEcsDeploymentConfig.deploymentConfigArn", "docs-public-apis:@aws-cdk/aws-codedeploy.IEcsDeploymentConfig.deploymentConfigName", "props-physical-name:@aws-cdk/aws-codedeploy.CustomLambdaDeploymentConfigProps" diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/application.test.ts b/packages/@aws-cdk/aws-codedeploy/test/ecs/application.test.ts index a5661c3538f14..a525e742f9d83 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/ecs/application.test.ts +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/application.test.ts @@ -24,6 +24,15 @@ describe('CodeDeploy ECS Application', () => { }); }); + test('can be imported', () => { + const stack = new cdk.Stack(); + + const application = codedeploy.EcsApplication.fromEcsApplicationName(stack, 'MyApp', 'MyApp'); + + expect(application).not.toEqual(undefined); + expect(application.applicationName).toEqual('MyApp'); + }); + test('fail with more than 100 characters in name', () => { const app = new cdk.App(); const stack = new cdk.Stack(app); diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-config.test.ts b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-config.test.ts new file mode 100644 index 0000000000000..0f92b9f2373a1 --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-config.test.ts @@ -0,0 +1,117 @@ +import { Template } from '@aws-cdk/assertions'; +import * as cdk from '@aws-cdk/core'; +import * as codedeploy from '../../lib'; +import { AllAtOnceTrafficRoutingConfig, TimeBasedCanaryTrafficRoutingConfig, TimeBasedLinearTrafficRoutingConfig } from '../../lib'; + +/* eslint-disable quote-props */ + +describe('CodeDeploy DeploymentConfig', () => { + test('can be created without props', () => { + const stack = new cdk.Stack(); + + new codedeploy.EcsDeploymentConfig(stack, 'DeploymentConfig', { + trafficRoutingConfig: new AllAtOnceTrafficRoutingConfig(), + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentConfig', { + 'ComputePlatform': 'ECS', + }); + }); + + test('can be created with a name', () => { + const stack = new cdk.Stack(); + + new codedeploy.EcsDeploymentConfig(stack, 'DeploymentConfig', { + deploymentConfigName: 'AAA', + trafficRoutingConfig: new AllAtOnceTrafficRoutingConfig(), + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentConfig', { + 'ComputePlatform': 'ECS', + 'DeploymentConfigName': 'AAA', + }); + }); + + test('can be created by specifying AllAtOnce', () => { + const stack = new cdk.Stack(); + + new codedeploy.EcsDeploymentConfig(stack, 'DeploymentConfig', { + trafficRoutingConfig: new AllAtOnceTrafficRoutingConfig(), + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentConfig', { + 'ComputePlatform': 'ECS', + 'TrafficRoutingConfig': { + 'Type': 'AllAtOnce', + }, + }); + }); + + test('can be created by specifying TimeBasedCanary', () => { + const stack = new cdk.Stack(); + + new codedeploy.EcsDeploymentConfig(stack, 'DeploymentConfig', { + trafficRoutingConfig: new TimeBasedCanaryTrafficRoutingConfig(2, 20), + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentConfig', { + 'ComputePlatform': 'ECS', + 'TrafficRoutingConfig': { + 'Type': 'TimeBasedCanary', + 'TimeBasedCanary': { + 'CanaryInterval': 2, + 'CanaryPercentage': 20, + }, + }, + }); + }); + + test('can be created by specifying TimeBasedLinear', () => { + const stack = new cdk.Stack(); + + new codedeploy.EcsDeploymentConfig(stack, 'DeploymentConfig', { + trafficRoutingConfig: new TimeBasedLinearTrafficRoutingConfig(2, 20), + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentConfig', { + 'ComputePlatform': 'ECS', + 'TrafficRoutingConfig': { + 'Type': 'TimeBasedLinear', + 'TimeBasedLinear': { + 'LinearInterval': 2, + 'LinearPercentage': 20, + }, + }, + }); + }); + + test('can be imported', () => { + const stack = new cdk.Stack(); + + const deploymentConfig = codedeploy.EcsDeploymentConfig.fromEcsDeploymentConfigName(stack, 'MyDC', 'MyDC'); + + expect(deploymentConfig).not.toEqual(undefined); + }); + + test('fail with more than 100 characters in name', () => { + const app = new cdk.App(); + const stack = new cdk.Stack(app); + new codedeploy.EcsDeploymentConfig(stack, 'DeploymentConfig', { + deploymentConfigName: 'a'.repeat(101), + trafficRoutingConfig: new AllAtOnceTrafficRoutingConfig(), + }); + + expect(() => app.synth()).toThrow(`Deployment config name: "${'a'.repeat(101)}" can be a max of 100 characters.`); + }); + + test('fail with unallowed characters in name', () => { + const app = new cdk.App(); + const stack = new cdk.Stack(app); + new codedeploy.EcsDeploymentConfig(stack, 'DeploymentConfig', { + deploymentConfigName: 'my name', + trafficRoutingConfig: new AllAtOnceTrafficRoutingConfig(), + }); + + expect(() => app.synth()).toThrow('Deployment config name: "my name" can only contain letters (a-z, A-Z), numbers (0-9), periods (.), underscores (_), + (plus signs), = (equals signs), , (commas), @ (at signs), - (minus signs).'); + }); +}); diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/EcsTestDefaultTestDeployAssert8B2741C4.assets.json b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/EcsTestDefaultTestDeployAssert8B2741C4.assets.json new file mode 100644 index 0000000000000..3f1f9a15a2698 --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/EcsTestDefaultTestDeployAssert8B2741C4.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "EcsTestDefaultTestDeployAssert8B2741C4.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/EcsTestDefaultTestDeployAssert8B2741C4.template.json b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/EcsTestDefaultTestDeployAssert8B2741C4.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/EcsTestDefaultTestDeployAssert8B2741C4.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/aws-cdk-codedeploy-ecs-dg.assets.json b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/aws-cdk-codedeploy-ecs-dg.assets.json new file mode 100644 index 0000000000000..86b606159833b --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/aws-cdk-codedeploy-ecs-dg.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "6fc64dbac5f1d7b309630619bfc02b3cb7cdcc232e7f9270016f783d2ebb5d5b": { + "source": { + "path": "aws-cdk-codedeploy-ecs-dg.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "6fc64dbac5f1d7b309630619bfc02b3cb7cdcc232e7f9270016f783d2ebb5d5b.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/aws-cdk-codedeploy-ecs-dg.template.json b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/aws-cdk-codedeploy-ecs-dg.template.json new file mode 100644 index 0000000000000..5f379e28aa154 --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/aws-cdk-codedeploy-ecs-dg.template.json @@ -0,0 +1,943 @@ +{ + "Resources": { + "VPCB9E5F0B4": { + "Type": "AWS::EC2::VPC", + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC" + } + ] + } + }, + "VPCPublicSubnet1SubnetB4246D30": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.0.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1" + } + ] + } + }, + "VPCPublicSubnet1RouteTableFEE4B781": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1" + } + ] + } + }, + "VPCPublicSubnet1RouteTableAssociation0B0896DC": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" + }, + "SubnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + } + } + }, + "VPCPublicSubnet1DefaultRoute91CEF279": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VPCIGWB7E252D3" + } + }, + "DependsOn": [ + "VPCVPCGW99B986DC" + ] + }, + "VPCPublicSubnet1EIP6AD938E8": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1" + } + ] + } + }, + "VPCPublicSubnet1NATGatewayE0556630": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "SubnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + }, + "AllocationId": { + "Fn::GetAtt": [ + "VPCPublicSubnet1EIP6AD938E8", + "AllocationId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1" + } + ] + }, + "DependsOn": [ + "VPCPublicSubnet1DefaultRoute91CEF279", + "VPCPublicSubnet1RouteTableAssociation0B0896DC" + ] + }, + "VPCPublicSubnet2Subnet74179F39": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.64.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2" + } + ] + } + }, + "VPCPublicSubnet2RouteTable6F1A15F1": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2" + } + ] + } + }, + "VPCPublicSubnet2RouteTableAssociation5A808732": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" + }, + "SubnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + } + } + }, + "VPCPublicSubnet2DefaultRouteB7481BBA": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VPCIGWB7E252D3" + } + }, + "DependsOn": [ + "VPCVPCGW99B986DC" + ] + }, + "VPCPublicSubnet2EIP4947BC00": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2" + } + ] + } + }, + "VPCPublicSubnet2NATGateway3C070193": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "SubnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + }, + "AllocationId": { + "Fn::GetAtt": [ + "VPCPublicSubnet2EIP4947BC00", + "AllocationId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2" + } + ] + }, + "DependsOn": [ + "VPCPublicSubnet2DefaultRouteB7481BBA", + "VPCPublicSubnet2RouteTableAssociation5A808732" + ] + }, + "VPCPrivateSubnet1Subnet8BCA10E0": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.128.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1" + } + ] + } + }, + "VPCPrivateSubnet1RouteTableBE8A6027": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1" + } + ] + } + }, + "VPCPrivateSubnet1RouteTableAssociation347902D1": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" + }, + "SubnetId": { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + } + } + }, + "VPCPrivateSubnet1DefaultRouteAE1D6490": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VPCPublicSubnet1NATGatewayE0556630" + } + } + }, + "VPCPrivateSubnet2SubnetCFCDAA7A": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.192.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2" + } + ] + } + }, + "VPCPrivateSubnet2RouteTable0A19E10E": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2" + } + ] + } + }, + "VPCPrivateSubnet2RouteTableAssociation0C73D413": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" + }, + "SubnetId": { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + } + }, + "VPCPrivateSubnet2DefaultRouteF4F5CFD2": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VPCPublicSubnet2NATGateway3C070193" + } + } + }, + "VPCIGWB7E252D3": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-codedeploy-ecs-dg/VPC" + } + ] + } + }, + "VPCVPCGW99B986DC": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "InternetGatewayId": { + "Ref": "VPCIGWB7E252D3" + } + } + }, + "MyCluster4C1BA579": { + "Type": "AWS::ECS::Cluster" + }, + "MyTaskDefTaskRole727F9D3B": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "MyTaskDef01F0D39B": { + "Type": "AWS::ECS::TaskDefinition", + "Properties": { + "ContainerDefinitions": [ + { + "Essential": true, + "Image": "nginx@sha256:79c77eb7ca32f9a117ef91bc6ac486014e0d0e75f2f06683ba24dc298f9f4dd4", + "Name": "MyContainer", + "PortMappings": [ + { + "ContainerPort": 80, + "Protocol": "tcp" + } + ] + } + ], + "Cpu": "256", + "Family": "nginx", + "Memory": "512", + "NetworkMode": "awsvpc", + "RequiresCompatibilities": [ + "FARGATE" + ], + "TaskRoleArn": { + "Fn::GetAtt": [ + "MyTaskDefTaskRole727F9D3B", + "Arn" + ] + } + } + }, + "MyServiceB4132EDA": { + "Type": "AWS::ECS::Service", + "Properties": { + "Cluster": { + "Ref": "MyCluster4C1BA579" + }, + "DeploymentConfiguration": { + "MaximumPercent": 200, + "MinimumHealthyPercent": 50 + }, + "DeploymentController": { + "Type": "CODE_DEPLOY" + }, + "EnableECSManagedTags": false, + "HealthCheckGracePeriodSeconds": 60, + "LaunchType": "FARGATE", + "LoadBalancers": [ + { + "ContainerName": "MyContainer", + "ContainerPort": 80, + "TargetGroupArn": { + "Ref": "BlueTargetGroupF108EB01" + } + } + ], + "NetworkConfiguration": { + "AwsvpcConfiguration": { + "AssignPublicIp": "DISABLED", + "SecurityGroups": [ + { + "Fn::GetAtt": [ + "MyServiceSecurityGroup6281A313", + "GroupId" + ] + } + ], + "Subnets": [ + { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + }, + { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + ] + } + }, + "TaskDefinition": "nginx" + }, + "DependsOn": [ + "ALBListener3B99FF85", + "MyTaskDef01F0D39B", + "MyTaskDefTaskRole727F9D3B" + ] + }, + "MyServiceSecurityGroup6281A313": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "aws-cdk-codedeploy-ecs-dg/MyService/SecurityGroup", + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + }, + "DependsOn": [ + "MyTaskDef01F0D39B", + "MyTaskDefTaskRole727F9D3B" + ] + }, + "MyServiceSecurityGroupfromawscdkcodedeployecsdgALBSecurityGroup48D554A080C46A885A": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Properties": { + "IpProtocol": "tcp", + "Description": "Load balancer to target", + "FromPort": 80, + "GroupId": { + "Fn::GetAtt": [ + "MyServiceSecurityGroup6281A313", + "GroupId" + ] + }, + "SourceSecurityGroupId": { + "Fn::GetAtt": [ + "ALBSecurityGroup8B8624F8", + "GroupId" + ] + }, + "ToPort": 80 + }, + "DependsOn": [ + "MyTaskDef01F0D39B", + "MyTaskDefTaskRole727F9D3B" + ] + }, + "BlueTargetGroupF108EB01": { + "Type": "AWS::ElasticLoadBalancingV2::TargetGroup", + "Properties": { + "Port": 80, + "Protocol": "HTTP", + "TargetGroupAttributes": [ + { + "Key": "stickiness.enabled", + "Value": "false" + } + ], + "TargetType": "ip", + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "GreenTargetGroupEEB2DF3E": { + "Type": "AWS::ElasticLoadBalancingV2::TargetGroup", + "Properties": { + "Port": 80, + "Protocol": "HTTP", + "TargetGroupAttributes": [ + { + "Key": "stickiness.enabled", + "Value": "false" + } + ], + "TargetType": "ip", + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "ALBAEE750D2": { + "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer", + "Properties": { + "LoadBalancerAttributes": [ + { + "Key": "deletion_protection.enabled", + "Value": "false" + } + ], + "Scheme": "internal", + "SecurityGroups": [ + { + "Fn::GetAtt": [ + "ALBSecurityGroup8B8624F8", + "GroupId" + ] + } + ], + "Subnets": [ + { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + }, + { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + ], + "Type": "application" + } + }, + "ALBSecurityGroup8B8624F8": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Automatically created Security Group for ELB awscdkcodedeployecsdgALBEA16F3F1", + "SecurityGroupIngress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow from anyone on port 80", + "FromPort": 80, + "IpProtocol": "tcp", + "ToPort": 80 + } + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "ALBSecurityGrouptoawscdkcodedeployecsdgMyServiceSecurityGroupEE2386E380F23C2EA5": { + "Type": "AWS::EC2::SecurityGroupEgress", + "Properties": { + "GroupId": { + "Fn::GetAtt": [ + "ALBSecurityGroup8B8624F8", + "GroupId" + ] + }, + "IpProtocol": "tcp", + "Description": "Load balancer to target", + "DestinationSecurityGroupId": { + "Fn::GetAtt": [ + "MyServiceSecurityGroup6281A313", + "GroupId" + ] + }, + "FromPort": 80, + "ToPort": 80 + } + }, + "ALBListener3B99FF85": { + "Type": "AWS::ElasticLoadBalancingV2::Listener", + "Properties": { + "DefaultActions": [ + { + "TargetGroupArn": { + "Ref": "BlueTargetGroupF108EB01" + }, + "Type": "forward" + } + ], + "LoadBalancerArn": { + "Ref": "ALBAEE750D2" + }, + "Port": 80, + "Protocol": "HTTP" + } + }, + "Alarm1F9009D71": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "EvaluationPeriods": 2, + "Dimensions": [ + { + "Name": "LoadBalancer", + "Value": { + "Fn::GetAtt": [ + "ALBAEE750D2", + "LoadBalancerFullName" + ] + } + } + ], + "MetricName": "TargetResponseTime", + "Namespace": "AWS/ApplicationELB", + "Period": 300, + "Statistic": "Average", + "Threshold": 3 + } + }, + "CodeDeployGroupApplication13EFBDA6": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "ECS" + } + }, + "CodeDeployGroupServiceRole50553EBF": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::FindInMap": [ + "ServiceprincipalMap", + { + "Ref": "AWS::Region" + }, + "codedeploy" + ] + } + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/AWSCodeDeployRoleForECSLimited" + ] + ] + } + ] + } + }, + "CodeDeployGroup58220FC8": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "CodeDeployGroupApplication13EFBDA6" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployGroupServiceRole50553EBF", + "Arn" + ] + }, + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "Alarm1F9009D71" + } + } + ], + "Enabled": true + }, + "BlueGreenDeploymentConfiguration": { + "DeploymentReadyOption": { + "ActionOnTimeout": "CONTINUE_DEPLOYMENT" + }, + "TerminateBlueInstancesOnDeploymentSuccess": { + "Action": "TERMINATE", + "TerminationWaitTimeInMinutes": 0 + } + }, + "DeploymentConfigName": "CodeDeployDefault.ECSCanary10Percent5Minutes", + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ECSServices": [ + { + "ClusterName": { + "Ref": "MyCluster4C1BA579" + }, + "ServiceName": { + "Fn::GetAtt": [ + "MyServiceB4132EDA", + "Name" + ] + } + } + ], + "LoadBalancerInfo": { + "TargetGroupPairInfoList": [ + { + "ProdTrafficRoute": { + "ListenerArns": [ + { + "Ref": "ALBListener3B99FF85" + } + ] + }, + "TargetGroups": [ + { + "Name": { + "Fn::GetAtt": [ + "BlueTargetGroupF108EB01", + "TargetGroupName" + ] + } + }, + { + "Name": { + "Fn::GetAtt": [ + "GreenTargetGroupEEB2DF3E", + "TargetGroupName" + ] + } + } + ] + } + ] + } + } + } + }, + "Mappings": { + "ServiceprincipalMap": { + "af-south-1": { + "codedeploy": "codedeploy.af-south-1.amazonaws.com" + }, + "ap-east-1": { + "codedeploy": "codedeploy.ap-east-1.amazonaws.com" + }, + "ap-northeast-1": { + "codedeploy": "codedeploy.ap-northeast-1.amazonaws.com" + }, + "ap-northeast-2": { + "codedeploy": "codedeploy.ap-northeast-2.amazonaws.com" + }, + "ap-northeast-3": { + "codedeploy": "codedeploy.ap-northeast-3.amazonaws.com" + }, + "ap-south-1": { + "codedeploy": "codedeploy.ap-south-1.amazonaws.com" + }, + "ap-southeast-1": { + "codedeploy": "codedeploy.ap-southeast-1.amazonaws.com" + }, + "ap-southeast-2": { + "codedeploy": "codedeploy.ap-southeast-2.amazonaws.com" + }, + "ap-southeast-3": { + "codedeploy": "codedeploy.ap-southeast-3.amazonaws.com" + }, + "ca-central-1": { + "codedeploy": "codedeploy.ca-central-1.amazonaws.com" + }, + "cn-north-1": { + "codedeploy": "codedeploy.cn-north-1.amazonaws.com.cn" + }, + "cn-northwest-1": { + "codedeploy": "codedeploy.cn-northwest-1.amazonaws.com.cn" + }, + "eu-central-1": { + "codedeploy": "codedeploy.eu-central-1.amazonaws.com" + }, + "eu-north-1": { + "codedeploy": "codedeploy.eu-north-1.amazonaws.com" + }, + "eu-south-1": { + "codedeploy": "codedeploy.eu-south-1.amazonaws.com" + }, + "eu-south-2": { + "codedeploy": "codedeploy.eu-south-2.amazonaws.com" + }, + "eu-west-1": { + "codedeploy": "codedeploy.eu-west-1.amazonaws.com" + }, + "eu-west-2": { + "codedeploy": "codedeploy.eu-west-2.amazonaws.com" + }, + "eu-west-3": { + "codedeploy": "codedeploy.eu-west-3.amazonaws.com" + }, + "me-south-1": { + "codedeploy": "codedeploy.me-south-1.amazonaws.com" + }, + "sa-east-1": { + "codedeploy": "codedeploy.sa-east-1.amazonaws.com" + }, + "us-east-1": { + "codedeploy": "codedeploy.us-east-1.amazonaws.com" + }, + "us-east-2": { + "codedeploy": "codedeploy.us-east-2.amazonaws.com" + }, + "us-gov-east-1": { + "codedeploy": "codedeploy.us-gov-east-1.amazonaws.com" + }, + "us-gov-west-1": { + "codedeploy": "codedeploy.us-gov-west-1.amazonaws.com" + }, + "us-iso-east-1": { + "codedeploy": "codedeploy.amazonaws.com" + }, + "us-iso-west-1": { + "codedeploy": "codedeploy.amazonaws.com" + }, + "us-isob-east-1": { + "codedeploy": "codedeploy.amazonaws.com" + }, + "us-west-1": { + "codedeploy": "codedeploy.us-west-1.amazonaws.com" + }, + "us-west-2": { + "codedeploy": "codedeploy.us-west-2.amazonaws.com" + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/cdk.out b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/cdk.out new file mode 100644 index 0000000000000..8ecc185e9dbee --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/integ.json b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/integ.json new file mode 100644 index 0000000000000..d3aa87d172676 --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "21.0.0", + "testCases": { + "EcsTest/DefaultTest": { + "stacks": [ + "aws-cdk-codedeploy-ecs-dg" + ], + "assertionStack": "EcsTest/DefaultTest/DeployAssert", + "assertionStackName": "EcsTestDefaultTestDeployAssert8B2741C4" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/manifest.json new file mode 100644 index 0000000000000..4049e031e9635 --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/manifest.json @@ -0,0 +1,345 @@ +{ + "version": "21.0.0", + "artifacts": { + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + }, + "aws-cdk-codedeploy-ecs-dg.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "aws-cdk-codedeploy-ecs-dg.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "aws-cdk-codedeploy-ecs-dg": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "aws-cdk-codedeploy-ecs-dg.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/6fc64dbac5f1d7b309630619bfc02b3cb7cdcc232e7f9270016f783d2ebb5d5b.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "aws-cdk-codedeploy-ecs-dg.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "aws-cdk-codedeploy-ecs-dg.assets" + ], + "metadata": { + "/aws-cdk-codedeploy-ecs-dg/VPC/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCB9E5F0B4" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1SubnetB4246D30" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1RouteTableFEE4B781" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1RouteTableAssociation0B0896DC" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1DefaultRoute91CEF279" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1EIP6AD938E8" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1NATGatewayE0556630" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2Subnet74179F39" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2RouteTable6F1A15F1" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2RouteTableAssociation5A808732" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2DefaultRouteB7481BBA" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2EIP4947BC00" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2NATGateway3C070193" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet1Subnet8BCA10E0" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet1RouteTableBE8A6027" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet1RouteTableAssociation347902D1" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet1DefaultRouteAE1D6490" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet2RouteTable0A19E10E" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet2RouteTableAssociation0C73D413" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet2DefaultRouteF4F5CFD2" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/IGW": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCIGWB7E252D3" + } + ], + "/aws-cdk-codedeploy-ecs-dg/VPC/VPCGW": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCVPCGW99B986DC" + } + ], + "/aws-cdk-codedeploy-ecs-dg/MyCluster/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyCluster4C1BA579" + } + ], + "/aws-cdk-codedeploy-ecs-dg/MyTaskDef/TaskRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyTaskDefTaskRole727F9D3B" + } + ], + "/aws-cdk-codedeploy-ecs-dg/MyTaskDef/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyTaskDef01F0D39B" + } + ], + "/aws-cdk-codedeploy-ecs-dg/MyService/Service": [ + { + "type": "aws:cdk:logicalId", + "data": "MyServiceB4132EDA" + } + ], + "/aws-cdk-codedeploy-ecs-dg/MyService/SecurityGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyServiceSecurityGroup6281A313" + } + ], + "/aws-cdk-codedeploy-ecs-dg/MyService/SecurityGroup/from awscdkcodedeployecsdgALBSecurityGroup48D554A0:80": [ + { + "type": "aws:cdk:logicalId", + "data": "MyServiceSecurityGroupfromawscdkcodedeployecsdgALBSecurityGroup48D554A080C46A885A" + } + ], + "/aws-cdk-codedeploy-ecs-dg/BlueTargetGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "BlueTargetGroupF108EB01" + } + ], + "/aws-cdk-codedeploy-ecs-dg/GreenTargetGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "GreenTargetGroupEEB2DF3E" + } + ], + "/aws-cdk-codedeploy-ecs-dg/ALB/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ALBAEE750D2" + } + ], + "/aws-cdk-codedeploy-ecs-dg/ALB/SecurityGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ALBSecurityGroup8B8624F8" + } + ], + "/aws-cdk-codedeploy-ecs-dg/ALB/SecurityGroup/to awscdkcodedeployecsdgMyServiceSecurityGroupEE2386E3:80": [ + { + "type": "aws:cdk:logicalId", + "data": "ALBSecurityGrouptoawscdkcodedeployecsdgMyServiceSecurityGroupEE2386E380F23C2EA5" + } + ], + "/aws-cdk-codedeploy-ecs-dg/ALB/Listener/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ALBListener3B99FF85" + } + ], + "/aws-cdk-codedeploy-ecs-dg/Alarm1/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Alarm1F9009D71" + } + ], + "/aws-cdk-codedeploy-ecs-dg/CodeDeployGroup/Application/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CodeDeployGroupApplication13EFBDA6" + } + ], + "/aws-cdk-codedeploy-ecs-dg/CodeDeployGroup/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CodeDeployGroupServiceRole50553EBF" + } + ], + "/aws-cdk-codedeploy-ecs-dg/CodeDeployGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CodeDeployGroup58220FC8" + } + ], + "/aws-cdk-codedeploy-ecs-dg/Service-principalMap": [ + { + "type": "aws:cdk:logicalId", + "data": "ServiceprincipalMap" + } + ], + "/aws-cdk-codedeploy-ecs-dg/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/aws-cdk-codedeploy-ecs-dg/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "aws-cdk-codedeploy-ecs-dg" + }, + "EcsTestDefaultTestDeployAssert8B2741C4.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "EcsTestDefaultTestDeployAssert8B2741C4.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "EcsTestDefaultTestDeployAssert8B2741C4": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "EcsTestDefaultTestDeployAssert8B2741C4.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "EcsTestDefaultTestDeployAssert8B2741C4.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "EcsTestDefaultTestDeployAssert8B2741C4.assets" + ], + "metadata": { + "/EcsTest/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/EcsTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "EcsTest/DefaultTest/DeployAssert" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/tree.json b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/tree.json new file mode 100644 index 0000000000000..c5593739fe2a8 --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.integ.snapshot/tree.json @@ -0,0 +1,1402 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.95" + } + }, + "aws-cdk-codedeploy-ecs-dg": { + "id": "aws-cdk-codedeploy-ecs-dg", + "path": "aws-cdk-codedeploy-ecs-dg", + "children": { + "VPC": { + "id": "VPC", + "path": "aws-cdk-codedeploy-ecs-dg/VPC", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPC", + "aws:cdk:cloudformation:props": { + "cidrBlock": "10.0.0.0/16", + "enableDnsHostnames": true, + "enableDnsSupport": true, + "instanceTenancy": "default", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnVPC", + "version": "0.0.0" + } + }, + "PublicSubnet1": { + "id": "PublicSubnet1", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "VPCB9E5F0B4" + }, + "availabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.0.0/18", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/Acl", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "VPCB9E5F0B4" + }, + "tags": [ + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" + }, + "subnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" + }, + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "VPCIGWB7E252D3" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "subnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + }, + "allocationId": { + "Fn::GetAtt": [ + "VPCPublicSubnet1EIP6AD938E8", + "AllocationId" + ] + }, + "tags": [ + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnNatGateway", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.PublicSubnet", + "version": "0.0.0" + } + }, + "PublicSubnet2": { + "id": "PublicSubnet2", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "VPCB9E5F0B4" + }, + "availabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.64.0/18", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/Acl", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "VPCB9E5F0B4" + }, + "tags": [ + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" + }, + "subnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" + }, + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "VPCIGWB7E252D3" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "subnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + }, + "allocationId": { + "Fn::GetAtt": [ + "VPCPublicSubnet2EIP4947BC00", + "AllocationId" + ] + }, + "tags": [ + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnNatGateway", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.PublicSubnet", + "version": "0.0.0" + } + }, + "PrivateSubnet1": { + "id": "PrivateSubnet1", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "VPCB9E5F0B4" + }, + "availabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.128.0/18", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1/Acl", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "VPCB9E5F0B4" + }, + "tags": [ + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" + }, + "subnetId": { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" + }, + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "VPCPublicSubnet1NATGatewayE0556630" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.PrivateSubnet", + "version": "0.0.0" + } + }, + "PrivateSubnet2": { + "id": "PrivateSubnet2", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "VPCB9E5F0B4" + }, + "availabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.192.0/18", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2/Acl", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "VPCB9E5F0B4" + }, + "tags": [ + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" + }, + "subnetId": { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/PrivateSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" + }, + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "VPCPublicSubnet2NATGateway3C070193" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.PrivateSubnet", + "version": "0.0.0" + } + }, + "IGW": { + "id": "IGW", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/IGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::InternetGateway", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-cdk-codedeploy-ecs-dg/VPC" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnInternetGateway", + "version": "0.0.0" + } + }, + "VPCGW": { + "id": "VPCGW", + "path": "aws-cdk-codedeploy-ecs-dg/VPC/VPCGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPCGatewayAttachment", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "VPCB9E5F0B4" + }, + "internetGatewayId": { + "Ref": "VPCIGWB7E252D3" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnVPCGatewayAttachment", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.Vpc", + "version": "0.0.0" + } + }, + "MyCluster": { + "id": "MyCluster", + "path": "aws-cdk-codedeploy-ecs-dg/MyCluster", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/MyCluster/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECS::Cluster", + "aws:cdk:cloudformation:props": {} + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ecs.CfnCluster", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ecs.Cluster", + "version": "0.0.0" + } + }, + "MyTaskDef": { + "id": "MyTaskDef", + "path": "aws-cdk-codedeploy-ecs-dg/MyTaskDef", + "children": { + "TaskRole": { + "id": "TaskRole", + "path": "aws-cdk-codedeploy-ecs-dg/MyTaskDef/TaskRole", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/MyTaskDef/TaskRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/MyTaskDef/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECS::TaskDefinition", + "aws:cdk:cloudformation:props": { + "containerDefinitions": [ + { + "essential": true, + "image": "nginx@sha256:79c77eb7ca32f9a117ef91bc6ac486014e0d0e75f2f06683ba24dc298f9f4dd4", + "name": "MyContainer", + "portMappings": [ + { + "containerPort": 80, + "protocol": "tcp" + } + ] + } + ], + "cpu": "256", + "family": "nginx", + "memory": "512", + "networkMode": "awsvpc", + "requiresCompatibilities": [ + "FARGATE" + ], + "taskRoleArn": { + "Fn::GetAtt": [ + "MyTaskDefTaskRole727F9D3B", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ecs.CfnTaskDefinition", + "version": "0.0.0" + } + }, + "MyContainer": { + "id": "MyContainer", + "path": "aws-cdk-codedeploy-ecs-dg/MyTaskDef/MyContainer", + "constructInfo": { + "fqn": "@aws-cdk/aws-ecs.ContainerDefinition", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ecs.FargateTaskDefinition", + "version": "0.0.0" + } + }, + "MyService": { + "id": "MyService", + "path": "aws-cdk-codedeploy-ecs-dg/MyService", + "children": { + "Service": { + "id": "Service", + "path": "aws-cdk-codedeploy-ecs-dg/MyService/Service", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECS::Service", + "aws:cdk:cloudformation:props": { + "cluster": { + "Ref": "MyCluster4C1BA579" + }, + "deploymentConfiguration": { + "maximumPercent": 200, + "minimumHealthyPercent": 50 + }, + "deploymentController": { + "type": "CODE_DEPLOY" + }, + "enableEcsManagedTags": false, + "healthCheckGracePeriodSeconds": 60, + "launchType": "FARGATE", + "loadBalancers": [ + { + "targetGroupArn": { + "Ref": "BlueTargetGroupF108EB01" + }, + "containerName": "MyContainer", + "containerPort": 80 + } + ], + "networkConfiguration": { + "awsvpcConfiguration": { + "assignPublicIp": "DISABLED", + "subnets": [ + { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + }, + { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + ], + "securityGroups": [ + { + "Fn::GetAtt": [ + "MyServiceSecurityGroup6281A313", + "GroupId" + ] + } + ] + } + }, + "taskDefinition": "nginx" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ecs.CfnService", + "version": "0.0.0" + } + }, + "SecurityGroup": { + "id": "SecurityGroup", + "path": "aws-cdk-codedeploy-ecs-dg/MyService/SecurityGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/MyService/SecurityGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", + "aws:cdk:cloudformation:props": { + "groupDescription": "aws-cdk-codedeploy-ecs-dg/MyService/SecurityGroup", + "securityGroupEgress": [ + { + "cidrIp": "0.0.0.0/0", + "description": "Allow all outbound traffic by default", + "ipProtocol": "-1" + } + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSecurityGroup", + "version": "0.0.0" + } + }, + "from awscdkcodedeployecsdgALBSecurityGroup48D554A0:80": { + "id": "from awscdkcodedeployecsdgALBSecurityGroup48D554A0:80", + "path": "aws-cdk-codedeploy-ecs-dg/MyService/SecurityGroup/from awscdkcodedeployecsdgALBSecurityGroup48D554A0:80", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroupIngress", + "aws:cdk:cloudformation:props": { + "ipProtocol": "tcp", + "description": "Load balancer to target", + "fromPort": 80, + "groupId": { + "Fn::GetAtt": [ + "MyServiceSecurityGroup6281A313", + "GroupId" + ] + }, + "sourceSecurityGroupId": { + "Fn::GetAtt": [ + "ALBSecurityGroup8B8624F8", + "GroupId" + ] + }, + "toPort": 80 + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSecurityGroupIngress", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.SecurityGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ecs.FargateService", + "version": "0.0.0" + } + }, + "BlueTargetGroup": { + "id": "BlueTargetGroup", + "path": "aws-cdk-codedeploy-ecs-dg/BlueTargetGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/BlueTargetGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ElasticLoadBalancingV2::TargetGroup", + "aws:cdk:cloudformation:props": { + "port": 80, + "protocol": "HTTP", + "targetGroupAttributes": [ + { + "key": "stickiness.enabled", + "value": "false" + } + ], + "targetType": "ip", + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-elasticloadbalancingv2.CfnTargetGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-elasticloadbalancingv2.ApplicationTargetGroup", + "version": "0.0.0" + } + }, + "GreenTargetGroup": { + "id": "GreenTargetGroup", + "path": "aws-cdk-codedeploy-ecs-dg/GreenTargetGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/GreenTargetGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ElasticLoadBalancingV2::TargetGroup", + "aws:cdk:cloudformation:props": { + "port": 80, + "protocol": "HTTP", + "targetGroupAttributes": [ + { + "key": "stickiness.enabled", + "value": "false" + } + ], + "targetType": "ip", + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-elasticloadbalancingv2.CfnTargetGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-elasticloadbalancingv2.ApplicationTargetGroup", + "version": "0.0.0" + } + }, + "ALB": { + "id": "ALB", + "path": "aws-cdk-codedeploy-ecs-dg/ALB", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/ALB/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ElasticLoadBalancingV2::LoadBalancer", + "aws:cdk:cloudformation:props": { + "loadBalancerAttributes": [ + { + "key": "deletion_protection.enabled", + "value": "false" + } + ], + "scheme": "internal", + "securityGroups": [ + { + "Fn::GetAtt": [ + "ALBSecurityGroup8B8624F8", + "GroupId" + ] + } + ], + "subnets": [ + { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + }, + { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + ], + "type": "application" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-elasticloadbalancingv2.CfnLoadBalancer", + "version": "0.0.0" + } + }, + "SecurityGroup": { + "id": "SecurityGroup", + "path": "aws-cdk-codedeploy-ecs-dg/ALB/SecurityGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/ALB/SecurityGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", + "aws:cdk:cloudformation:props": { + "groupDescription": "Automatically created Security Group for ELB awscdkcodedeployecsdgALBEA16F3F1", + "securityGroupIngress": [ + { + "cidrIp": "0.0.0.0/0", + "ipProtocol": "tcp", + "fromPort": 80, + "toPort": 80, + "description": "Allow from anyone on port 80" + } + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSecurityGroup", + "version": "0.0.0" + } + }, + "to awscdkcodedeployecsdgMyServiceSecurityGroupEE2386E3:80": { + "id": "to awscdkcodedeployecsdgMyServiceSecurityGroupEE2386E3:80", + "path": "aws-cdk-codedeploy-ecs-dg/ALB/SecurityGroup/to awscdkcodedeployecsdgMyServiceSecurityGroupEE2386E3:80", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroupEgress", + "aws:cdk:cloudformation:props": { + "groupId": { + "Fn::GetAtt": [ + "ALBSecurityGroup8B8624F8", + "GroupId" + ] + }, + "ipProtocol": "tcp", + "description": "Load balancer to target", + "destinationSecurityGroupId": { + "Fn::GetAtt": [ + "MyServiceSecurityGroup6281A313", + "GroupId" + ] + }, + "fromPort": 80, + "toPort": 80 + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSecurityGroupEgress", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.SecurityGroup", + "version": "0.0.0" + } + }, + "Listener": { + "id": "Listener", + "path": "aws-cdk-codedeploy-ecs-dg/ALB/Listener", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/ALB/Listener/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ElasticLoadBalancingV2::Listener", + "aws:cdk:cloudformation:props": { + "defaultActions": [ + { + "type": "forward", + "targetGroupArn": { + "Ref": "BlueTargetGroupF108EB01" + } + } + ], + "loadBalancerArn": { + "Ref": "ALBAEE750D2" + }, + "port": 80, + "protocol": "HTTP" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-elasticloadbalancingv2.CfnListener", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-elasticloadbalancingv2.ApplicationListener", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-elasticloadbalancingv2.ApplicationLoadBalancer", + "version": "0.0.0" + } + }, + "Alarm1": { + "id": "Alarm1", + "path": "aws-cdk-codedeploy-ecs-dg/Alarm1", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/Alarm1/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudWatch::Alarm", + "aws:cdk:cloudformation:props": { + "comparisonOperator": "GreaterThanOrEqualToThreshold", + "evaluationPeriods": 2, + "dimensions": [ + { + "name": "LoadBalancer", + "value": { + "Fn::GetAtt": [ + "ALBAEE750D2", + "LoadBalancerFullName" + ] + } + } + ], + "metricName": "TargetResponseTime", + "namespace": "AWS/ApplicationELB", + "period": 300, + "statistic": "Average", + "threshold": 3 + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-cloudwatch.CfnAlarm", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-cloudwatch.Alarm", + "version": "0.0.0" + } + }, + "CodeDeployGroup": { + "id": "CodeDeployGroup", + "path": "aws-cdk-codedeploy-ecs-dg/CodeDeployGroup", + "children": { + "Application": { + "id": "Application", + "path": "aws-cdk-codedeploy-ecs-dg/CodeDeployGroup/Application", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/CodeDeployGroup/Application/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CodeDeploy::Application", + "aws:cdk:cloudformation:props": { + "computePlatform": "ECS" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-codedeploy.CfnApplication", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-codedeploy.EcsApplication", + "version": "0.0.0" + } + }, + "ServiceRole": { + "id": "ServiceRole", + "path": "aws-cdk-codedeploy-ecs-dg/CodeDeployGroup/ServiceRole", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/CodeDeployGroup/ServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::FindInMap": [ + "ServiceprincipalMap", + { + "Ref": "AWS::Region" + }, + "codedeploy" + ] + } + } + } + ], + "Version": "2012-10-17" + }, + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/AWSCodeDeployRoleForECSLimited" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-cdk-codedeploy-ecs-dg/CodeDeployGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CodeDeploy::DeploymentGroup", + "aws:cdk:cloudformation:props": { + "applicationName": { + "Ref": "CodeDeployGroupApplication13EFBDA6" + }, + "serviceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployGroupServiceRole50553EBF", + "Arn" + ] + }, + "alarmConfiguration": { + "alarms": [ + { + "name": { + "Ref": "Alarm1F9009D71" + } + } + ], + "enabled": true + }, + "blueGreenDeploymentConfiguration": { + "deploymentReadyOption": { + "actionOnTimeout": "CONTINUE_DEPLOYMENT" + }, + "terminateBlueInstancesOnDeploymentSuccess": { + "action": "TERMINATE", + "terminationWaitTimeInMinutes": 0 + } + }, + "deploymentConfigName": "CodeDeployDefault.ECSCanary10Percent5Minutes", + "deploymentStyle": { + "deploymentType": "BLUE_GREEN", + "deploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ecsServices": [ + { + "clusterName": { + "Ref": "MyCluster4C1BA579" + }, + "serviceName": { + "Fn::GetAtt": [ + "MyServiceB4132EDA", + "Name" + ] + } + } + ], + "loadBalancerInfo": { + "targetGroupPairInfoList": [ + { + "targetGroups": [ + { + "name": { + "Fn::GetAtt": [ + "BlueTargetGroupF108EB01", + "TargetGroupName" + ] + } + }, + { + "name": { + "Fn::GetAtt": [ + "GreenTargetGroupEEB2DF3E", + "TargetGroupName" + ] + } + } + ], + "prodTrafficRoute": { + "listenerArns": [ + { + "Ref": "ALBListener3B99FF85" + } + ] + } + } + ] + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-codedeploy.CfnDeploymentGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-codedeploy.EcsDeploymentGroup", + "version": "0.0.0" + } + }, + "Service-principalMap": { + "id": "Service-principalMap", + "path": "aws-cdk-codedeploy-ecs-dg/Service-principalMap", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnMapping", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + }, + "EcsTest": { + "id": "EcsTest", + "path": "EcsTest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "EcsTest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "EcsTest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.95" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "EcsTest/DefaultTest/DeployAssert", + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTest", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.test.ts b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.test.ts index 70750e3406e44..60a3795fe3fb5 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.test.ts +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.test.ts @@ -1,5 +1,61 @@ +import { Template } from '@aws-cdk/assertions'; +import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; +import * as ec2 from '@aws-cdk/aws-ec2'; +import * as ecs from '@aws-cdk/aws-ecs'; +import { ApplicationLoadBalancer, ApplicationProtocol, ApplicationTargetGroup, IApplicationTargetGroup, TargetType } from '@aws-cdk/aws-elasticloadbalancingv2'; import * as cdk from '@aws-cdk/core'; +import { Duration } from '@aws-cdk/core'; import * as codedeploy from '../../lib'; +import { EcsDeploymentGroupProps } from '../../lib'; + +function stubEcsDeploymentGroupProps(stack: cdk.Stack) : EcsDeploymentGroupProps { + const vpc = new ec2.Vpc(stack, 'MyVpc'); + const cluster = new ecs.Cluster(stack, 'MyCluster', { + vpc, + }); + const taskDefinition = new ecs.FargateTaskDefinition(stack, 'MyTaskDef', { + cpu: 256, + memoryLimitMiB: 512, + family: 'myfamily', + }); + taskDefinition.addContainer('MyContainer', { + image: ecs.ContainerImage.fromRegistry('nginx'), + portMappings: [{ + containerPort: 80, + }], + }); + const service = new ecs.FargateService(stack, 'MyService', { + cluster, + taskDefinition, + }); + const blueTargetGroup = new ApplicationTargetGroup(stack, 'BlueTargetGroup', { + vpc, + protocol: ApplicationProtocol.HTTP, + targetType: TargetType.IP, + }); + const greenTargetGroup = new ApplicationTargetGroup(stack, 'GreenTargetGroup', { + vpc, + protocol: ApplicationProtocol.HTTP, + targetType: TargetType.IP, + }); + const loadBalancer = new ApplicationLoadBalancer(stack, 'SvcALB', { + vpc, + }); + const listener = loadBalancer.addListener('SvcListener', { + defaultTargetGroups: [blueTargetGroup], + port: 80, + }); + service.attachToApplicationTargetGroup(blueTargetGroup); + + return { + services: [service], + blueGreenDeploymentConfiguration: { + prodListener: listener, + blueTargetGroup, + greenTargetGroup, + }, + }; +} describe('CodeDeploy ECS DeploymentGroup', () => { describe('imported with fromEcsDeploymentGroupAttributes', () => { @@ -15,4 +71,273 @@ describe('CodeDeploy ECS DeploymentGroup', () => { expect(importedGroup.deploymentConfig).toEqual(codedeploy.EcsDeploymentConfig.ALL_AT_ONCE); }); }); + + test('service is updated', () => { + const stack = new cdk.Stack(); + + const props = stubEcsDeploymentGroupProps(stack); + const application = new codedeploy.EcsApplication(stack, 'MyApp'); + new codedeploy.EcsDeploymentGroup(stack, 'MyDG', { + ...props, + application, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { + DeploymentController: { + Type: 'CODE_DEPLOY', + }, + TaskDefinition: 'myfamily', + }); + }); + + test('can set deploymentReadyOption', () => { + const stack = new cdk.Stack(); + + const props = stubEcsDeploymentGroupProps(stack); + const application = new codedeploy.EcsApplication(stack, 'MyApp'); + new codedeploy.EcsDeploymentGroup(stack, 'MyDG', { + ...props, + application, + blueGreenDeploymentConfiguration: { + ...props.blueGreenDeploymentConfiguration, + waitTimeForContinueDeployment: Duration.minutes(10), + waitTimeForTermination: Duration.minutes(5), + }, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', { + BlueGreenDeploymentConfiguration: { + DeploymentReadyOption: { + ActionOnTimeout: 'STOP_DEPLOYMENT', + WaitTimeInMinutes: 10, + }, + TerminateBlueInstancesOnDeploymentSuccess: { + Action: 'TERMINATE', + TerminationWaitTimeInMinutes: 5, + }, + }, + }); + }); + + test('can be created by explicitly passing an Application', () => { + const stack = new cdk.Stack(); + + const application = new codedeploy.EcsApplication(stack, 'MyApp'); + const props = stubEcsDeploymentGroupProps(stack); + new codedeploy.EcsDeploymentGroup(stack, 'MyDG', { + ...props, + application, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', { + ApplicationName: { + Ref: 'MyApp3CE31C26', + }, + ECSServices: [{ + ClusterName: stack.resolve(props.services[0].cluster.clusterName), + ServiceName: stack.resolve(props.services[0].serviceName), + }], + DeploymentStyle: { + DeploymentOption: 'WITH_TRAFFIC_CONTROL', + DeploymentType: 'BLUE_GREEN', + }, + AutoRollbackConfiguration: { + Enabled: true, + Events: [ + 'DEPLOYMENT_FAILURE', + ], + }, + BlueGreenDeploymentConfiguration: { + DeploymentReadyOption: { + ActionOnTimeout: 'CONTINUE_DEPLOYMENT', + }, + TerminateBlueInstancesOnDeploymentSuccess: { + Action: 'TERMINATE', + TerminationWaitTimeInMinutes: 0, + }, + }, + DeploymentConfigName: 'CodeDeployDefault.ECSAllAtOnce', + }); + }); + + test('can be imported', () => { + const stack = new cdk.Stack(); + + const application = codedeploy.EcsApplication.fromEcsApplicationName(stack, 'MyApp', 'MyApp'); + const deploymentGroup = codedeploy.EcsDeploymentGroup.fromEcsDeploymentGroupAttributes(stack, 'MyDG', { + application, + deploymentGroupName: 'MyDG', + }); + + expect(deploymentGroup).not.toEqual(undefined); + }); + + test('can have alarms added to it after being created', () => { + const stack = new cdk.Stack(); + + const alarm = new cloudwatch.Alarm(stack, 'Alarm1', { + metric: new cloudwatch.Metric({ + metricName: 'Errors', + namespace: 'my.namespace', + }), + threshold: 1, + evaluationPeriods: 1, + }); + + const props = stubEcsDeploymentGroupProps(stack); + const deploymentGroup = new codedeploy.EcsDeploymentGroup(stack, 'DeploymentGroup', { + ...props, + }); + deploymentGroup.addAlarm(alarm); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', { + AlarmConfiguration: { + Alarms: [ + { + Name: { + Ref: 'Alarm1F9009D71', + }, + }, + ], + Enabled: true, + }, + }); + }); + + test('only automatically rolls back failed deployments by default', () => { + const stack = new cdk.Stack(); + + const props = stubEcsDeploymentGroupProps(stack); + new codedeploy.EcsDeploymentGroup(stack, 'DeploymentGroup', { + ...props, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', { + AutoRollbackConfiguration: { + Enabled: true, + Events: [ + 'DEPLOYMENT_FAILURE', + ], + }, + }); + }); + + test('rolls back alarmed deployments if at least one alarm has been added', () => { + const stack = new cdk.Stack(); + + const alarm = new cloudwatch.Alarm(stack, 'Alarm1', { + metric: new cloudwatch.Metric({ + metricName: 'Errors', + namespace: 'my.namespace', + }), + threshold: 1, + evaluationPeriods: 1, + }); + + const props = stubEcsDeploymentGroupProps(stack); + const deploymentGroup = new codedeploy.EcsDeploymentGroup(stack, 'DeploymentGroup', { + ...props, + autoRollback: { + failedDeployment: false, + }, + }); + deploymentGroup.addAlarm(alarm); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', { + AutoRollbackConfiguration: { + Enabled: true, + Events: [ + 'DEPLOYMENT_STOP_ON_ALARM', + ], + }, + }); + }); + + test('setting to roll back on alarms without providing any results in an exception', () => { + const app = new cdk.App(); + const stack = new cdk.Stack(app); + + const props = stubEcsDeploymentGroupProps(stack); + new codedeploy.EcsDeploymentGroup(stack, 'DeploymentGroup', { + ...props, + autoRollback: { + deploymentInAlarm: true, + }, + }); + + expect(() => app.synth()).toThrow(/deploymentInAlarm/); + }); + + test('setting traffic shifting', () => { + const app = new cdk.App(); + const stack = new cdk.Stack(app); + + const props = stubEcsDeploymentGroupProps(stack); + const loadBalancer = new ApplicationLoadBalancer(stack, 'testALB', { + vpc: props.services[0].cluster.vpc, + }); + const testListener = loadBalancer.addListener('TestListener', { + defaultTargetGroups: [props.blueGreenDeploymentConfiguration.blueTargetGroup as IApplicationTargetGroup], + protocol: ApplicationProtocol.HTTP, + port: 81, + }); + new codedeploy.EcsDeploymentGroup(stack, 'DeploymentGroup', { + ...props, + blueGreenDeploymentConfiguration: { + ...props.blueGreenDeploymentConfiguration, + testListener, + }, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', { + DeploymentStyle: { + DeploymentOption: 'WITH_TRAFFIC_CONTROL', + DeploymentType: 'BLUE_GREEN', + }, + LoadBalancerInfo: { + TargetGroupPairInfoList: [{ + TargetGroups: [{ + Name: stack.resolve(props.blueGreenDeploymentConfiguration.blueTargetGroup.targetGroupName), + }, { + Name: stack.resolve(props.blueGreenDeploymentConfiguration.greenTargetGroup.targetGroupName), + }], + ProdTrafficRoute: { + ListenerArns: [ + stack.resolve(props.blueGreenDeploymentConfiguration.prodListener.listenerArn), + ], + }, + TestTrafficRoute: { + ListenerArns: [ + stack.resolve(testListener.listenerArn), + ], + }, + }], + }, + }); + }); + + test('fail with more than 100 characters in name', () => { + const app = new cdk.App(); + const stack = new cdk.Stack(app); + const props = stubEcsDeploymentGroupProps(stack); + new codedeploy.EcsDeploymentGroup(stack, 'MyDG', { + ...props, + deploymentGroupName: 'a'.repeat(101), + }); + + expect(() => app.synth()).toThrow(`Deployment group name: "${'a'.repeat(101)}" can be a max of 100 characters.`); + }); + + test('fail with unallowed characters in name', () => { + const app = new cdk.App(); + const stack = new cdk.Stack(app); + const props = stubEcsDeploymentGroupProps(stack); + new codedeploy.EcsDeploymentGroup(stack, 'MyDG', { + ...props, + deploymentGroupName: 'my name', + }); + + expect(() => app.synth()).toThrow('Deployment group name: "my name" can only contain letters (a-z, A-Z), numbers (0-9), periods (.), underscores (_), + (plus signs), = (equals signs), , (commas), @ (at signs), - (minus signs).'); + }); + }); diff --git a/packages/@aws-cdk/aws-codedeploy/test/ecs/integ.deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/test/ecs/integ.deployment-group.ts new file mode 100644 index 0000000000000..b42e069249ffa --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/test/ecs/integ.deployment-group.ts @@ -0,0 +1,80 @@ +import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; +import { ComparisonOperator } from '@aws-cdk/aws-cloudwatch'; +import * as ec2 from '@aws-cdk/aws-ec2'; +import * as ecs from '@aws-cdk/aws-ecs'; +import { ApplicationLoadBalancer, ApplicationProtocol, ApplicationTargetGroup, TargetType } from '@aws-cdk/aws-elasticloadbalancingv2'; +import * as cdk from '@aws-cdk/core'; +import * as integ from '@aws-cdk/integ-tests'; +import * as codedeploy from '../../lib'; +import { EcsDeploymentConfig } from '../../lib'; + +const app = new cdk.App(); + +const stack = new cdk.Stack(app, 'aws-cdk-codedeploy-ecs-dg'); + +const vpc = new ec2.Vpc(stack, 'VPC'); + +const cluster = new ecs.Cluster(stack, 'MyCluster', { + vpc, +}); +const taskDefinition = new ecs.FargateTaskDefinition(stack, 'MyTaskDef', { + cpu: 256, + memoryLimitMiB: 512, + family: 'nginx', +}); +taskDefinition.addContainer('MyContainer', { + image: ecs.ContainerImage.fromRegistry('nginx@sha256:79c77eb7ca32f9a117ef91bc6ac486014e0d0e75f2f06683ba24dc298f9f4dd4'), + portMappings: [{ + containerPort: 80, + }], +}); +const service = new ecs.FargateService(stack, 'MyService', { + cluster, + taskDefinition, +}); +const blueTargetGroup = new ApplicationTargetGroup(stack, 'BlueTargetGroup', { + vpc, + protocol: ApplicationProtocol.HTTP, + targetType: TargetType.IP, +}); +const greenTargetGroup = new ApplicationTargetGroup(stack, 'GreenTargetGroup', { + vpc, + protocol: ApplicationProtocol.HTTP, + targetType: TargetType.IP, +}); +const loadBalancer = new ApplicationLoadBalancer(stack, 'ALB', { + vpc, +}); +const listener = loadBalancer.addListener('Listener', { + defaultTargetGroups: [blueTargetGroup], + port: 80, +}); +service.attachToApplicationTargetGroup(blueTargetGroup); + +new codedeploy.EcsDeploymentGroup(stack, 'CodeDeployGroup', { + deploymentConfig: EcsDeploymentConfig.CANARY_10_PERCENT_5_MINUTES, + services: [service], + alarms: [ + new cloudwatch.Alarm(stack, 'Alarm1', { + metric: loadBalancer.metricTargetResponseTime(), + threshold: 3, + evaluationPeriods: 2, + comparisonOperator: ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD, + }), + ], + blueGreenDeploymentConfiguration: { + prodListener: listener, + blueTargetGroup: blueTargetGroup, + greenTargetGroup: greenTargetGroup, + }, + autoRollback: { + failedDeployment: false, + deploymentInAlarm: false, + }, +}); + +new integ.IntegTest(app, 'EcsTest', { + testCases: [stack], +}); + +app.synth(); \ No newline at end of file