Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/aws-cdk-lib/aws-codedeploy/lib/ecs/deployment-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import { propertyInjectable } from '../../../core/lib/prop-injectable';
import { CODEDEPLOY_REMOVE_ALARMS_FROM_DEPLOYMENT_GROUP } from '../../../cx-api';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { ImportedDeploymentGroupBase, DeploymentGroupBase } from '../private/base-deployment-group';
import { renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../private/utils';
import { renderAlarmConfiguration, renderAutoRollbackConfiguration, renderTriggerConfiguration } from '../private/utils';
import { AutoRollbackConfig } from '../rollback-config';
import { TriggerConfiguration } from '../trigger-configuration';

/**
* Interface for an ECS deployment group.
Expand Down Expand Up @@ -188,6 +189,13 @@ export interface EcsDeploymentGroupProps {
* @default - false
*/
readonly ignoreAlarmConfiguration?: boolean;

/**
* Information about triggers associated with the deployment group.
*
* @see https://docs.aws.amazon.com/codedeploy/latest/userguide/monitoring-sns-event-notifications.html
*/
readonly triggerConfigurations?: TriggerConfiguration[];
}

/**
Expand Down Expand Up @@ -281,6 +289,7 @@ export class EcsDeploymentGroup extends DeploymentGroupBase implements IEcsDeplo
}),
}),
autoRollbackConfiguration: cdk.Lazy.any({ produce: () => renderAutoRollbackConfiguration(this, this.alarms, props.autoRollback) }),
triggerConfigurations: cdk.Lazy.any({ produce: () => renderTriggerConfiguration(props.triggerConfigurations) }),
});

this._setNameAndArn(resource, this.application);
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-codedeploy/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './traffic-routing-config';
export * from './ecs';
export * from './lambda';
export * from './server';
export * from './trigger-configuration';

// AWS::CodeDeploy CloudFormation Resources:
export * from './codedeploy.generated';
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { propertyInjectable } from '../../../core/lib/prop-injectable';
import { CODEDEPLOY_REMOVE_ALARMS_FROM_DEPLOYMENT_GROUP } from '../../../cx-api';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { ImportedDeploymentGroupBase, DeploymentGroupBase } from '../private/base-deployment-group';
import { renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../private/utils';
import { renderAlarmConfiguration, renderAutoRollbackConfiguration, renderTriggerConfiguration } from '../private/utils';
import { AutoRollbackConfig } from '../rollback-config';
import { TriggerConfiguration } from '../trigger-configuration';

/**
* Interface for a Lambda deployment groups.
Expand Down Expand Up @@ -126,6 +127,13 @@ export interface LambdaDeploymentGroupProps {
* @default - false
*/
readonly ignoreAlarmConfiguration?: boolean;

/**
* Information about triggers associated with the deployment group.
*
* @see https://docs.aws.amazon.com/codedeploy/latest/userguide/monitoring-sns-event-notifications.html
*/
readonly triggerConfigurations?: TriggerConfiguration[];
}

/**
Expand Down Expand Up @@ -200,6 +208,7 @@ export class LambdaDeploymentGroup extends DeploymentGroupBase implements ILambd
}),
}),
autoRollbackConfiguration: cdk.Lazy.any({ produce: () => renderAutoRollbackConfiguration(this, this.alarms, props.autoRollback) }),
triggerConfigurations: cdk.Lazy.any({ produce: () => renderTriggerConfiguration(props.triggerConfigurations) }),
});

this._setNameAndArn(resource, this.application);
Expand Down
16 changes: 16 additions & 0 deletions packages/aws-cdk-lib/aws-codedeploy/lib/private/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Token, Stack, ArnFormat, Arn, Fn, Aws, IResource, ValidationError } fro
import { IBaseDeploymentConfig } from '../base-deployment-config';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { AutoRollbackConfig } from '../rollback-config';
import { TriggerConfiguration } from '../trigger-configuration';

export function arnForApplication(stack: Stack, applicationName: string): string {
return stack.formatArn({
Expand Down Expand Up @@ -152,3 +153,18 @@ export function validateName(type: 'Application' | 'Deployment group' | 'Deploym

return ret;
}

export function renderTriggerConfiguration(config: TriggerConfiguration[] | undefined): CfnDeploymentGroup.TriggerConfigProperty[] | undefined {
if (config === undefined || config.length === 0) {
return undefined;
}
const triggers = new Array<CfnDeploymentGroup.TriggerConfigProperty>();
config.forEach(triggerConfig => {
triggers.push({
triggerEvents: triggerConfig.events,
triggerName: triggerConfig.name,
triggerTargetArn: triggerConfig.targetArn,
});
});
return triggers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { propertyInjectable } from '../../../core/lib/prop-injectable';
import { CODEDEPLOY_REMOVE_ALARMS_FROM_DEPLOYMENT_GROUP } from '../../../cx-api';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { ImportedDeploymentGroupBase, DeploymentGroupBase } from '../private/base-deployment-group';
import { renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../private/utils';
import { renderAlarmConfiguration, renderAutoRollbackConfiguration, renderTriggerConfiguration } from '../private/utils';
import { AutoRollbackConfig } from '../rollback-config';
import { TriggerConfiguration } from '../trigger-configuration';

export interface IServerDeploymentGroup extends cdk.IResource {
readonly application: IServerApplication;
Expand Down Expand Up @@ -242,6 +243,13 @@ export interface ServerDeploymentGroupProps {
* @default - false
*/
readonly terminationHook?: boolean;

