Skip to content

Commit f563c95

Browse files
committed
feat: add EcsDeploymentConfiguration construct
1 parent 8699217 commit f563c95

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { IEcsDeploymentConfig, CfnDeploymentConfigProps, CfnDeploymentConfig } from '@aws-cdk/aws-codedeploy';
2+
3+
import { Aws, Construct } from '@aws-cdk/core';
4+
5+
type EcsDeploymentConfigurationProps = Omit<CfnDeploymentConfigProps, 'computePlatform'>;
6+
7+
export class EcsDeploymentConfiguration extends Construct {
8+
readonly ecsDeploymentConfig: IEcsDeploymentConfig;
9+
10+
constructor(scope: Construct, id: string, props: EcsDeploymentConfigurationProps) {
11+
super(scope, id);
12+
13+
const cfnDeploymentConfig = new CfnDeploymentConfig(this, 'EcsDeploymentConfiguration', {
14+
computePlatform: 'ECS',
15+
...props,
16+
});
17+
18+
const deployConfigurationName = props.deploymentConfigName ?? cfnDeploymentConfig.ref;
19+
20+
this.ecsDeploymentConfig = {
21+
deploymentConfigName: deployConfigurationName,
22+
deploymentConfigArn: this.arnForDeploymentConfig(deployConfigurationName),
23+
};
24+
}
25+
26+
private arnForDeploymentConfig(deploymentConfigurationName: string): string {
27+
return `arn:${Aws.PARTITION}:codedeploy:${Aws.REGION}:${Aws.ACCOUNT_ID}:deploymentconfig:${deploymentConfigurationName}`;
28+
}
29+
}

packages/cdk-blue-green-container-deployment/src/ecs-deployment-group.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import * as path from 'path';
2-
import {
3-
EcsApplication,
4-
IEcsDeploymentGroup,
5-
IEcsApplication,
6-
IEcsDeploymentConfig,
7-
EcsDeploymentConfig,
8-
CfnDeploymentConfigProps,
9-
} from '@aws-cdk/aws-codedeploy';
2+
import { EcsApplication, IEcsDeploymentGroup, IEcsApplication, IEcsDeploymentConfig, EcsDeploymentConfig } from '@aws-cdk/aws-codedeploy';
103
import { Role, ServicePrincipal, ManagedPolicy, Effect } from '@aws-cdk/aws-iam';
114
import { Aws, Construct, Resource, CustomResource, CustomResourceProvider, CustomResourceProviderRuntime } from '@aws-cdk/core';
125

@@ -50,8 +43,6 @@ export interface EcsDeploymentGroupProps {
5043
* The event type or types that trigger a rollback.
5144
*/
5245
readonly autoRollbackOnEvents?: RollbackEvent[];
53-
54-
readonly createDeploymentConfigInput?: CfnDeploymentConfigProps;
5546
}
5647

5748
export class EcsDeploymentGroup extends Resource implements IEcsDeploymentGroup {
@@ -73,7 +64,6 @@ export class EcsDeploymentGroup extends Resource implements IEcsDeploymentGroup
7364
testTrafficListener,
7465
terminationWaitTimeInMinutes = 60,
7566
autoRollbackOnEvents,
76-
createDeploymentConfigInput,
7767
} = props;
7868

7969
if (terminationWaitTimeInMinutes > 2880) {
@@ -128,8 +118,7 @@ export class EcsDeploymentGroup extends Resource implements IEcsDeploymentGroup
128118
TestTrafficListenerArn: testTrafficListener.listenerArn,
129119
TerminationWaitTimeInMinutes: terminationWaitTimeInMinutes,
130120
AutoRollbackOnEvents: autoRollbackOnEvents,
131-
ExistsDeploymentConfigName: deploymentConfig?.deploymentConfigName,
132-
CreateDeploymentConfigInput: createDeploymentConfigInput,
121+
DeploymentConfigName: deploymentConfig?.deploymentConfigName,
133122
},
134123
});
135124

packages/cdk-blue-green-container-deployment/src/lambdas/ecs-deployment-group/index.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ export interface EcsDeploymentGroupProps {
2626
testTrafficListenerArn: string;
2727
terminationWaitTimeInMinutes: number;
2828
autoRollbackOnEvents?: RollbackEvent[];
29-
existsDeploymentConfigName?: string;
30-
createDeploymentConfigInput?: CodeDeploy.CreateDeploymentConfigInput;
29+
deploymentConfigName?: string;
3130
}
3231

3332
const codeDeploy = new CodeDeploy();
@@ -47,8 +46,7 @@ const getProperties = (
4746
testTrafficListenerArn: props.TestTrafficListenerArn,
4847
terminationWaitTimeInMinutes: props.TerminationWaitTimeInMinutes,
4948
autoRollbackOnEvents: props.AutoRollbackOnEvents,
50-
existsDeploymentConfigName: props.ExistsDeploymentConfigName,
51-
createDeploymentConfigInput: props.CreateDeploymentConfigInput,
49+
deploymentConfigName: props.DeploymentConfigName,
5250
});
5351

5452
const onCreate = async (event: CloudFormationCustomResourceCreateEvent): Promise<HandlerReturn> => {
@@ -62,14 +60,9 @@ const onCreate = async (event: CloudFormationCustomResourceCreateEvent): Promise
6260
testTrafficListenerArn,
6361
terminationWaitTimeInMinutes,
6462
autoRollbackOnEvents,
65-
existsDeploymentConfigName,
66-
createDeploymentConfigInput,
63+
deploymentConfigName,
6764
} = getProperties(event.ResourceProperties);
6865

69-
if (!existsDeploymentConfigName && createDeploymentConfigInput) {
70-
await codeDeploy.createDeploymentConfig(createDeploymentConfigInput).promise();
71-
}
72-
7366
await codeDeploy
7467
.createDeploymentGroup({
7568
applicationName,
@@ -108,7 +101,7 @@ const onCreate = async (event: CloudFormationCustomResourceCreateEvent): Promise
108101
deploymentType: 'BLUE_GREEN',
109102
deploymentOption: 'WITH_TRAFFIC_CONTROL',
110103
},
111-
deploymentConfigName: existsDeploymentConfigName ?? createDeploymentConfigInput?.deploymentConfigName,
104+
deploymentConfigName: deploymentConfigName ?? 'CodeDeployDefault.OneAtATime',
112105
})
113106
.promise();
114107

@@ -164,22 +157,14 @@ const onUpdate = async (event: CloudFormationCustomResourceUpdateEvent): Promise
164157
};
165158

166159
const onDelete = async (event: CloudFormationCustomResourceDeleteEvent): Promise<void> => {
167-
const { applicationName, deploymentGroupName, existsDeploymentConfigName, createDeploymentConfigInput } = getProperties(event.ResourceProperties);
160+
const { applicationName, deploymentGroupName } = getProperties(event.ResourceProperties);
168161

169162
await codeDeploy
170163
.deleteDeploymentGroup({
171164
applicationName,
172165
deploymentGroupName,
173166
})
174167
.promise();
175-
176-
if (!existsDeploymentConfigName && createDeploymentConfigInput) {
177-
await codeDeploy
178-
.deleteDeploymentConfig({
179-
deploymentConfigName: createDeploymentConfigInput?.deploymentConfigName,
180-
})
181-
.promise();
182-
}
183168
};
184169

185170
export const handler = async (event: CloudFormationCustomResourceEvent): Promise<HandlerReturn | void> => {

0 commit comments

Comments
 (0)