@gradientedge/cdk-utils 9.25.0 → 9.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { CfnApplication, CfnConfigurationProfile, CfnDeploymentStrategy, CfnEnvironment, CfnHostedConfigurationVersion } from 'aws-cdk-lib/aws-appconfig';
1
+ import { CfnApplication, CfnConfigurationProfile, CfnEnvironment, CfnHostedConfigurationVersion, IDeploymentStrategy } from 'aws-cdk-lib/aws-appconfig';
2
2
  import { Construct } from 'constructs';
3
3
  import { CommonConstruct } from '../../common';
4
4
  import { ApplicationConfigurationProps } from './types';
@@ -9,7 +9,7 @@ export declare class ApplicationConfiguration extends CommonConstruct {
9
9
  appConfigEnvironment: CfnEnvironment;
10
10
  appConfigProfile: CfnConfigurationProfile;
11
11
  appConfigVersion: CfnHostedConfigurationVersion;
12
- appConfigDeploymentStrategy: CfnDeploymentStrategy;
12
+ appConfigDeploymentStrategy: IDeploymentStrategy;
13
13
  constructor(parent: Construct, id: string, props: ApplicationConfigurationProps);
14
14
  initResources(): void;
15
15
  protected createConfiguration(): void;
@@ -46,11 +46,21 @@ class ApplicationConfiguration extends common_1.CommonConstruct {
46
46
  });
47
47
  }