/**
* Information about triggers associated with the deployment group.
*
* @see https://docs.aws.amazon.com/codedeploy/latest/userguide/monitoring-sns-event-notifications.html
*/
readonly triggerConfigurations?: TriggerConfiguration[];
}

/**
Expand Down Expand Up @@ -340,6 +348,7 @@ export class ServerDeploymentGroup extends DeploymentGroupBase implements IServe
}),
autoRollbackConfiguration: cdk.Lazy.any({ produce: () => renderAutoRollbackConfiguration(this, this.alarms, props.autoRollback) }),
terminationHookEnabled: props.terminationHook,
triggerConfigurations: cdk.Lazy.any({ produce: () => renderTriggerConfiguration(props.triggerConfigurations) }),
});

this._setNameAndArn(resource, this.application);
Expand Down
42 changes: 42 additions & 0 deletions packages/aws-cdk-lib/aws-codedeploy/lib/trigger-configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Type of Code Deploy events for which you can trigger notifications
*/
export enum TriggerEvent {
DEPLOYMENT_START = 'DeploymentStart',
DEPLOYMENT_SUCCESS = 'DeploymentSuccess',
DEPLOYMENT_FAILURE = 'DeploymentFailure',
DEPLOYMENT_STOP = 'DeploymentStop',
/**
* Applies only to replacement instances in a blue/green deployment
*/
DEPLOYMENT_READY = 'DeploymentReady',
DEPLOYMENT_ROLLBACK = 'DeploymentRollback',
INSTANCE_START = 'InstanceStart',
INSTANCE_SUCCESS = 'InstanceSuccess',
INSTANCE_FAILURE = 'InstanceFailure',
/**
* Applies only to replacement instances in a blue/green deployment
*/
INSTANCE_READY = 'InstanceReady',
}

/**
* Event trigger configuration that can be attached to a Deployment Group
*/
export interface TriggerConfiguration {
/**
* The event type or types that trigger notifications.
*/
readonly events: TriggerEvent[];

/**
* The name you want to give the trigger so you can easily identify it.
*/
readonly name: string;

/**
* The Amazon Resource Name (ARN) of the Amazon Simple Notification Service topic
* through which notifications about deployment or instance events are sent.
*/
readonly targetArn: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ describe('CodeDeploy ECS DeploymentGroup', () => {
greenTargetGroup: mockTargetGroup(stack, 'green'),
listener: mockListener(stack, 'prod'),
},
triggerConfigurations: [{
events: [codedeploy.TriggerEvent.DEPLOYMENT_SUCCESS],
name: 'testName',
targetArn: 'testArn',
}],
});

Template.fromStack(stack).hasResource('AWS::CodeDeploy::DeploymentGroup', {
Expand Down Expand Up @@ -124,6 +129,11 @@ describe('CodeDeploy ECS DeploymentGroup', () => {
},
],
},
TriggerConfigurations: [{
TriggerEvents: ['DeploymentSuccess'],
TriggerName: 'testName',
TriggerTargetArn: 'testArn',
}],
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
application,
alias,
deploymentConfig: codedeploy.LambdaDeploymentConfig.ALL_AT_ONCE,
triggerConfigurations: [{
events: [codedeploy.TriggerEvent.DEPLOYMENT_SUCCESS],
name: 'testName',
targetArn: 'testArn',
}],
});

Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
Expand Down Expand Up @@ -60,6 +65,11 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
DeploymentOption: 'WITH_TRAFFIC_CONTROL',
DeploymentType: 'BLUE_GREEN',
},
TriggerConfigurations: [{
TriggerEvents: ['DeploymentSuccess'],
TriggerName: 'testName',
TriggerTargetArn: 'testArn',
}],
});

Template.fromStack(stack).hasResource('AWS::Lambda::Alias', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,36 @@ describe('CodeDeploy Server Deployment Group', () => {
});

Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
'ApplicationName': {
'Ref': 'MyApp3CE31C26',
ApplicationName: {
Ref: 'MyApp3CE31C26',
},
});
});

test('trigger config is created if specified', () => {
const stack = new cdk.Stack();
const application = new codedeploy.ServerApplication(stack, 'MyApp');
new codedeploy.ServerDeploymentGroup(stack, 'MyDG', {
application,
triggerConfigurations: [{
events: [codedeploy.TriggerEvent.DEPLOYMENT_SUCCESS],
name: 'testName',
targetArn: 'testArn',
}],
});

Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
ApplicationName: {
Ref: 'MyApp3CE31C26',
},
TriggerConfigurations: [{
TriggerEvents: ['DeploymentSuccess'],
TriggerName: 'testName',
TriggerTargetArn: 'testArn',
}],
});
});

test('can create a deployment group with no alarms', () => {
const stack = new cdk.Stack();
stack.node.setContext('@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup', true);
Expand Down