48
48
  createAppConfigDeploymentStrategy() {
49
- this.appConfigDeploymentStrategy = new aws_appconfig_1.CfnDeploymentStrategy(this, `${this.id}-ac-deployment-strategy`, {
50
- deploymentDurationInMinutes: this.props.appConfig.deploymentStrategy.deploymentDurationInMinutes,
51
- growthFactor: this.props.appConfig.deploymentStrategy.growthFactor,
52
- name: this.resourceNameFormatter.format(this.props.appConfig.deploymentStrategy.name, this.props.resourceNameOptions?.appconfig),
53
- replicateTo: this.props.appConfig.deploymentStrategy.replicateTo,
49
+ if (!this.props.appConfig.deploymentStrategy)
50
+ return;
51
+ if (this.props.appConfig.deploymentStrategy?.deploymentStrategyArn) {
52
+ this.appConfigDeploymentStrategy = aws_appconfig_1.DeploymentStrategy.fromDeploymentStrategyArn(this, `${this.id}-ac-deployment-strategy`, this.props.appConfig.deploymentStrategy?.deploymentStrategyArn);
53
+ return;
54
+ }
55
+ this.appConfigDeploymentStrategy = new aws_appconfig_1.DeploymentStrategy(this, `${this.id}-ac-deployment-strategy`, {
56
+ ...this.props.appConfig.deploymentStrategy,
57
+ rolloutStrategy: this.props.appConfig.deploymentStrategy?.rolloutStrategy ??
58
+ aws_appconfig_1.RolloutStrategy.linear({
59
+ growthFactor: 100,
60
+ deploymentDuration: aws_cdk_lib_1.Duration.minutes(0),
61
+ finalBakeTime: aws_cdk_lib_1.Duration.minutes(0),
62
+ }),
63
+ deploymentStrategyName: this.resourceNameFormatter.format(this.props.appConfig.deploymentStrategy.deploymentStrategyName ?? 'common-deployment-strategy', this.props.resourceNameOptions?.appconfig),
54
64
  });
55
65
  }
56
66
  createAppConfigDeployment() {
@@ -58,7 +68,7 @@ class ApplicationConfiguration extends common_1.CommonConstruct {
58
68
  applicationId: aws_cdk_lib_1.Fn.ref(this.appConfigApplication.logicalId),
59
69
  configurationProfileId: aws_cdk_lib_1.Fn.ref(this.appConfigProfile.logicalId),
60
70
  configurationVersion: aws_cdk_lib_1.Fn.ref(this.appConfigVersion.logicalId),
61
- deploymentStrategyId: aws_cdk_lib_1.Fn.ref(this.appConfigDeploymentStrategy.logicalId),
71
+ deploymentStrategyId: this.appConfigDeploymentStrategy.deploymentStrategyId,
62
72
  environmentId: aws_cdk_lib_1.Fn.ref(this.appConfigEnvironment.logicalId),
63
73
  });
64
74
  }
@@ -85,6 +85,8 @@ class EventHandler extends common_1.CommonConstruct {
85
85
  * @summary Method to create the event rule pattern.
86
86
  */
87
87
  createEventRulePattern() {
88
+ if (!this.props.eventRule)
89
+ return;
88
90
  this.handler.rulePattern = this.props.eventRule.eventPattern;
89
91
  }
90
92
  /**
@@ -111,7 +113,10 @@ class EventHandler extends common_1.CommonConstruct {
111
113
  */
112
114
  createEventArchive() {
113
115
  /* do not enable for scheduled events */
114
- if (this.props.eventRule.schedule || this.props.eventRuleSchedule || !this.props.eventRuleArchiveEnabled)
116
+ if (!this.props.eventRule ||
117
+ this.props.eventRule.schedule ||
118
+ this.props.eventRuleSchedule ||
119
+ !this.props.eventRuleArchiveEnabled)
115
120
  return;
116
121
  this.handler.archive = new aws_events_1.Archive(this, `${this.id}-archive`, {
117
122
  archiveName: `${this.props.eventRule.ruleName}-${this.props.stage}`.replace(`${this.node.tryGetContext('stackName')}-`, ''),
@@ -125,6 +130,8 @@ class EventHandler extends common_1.CommonConstruct {
125
130
  * @summary Method to create the event rule.
126
131
  */
127
132
  createEventRule() {
133
+ if (!this.props.eventRule)
134
+ return;
128
135
  let schedule;
129
136
  if (this.props.eventRuleSchedule) {
130
137
  schedule = aws_events_1.Schedule.expression(this.props.eventRuleSchedule);
@@ -9,7 +9,7 @@ import { EventRuleProps, LogProps, QueueProps, SfnMapProps, SfnStateMachineProps
9
9
  export interface EventHandlerProps extends CommonStackProps {
10
10
  eventBusName: string;
11
11
  eventRetentionInDays: number;
12
- eventRule: EventRuleProps;
12
+ eventRule?: EventRuleProps;
13
13
  eventRuleArchiveEnabled: boolean;
14
14
  eventRuleSchedule: string;
15
15
  eventSqs: QueueProps;
@@ -1,4 +1,4 @@
1
- import { CfnApplication, CfnConfigurationProfile, CfnEnvironment } from 'aws-cdk-lib/aws-appconfig';
1
+ import { CfnApplication, CfnConfigurationProfile, CfnEnvironment, DeploymentStrategy } from 'aws-cdk-lib/aws-appconfig';
2
2
  import { CommonConstruct } from '../../common';
3
3
  import { Architecture } from '../constants';
4
4
  import { AppConfigProps } from './types';
@@ -52,4 +52,12 @@ export declare class AppConfigManager {
52
52
  * @returns the appconfig configuration profile
53
53
  */
54
54
  createConfigurationProfile(id: string, scope: CommonConstruct, applicationId: string, props: AppConfigProps): CfnConfigurationProfile;
55
+ /**
56
+ * @summary Method to create an AppConfig Deployment Strategy
57
+ * @param id scoped id of the resource
58
+ * @param scope scope in which this resource is defined
59
+ * @param props
60
+ * @returns the appconfig deployment strategy
61
+ */
62
+ createDeploymentStrategy(id: string, scope: CommonConstruct, props: AppConfigProps): DeploymentStrategy;
55
63
  }
@@ -98,5 +98,26 @@ class AppConfigManager {
98
98
  (0, utils_1.createCfnOutput)(`${id}-configurationProfileName`, scope, profile.name);
99
99
  return profile;
100
100
  }
101
+ /**
102
+ * @summary Method to create an AppConfig Deployment Strategy
103
+ * @param id scoped id of the resource
104
+ * @param scope scope in which this resource is defined
105
+ * @param props
106
+ * @returns the appconfig deployment strategy
107
+ */
108
+ createDeploymentStrategy(id, scope, props) {
109
+ if (!props)
110
+ throw `AppConfig props undefined for ${id}`;
111
+ if (!props.deploymentStrategy)
112
+ throw `AppConfig deploymentStrategy props undefined for ${id}`;
113
+ const deploymentStrategy = new aws_appconfig_1.DeploymentStrategy(scope, `${id}`, {
114
+ ...props,
115
+ deploymentStrategyName: scope.resourceNameFormatter.format(props.deploymentStrategy.deploymentStrategyName ?? 'common-deployment-strategy', scope.props.resourceNameOptions?.appconfig),
116
+ rolloutStrategy: props.deploymentStrategy.rolloutStrategy ?? aws_appconfig_1.RolloutStrategy.ALL_AT_ONCE,
117
+ });
118
+ (0, utils_1.createCfnOutput)(`${id}-deploymentStrategyId`, scope, deploymentStrategy.deploymentStrategyId);
119
+ (0, utils_1.createCfnOutput)(`${id}-deploymentStrategyArn`, scope, deploymentStrategy.deploymentStrategyArn);
120
+ return deploymentStrategy;
121
+ }
101
122
  }
102
123
  exports.AppConfigManager = AppConfigManager;
@@ -1,11 +1,17 @@
1
- import { CfnApplicationProps, CfnConfigurationProfileProps, CfnDeploymentProps, CfnDeploymentStrategyProps, CfnEnvironmentProps } from 'aws-cdk-lib/aws-appconfig';
1
+ import { CfnApplicationProps, CfnConfigurationProfileProps, CfnDeploymentProps, CfnEnvironmentProps, DeploymentStrategyProps } from 'aws-cdk-lib/aws-appconfig';
2
+ /**
3
+ *
4
+ */
5
+ export interface AppConfigDeploymentStrategyProps extends DeploymentStrategyProps {
6
+ deploymentStrategyArn?: string;
7
+ }
2
8
  /**
3
9
  */
4
10
  export interface AppConfigProps {
5
11
  application: CfnApplicationProps;
6
12
  configurationProfile: CfnConfigurationProfileProps;
7
13
  deployment: CfnDeploymentProps;
8
- deploymentStrategy: CfnDeploymentStrategyProps;
14
+ deploymentStrategy: AppConfigDeploymentStrategyProps;
9
15
  environment: CfnEnvironmentProps;
10
16
  id: string;
11
17
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "9.25.0",
3
+ "version": "9.26.1",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
7
7
  "node": ">=16 <=20",
8
8
  "pnpm": "=9"
9
9
  },
10
- "packageManager": "pnpm@8.15.8",
10
+ "packageManager": "pnpm@9.14.1+sha256.9978d5f40d4f376b054cf8c000cf8c326284344281e3c9bbf4e3d6f153b0e8de",
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/gradientedge/cdk-utils.git"
@@ -1,11 +1,13 @@
1
- import { Fn } from 'aws-cdk-lib'
1
+ import { Duration, Fn } from 'aws-cdk-lib'
2
2
  import {
3
3
  CfnApplication,
4
4
  CfnConfigurationProfile,
5
5
  CfnDeployment,
6
- CfnDeploymentStrategy,
7
6
  CfnEnvironment,
8
7
  CfnHostedConfigurationVersion,
8
+ DeploymentStrategy,
9
+ IDeploymentStrategy,
10
+ RolloutStrategy,
9
11
  } from 'aws-cdk-lib/aws-appconfig'
10
12
  import { Construct } from 'constructs'
11
13
  import { CommonConstruct } from '../../common'
@@ -18,7 +20,7 @@ export class ApplicationConfiguration extends CommonConstruct {
18
20
  appConfigEnvironment: CfnEnvironment
19
21
  appConfigProfile: CfnConfigurationProfile
20
22
  appConfigVersion: CfnHostedConfigurationVersion
21
- appConfigDeploymentStrategy: CfnDeploymentStrategy
23
+ appConfigDeploymentStrategy: IDeploymentStrategy
22
24
 
23
25
  constructor(parent: Construct, id: string, props: ApplicationConfigurationProps) {
24
26
  super(parent, id, props)
@@ -76,14 +78,30 @@ export class ApplicationConfiguration extends CommonConstruct {
76
78
  }
77
79
 
78
80
  protected createAppConfigDeploymentStrategy() {
79
- this.appConfigDeploymentStrategy = new CfnDeploymentStrategy(this, `${this.id}-ac-deployment-strategy`, {
80
- deploymentDurationInMinutes: this.props.appConfig.deploymentStrategy.deploymentDurationInMinutes,
81
- growthFactor: this.props.appConfig.deploymentStrategy.growthFactor,
82
- name: this.resourceNameFormatter.format(
83
- this.props.appConfig.deploymentStrategy.name,
81
+ if (!this.props.appConfig.deploymentStrategy) return
82
+
83
+ if (this.props.appConfig.deploymentStrategy?.deploymentStrategyArn) {
84
+ this.appConfigDeploymentStrategy = DeploymentStrategy.fromDeploymentStrategyArn(
85
+ this,
86
+ `${this.id}-ac-deployment-strategy`,
87
+ this.props.appConfig.deploymentStrategy?.deploymentStrategyArn
88
+ )
89
+ return
90
+ }
91
+
92
+ this.appConfigDeploymentStrategy = new DeploymentStrategy(this, `${this.id}-ac-deployment-strategy`, {
93
+ ...this.props.appConfig.deploymentStrategy,
94
+ rolloutStrategy:
95
+ this.props.appConfig.deploymentStrategy?.rolloutStrategy ??
96
+ RolloutStrategy.linear({
97
+ growthFactor: 100,
98
+ deploymentDuration: Duration.minutes(0),
99
+ finalBakeTime: Duration.minutes(0),
100
+ }),
101
+ deploymentStrategyName: this.resourceNameFormatter.format(
102
+ this.props.appConfig.deploymentStrategy.deploymentStrategyName ?? 'common-deployment-strategy',
84
103
  this.props.resourceNameOptions?.appconfig
85
104
  ),
86
- replicateTo: this.props.appConfig.deploymentStrategy.replicateTo,
87
105
  })
88
106
  }
89
107
 
@@ -92,7 +110,7 @@ export class ApplicationConfiguration extends CommonConstruct {
92
110
  applicationId: Fn.ref(this.appConfigApplication.logicalId),
93
111
  configurationProfileId: Fn.ref(this.appConfigProfile.logicalId),
94
112
  configurationVersion: Fn.ref(this.appConfigVersion.logicalId),
95
- deploymentStrategyId: Fn.ref(this.appConfigDeploymentStrategy.logicalId),
113
+ deploymentStrategyId: this.appConfigDeploymentStrategy.deploymentStrategyId,
96
114
  environmentId: Fn.ref(this.appConfigEnvironment.logicalId),
97
115
  })
98
116
  }
@@ -97,6 +97,7 @@ export class EventHandler extends CommonConstruct {
97
97
  * @summary Method to create the event rule pattern.
98
98
  */
99
99
  protected createEventRulePattern() {
100
+ if (!this.props.eventRule) return
100
101
  this.handler.rulePattern = this.props.eventRule.eventPattern
101
102
  }
102
103
 
@@ -130,7 +131,13 @@ export class EventHandler extends CommonConstruct {
130
131
  */
131
132
  protected createEventArchive() {
132
133
  /* do not enable for scheduled events */
133
- if (this.props.eventRule.schedule || this.props.eventRuleSchedule || !this.props.eventRuleArchiveEnabled) return
134
+ if (
135
+ !this.props.eventRule ||
136
+ this.props.eventRule.schedule ||
137
+ this.props.eventRuleSchedule ||
138
+ !this.props.eventRuleArchiveEnabled
139
+ )
140
+ return
134
141
  this.handler.archive = new Archive(this, `${this.id}-archive`, {
135
142
  archiveName: `${this.props.eventRule.ruleName}-${this.props.stage}`.replace(
136
143
  `${this.node.tryGetContext('stackName')}-`,
@@ -147,6 +154,7 @@ export class EventHandler extends CommonConstruct {
147
154
  * @summary Method to create the event rule.
148
155
  */
149
156
  protected createEventRule() {
157
+ if (!this.props.eventRule) return
150
158
  let schedule
151
159
  if (this.props.eventRuleSchedule) {
152
160
  schedule = Schedule.expression(this.props.eventRuleSchedule)
@@ -10,7 +10,7 @@ import { EventRuleProps, LogProps, QueueProps, SfnMapProps, SfnStateMachineProps
10
10
  export interface EventHandlerProps extends CommonStackProps {
11
11
  eventBusName: string
12
12
  eventRetentionInDays: number
13
- eventRule: EventRuleProps
13
+ eventRule?: EventRuleProps
14
14
  eventRuleArchiveEnabled: boolean
15
15
  eventRuleSchedule: string
16
16
  eventSqs: QueueProps
@@ -1,5 +1,11 @@
1
1
  import { Fn } from 'aws-cdk-lib'
2
- import { CfnApplication, CfnConfigurationProfile, CfnEnvironment } from 'aws-cdk-lib/aws-appconfig'
2
+ import {
3
+ CfnApplication,
4
+ CfnConfigurationProfile,
5
+ CfnEnvironment,
6
+ DeploymentStrategy,
7
+ RolloutStrategy,
8
+ } from 'aws-cdk-lib/aws-appconfig'
3
9
  import { CommonConstruct } from '../../common'
4
10
  import { createCfnOutput } from '../../utils'
5
11
  import { Architecture } from '../constants'
@@ -120,4 +126,30 @@ export class AppConfigManager {
120
126
 
121
127
  return profile
122
128
  }
129
+
130
+ /**
131
+ * @summary Method to create an AppConfig Deployment Strategy
132
+ * @param id scoped id of the resource
133
+ * @param scope scope in which this resource is defined
134
+ * @param props
135
+ * @returns the appconfig deployment strategy
136
+ */
137
+ public createDeploymentStrategy(id: string, scope: CommonConstruct, props: AppConfigProps): DeploymentStrategy {
138
+ if (!props) throw `AppConfig props undefined for ${id}`
139
+ if (!props.deploymentStrategy) throw `AppConfig deploymentStrategy props undefined for ${id}`
140
+
141
+ const deploymentStrategy = new DeploymentStrategy(scope, `${id}`, {
142
+ ...props,
143
+ deploymentStrategyName: scope.resourceNameFormatter.format(
144
+ props.deploymentStrategy.deploymentStrategyName ?? 'common-deployment-strategy',
145
+ scope.props.resourceNameOptions?.appconfig
146
+ ),
147
+ rolloutStrategy: props.deploymentStrategy.rolloutStrategy ?? RolloutStrategy.ALL_AT_ONCE,
148
+ })
149
+
150
+ createCfnOutput(`${id}-deploymentStrategyId`, scope, deploymentStrategy.deploymentStrategyId)
151
+ createCfnOutput(`${id}-deploymentStrategyArn`, scope, deploymentStrategy.deploymentStrategyArn)
152
+
153
+ return deploymentStrategy
154
+ }
123
155
  }
@@ -4,16 +4,24 @@ import {
4
4
  CfnDeploymentProps,
5
5
  CfnDeploymentStrategyProps,
6
6
  CfnEnvironmentProps,
7
+ DeploymentStrategyProps,
7
8
  } from 'aws-cdk-lib/aws-appconfig'
8
9
  import { ResourceNameFormatterProps } from '../../common'
9
10
 
11
+ /**
12
+ *
13
+ */
14
+ export interface AppConfigDeploymentStrategyProps extends DeploymentStrategyProps {
15
+ deploymentStrategyArn?: string
16
+ }
17
+
10
18
  /**
11
19
  */
12
20
  export interface AppConfigProps {
13
21
  application: CfnApplicationProps
14
22
  configurationProfile: CfnConfigurationProfileProps
15
23
  deployment: CfnDeploymentProps
16
- deploymentStrategy: CfnDeploymentStrategyProps
24
+ deploymentStrategy: AppConfigDeploymentStrategyProps
17
25
  environment: CfnEnvironmentProps
18
26
  id: string
19
27
  }