@gradientedge/cdk-utils 7.4.0 → 7.6.0

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.
@@ -8,7 +8,6 @@ import * as iam from 'aws-cdk-lib/aws-iam';
8
8
  import * as logs from 'aws-cdk-lib/aws-logs';
9
9
  import * as route53 from 'aws-cdk-lib/aws-route53';
10
10
  import * as s3 from 'aws-cdk-lib/aws-s3';
11
- import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
12
11
  import { Construct } from 'constructs';
13
12
  import { CommonConstruct } from '../../common';
14
13
  import { SiteWithEcsBackendProps } from '../../types';
@@ -55,7 +54,6 @@ export declare class SiteWithEcsBackend extends CommonConstruct {
55
54
  siteLogBucket: s3.IBucket;
56
55
  siteOrigin: origins.HttpOrigin;
57
56
  siteDistribution: cloudfront.Distribution;
58
- siteSecretAlgolia: secretsmanager.ISecret;
59
57
  siteInternalDomainName: string;
60
58
  siteExternalDomainName: string;
61
59
  siteDomainNames: string[];
@@ -24,11 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.SiteWithEcsBackend = void 0;
27
- const cdk = __importStar(require("aws-cdk-lib"));
28
27
  const cloudfront = __importStar(require("aws-cdk-lib/aws-cloudfront"));
29
28
  const origins = __importStar(require("aws-cdk-lib/aws-cloudfront-origins"));
30
29
  const ecs = __importStar(require("aws-cdk-lib/aws-ecs"));
31
- const ecsPatterns = __importStar(require("aws-cdk-lib/aws-ecs-patterns"));
32
30
  const iam = __importStar(require("aws-cdk-lib/aws-iam"));
33
31
  const common_1 = require("../../common");
34
32
  /**
@@ -74,7 +72,6 @@ class SiteWithEcsBackend extends common_1.CommonConstruct {
74
72
  siteLogBucket;
75
73
  siteOrigin;
76
74
  siteDistribution;
77
- siteSecretAlgolia;
78
75
  siteInternalDomainName;
79
76
  siteExternalDomainName;
80
77
  siteDomainNames;
@@ -222,47 +219,21 @@ class SiteWithEcsBackend extends common_1.CommonConstruct {
222
219
  * @protected
223
220
  */
224
221
  createEcsService() {
225
- const fargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, `${this.id}-ecs-service`, {
226
- cluster: this.siteEcsCluster,
227
- desiredCount: this.props.siteTask.desiredCount,
228
- enableECSManagedTags: true,
229
- serviceName: `${this.id}-${this.props.stage}`,
230
- cpu: this.props.siteTask.cpu,
231
- loadBalancerName: `${this.id}-${this.props.stage}`,
232
- domainName: this.siteInternalDomainName,
233
- domainZone: this.siteHostedZone,
234
- listenerPort: this.props.siteTask.listenerPort,
235
- memoryLimitMiB: this.props.siteTask.memoryLimitMiB,
236
- healthCheckGracePeriod: cdk.Duration.seconds(60),
237
- assignPublicIp: true,
238
- taskImageOptions: {
239
- enableLogging: true,
240
- logDriver: ecs.LogDriver.awsLogs({
241
- logGroup: this.siteEcsLogGroup,
242
- streamPrefix: `${this.id}-${this.props.stage}/ecs`,
243
- }),
244
- image: this.siteEcsContainerImage,
245
- executionRole: this.siteEcsRole,
246
- taskRole: this.siteEcsRole,
247
- containerPort: this.props.siteTask.taskImageOptions?.containerPort,
248
- environment: this.siteEcsEnvironment,
249
- secrets: this.siteSecrets,
222
+ const fargateService = this.ecsManager.createLoadBalancedFargateService(this.id, this, {
223
+ ...this.props.siteTask,
224
+ ...{
225
+ domainName: this.siteInternalDomainName,
226
+ domainZone: this.siteHostedZone,
227
+ healthCheck: this.props.siteHealthCheck,
228
+ taskImageOptions: {
229
+ environment: this.siteEcsEnvironment,
230
+ executionRole: this.siteEcsRole,
231
+ taskRole: this.siteEcsRole,
232
+ image: this.siteEcsContainerImage,
233
+ secrets: this.siteSecrets,
234
+ },
250
235
  },
251
- });
252
- if (this.props.siteHealthCheck) {
253
- fargateService.targetGroup.configureHealthCheck({
254
- enabled: this.props.siteHealthCheck.enabled ?? true,
255
- path: this.props.siteHealthCheck.path ?? '/',
256
- port: this.props.siteHealthCheck.port,
257
- interval: cdk.Duration.seconds(this.props.siteHealthCheck.intervalInSecs),
258
- timeout: cdk.Duration.seconds(this.props.siteHealthCheck.timeoutInSecs),
259
- healthyThresholdCount: this.props.siteHealthCheck.healthyThresholdCount,
260
- unhealthyThresholdCount: this.props.siteHealthCheck.unhealthyThresholdCount,
261
- healthyGrpcCodes: this.props.siteHealthCheck.healthyGrpcCodes,
262
- healthyHttpCodes: this.props.siteHealthCheck.healthyHttpCodes,
263
- protocol: this.props.siteHealthCheck.protocol,
264
- });
265
- }
236
+ }, this.siteEcsCluster, this.siteEcsLogGroup);
266
237
  this.siteEcsService = fargateService.service;
267
238
  this.siteEcsTaskDefinition = fargateService.taskDefinition;
268
239
  this.siteEcsListener = fargateService.listener;
@@ -1,3 +1,4 @@
1
+ import * as cdk from 'aws-cdk-lib';
1
2
  import * as ec2 from 'aws-cdk-lib/aws-ec2';
2
3
  import * as ecs from 'aws-cdk-lib/aws-ecs';
3
4
  import * as iam from 'aws-cdk-lib/aws-iam';
@@ -32,7 +33,7 @@ export declare class EcsManager {
32
33
  * @param {types.EcsClusterProps} props
33
34
  * @param {ec2.IVpc} vpc
34
35
  */
35
- createEcsCluster(id: string, scope: common.CommonConstruct, props: types.EcsClusterProps, vpc: ec2.IVpc): ecs.Cluster;
36
+ createEcsCluster(id: string, scope: common.CommonConstruct, props: types.EcsClusterProps, vpc: ec2.IVpc): cdk.aws_ecs.Cluster;
36
37
  /**
37
38
  * @summary Method to create an ecs fargate task
38
39
  * @param {string} id scoped id of the resource
@@ -45,5 +46,14 @@ export declare class EcsManager {
45
46
  * @param {Map<string, string>} environment
46
47
  * @param {Map<string, string>} secrets
47
48
  */
48
- createEcsFargateTask(id: string, scope: common.CommonConstruct, props: types.EcsTaskProps, cluster: ecs.ICluster, role: iam.Role, logGroup: logs.ILogGroup, containerImage: ecs.ContainerImage, environment?: any, secrets?: any): ecs.TaskDefinition;
49
+ createEcsFargateTask(id: string, scope: common.CommonConstruct, props: types.EcsTaskProps, cluster: ecs.ICluster, role: iam.Role, logGroup: logs.ILogGroup, containerImage: ecs.ContainerImage, environment?: any, secrets?: any): cdk.aws_ecs.TaskDefinition;
50
+ /**
51
+ * @summary Method to create an application loadbalanced ecs fargate task
52
+ * @param {string} id scoped id of the resource
53
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
54
+ * @param {types.EcsApplicationLoadBalancedFargateServiceProps} props
55
+ * @param {ecs.ICluster} cluster
56
+ * @param {logs.ILogGroup} logGroup
57
+ */
58
+ createLoadBalancedFargateService(id: string, scope: common.CommonConstruct, props: types.EcsApplicationLoadBalancedFargateServiceProps, cluster: ecs.ICluster, logGroup: logs.ILogGroup): cdk.aws_ecs_patterns.ApplicationLoadBalancedFargateService;
49
59
  }
@@ -24,7 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.EcsManager = void 0;
27
+ const cdk = __importStar(require("aws-cdk-lib"));
27
28
  const ecs = __importStar(require("aws-cdk-lib/aws-ecs"));
29
+ const ecsPatterns = __importStar(require("aws-cdk-lib/aws-ecs-patterns"));
28
30
  const utils = __importStar(require("../../utils"));
29
31
  /**
30
32
  * @stability stable
@@ -121,5 +123,63 @@ class EcsManager {
121
123
  utils.createCfnOutput(`${id}-taskArn`, scope, ecsTask.taskDefinitionArn);
122
124
  return ecsTask;
123
125
  }
126
+ /**
127
+ * @summary Method to create an application loadbalanced ecs fargate task
128
+ * @param {string} id scoped id of the resource
129
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
130
+ * @param {types.EcsApplicationLoadBalancedFargateServiceProps} props
131
+ * @param {ecs.ICluster} cluster
132
+ * @param {logs.ILogGroup} logGroup
133
+ */
134
+ createLoadBalancedFargateService(id, scope, props, cluster, logGroup) {
135
+ if (!props)
136
+ throw `EcsLoadbalanced Fargate Serivice props undefined`;
137
+ if (!props.taskImageOptions)
138
+ throw `TaskImageOptions for EcsLoadbalanced Fargate Serivice props undefined`;
139
+ const fargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(scope, `${id}-ecs-service`, {
140
+ cluster: cluster,
141
+ desiredCount: props.desiredCount,
142
+ enableECSManagedTags: true,
143
+ serviceName: `${id}-${scope.props.stage}`,
144
+ certificate: props.certificate,
145
+ cpu: props.cpu,
146
+ loadBalancerName: `${id}-${scope.props.stage}`,
147
+ domainName: props.domainName,
148
+ domainZone: props.domainZone,
149
+ listenerPort: props.listenerPort,
150
+ memoryLimitMiB: props.memoryLimitMiB,
151
+ healthCheckGracePeriod: props.healthCheckGracePeriod ?? cdk.Duration.seconds(60),
152
+ assignPublicIp: props.assignPublicIp ?? true,
153
+ taskImageOptions: {
154
+ enableLogging: props.taskImageOptions?.enableLogging ?? true,
155
+ logDriver: props.taskImageOptions?.logDriver ??
156
+ ecs.LogDriver.awsLogs({
157
+ logGroup: logGroup,
158
+ streamPrefix: `${id}-${scope.props.stage}/ecs`,
159
+ }),
160
+ image: props.taskImageOptions.image,
161
+ executionRole: props.taskImageOptions?.executionRole,
162
+ taskRole: props.taskImageOptions?.taskRole,
163
+ containerPort: props.taskImageOptions?.containerPort,
164
+ environment: props.taskImageOptions?.environment,
165
+ secrets: props.taskImageOptions?.secrets,
166
+ },
167
+ });
168
+ if (props.healthCheck) {
169
+ fargateService.targetGroup.configureHealthCheck({
170
+ enabled: props.healthCheck.enabled ?? true,
171
+ path: props.healthCheck.path ?? '/',
172
+ port: props.healthCheck.port,
173
+ interval: props.healthCheck.interval ?? cdk.Duration.seconds(props.healthCheck.intervalInSecs),
174
+ timeout: props.healthCheck.timeout ?? cdk.Duration.seconds(props.healthCheck.timeoutInSecs),
175
+ healthyThresholdCount: props.healthCheck.healthyThresholdCount,
176
+ unhealthyThresholdCount: props.healthCheck.unhealthyThresholdCount,
177
+ healthyGrpcCodes: props.healthCheck.healthyGrpcCodes,
178
+ healthyHttpCodes: props.healthCheck.healthyHttpCodes,
179
+ protocol: props.healthCheck.protocol,
180
+ });
181
+ }
182
+ return fargateService;
183
+ }
124
184
  }
125
185
  exports.EcsManager = EcsManager;
@@ -554,6 +554,13 @@ export interface EcsClusterProps extends ecs.ClusterProps {
554
554
  */
555
555
  export interface EcsTaskProps extends ecs.TaskDefinitionProps {
556
556
  }
557
+ /**
558
+ * @category cdk-utils.ecs-manager
559
+ * @subcategory Properties
560
+ */
561
+ export interface EcsApplicationLoadBalancedFargateServiceProps extends ecsPatterns.ApplicationLoadBalancedFargateServiceProps {
562
+ healthCheck?: HealthCheck;
563
+ }
557
564
  /**
558
565
  * @category cdk-utils.eks-manager
559
566
  * @subcategory Properties
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "7.4.0",
3
+ "version": "7.6.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -1,16 +1,13 @@
1
- import * as cdk from 'aws-cdk-lib'
2
1
  import * as certificateManager from 'aws-cdk-lib/aws-certificatemanager'
3
2
  import * as cloudfront from 'aws-cdk-lib/aws-cloudfront'
4
3
  import * as origins from 'aws-cdk-lib/aws-cloudfront-origins'
5
4
  import * as ec2 from 'aws-cdk-lib/aws-ec2'
6
5
  import * as ecs from 'aws-cdk-lib/aws-ecs'
7
- import * as ecsPatterns from 'aws-cdk-lib/aws-ecs-patterns'
8
6
  import * as elb from 'aws-cdk-lib/aws-elasticloadbalancingv2'
9
7
  import * as iam from 'aws-cdk-lib/aws-iam'
10
8
  import * as logs from 'aws-cdk-lib/aws-logs'
11
9
  import * as route53 from 'aws-cdk-lib/aws-route53'
12
10
  import * as s3 from 'aws-cdk-lib/aws-s3'
13
- import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
14
11
  import { Construct } from 'constructs'
15
12
  import { CommonConstruct } from '../../common'
16
13
  import { SiteWithEcsBackendProps } from '../../types'
@@ -59,7 +56,6 @@ export class SiteWithEcsBackend extends CommonConstruct {
59
56
  siteLogBucket: s3.IBucket
60
57
  siteOrigin: origins.HttpOrigin
61
58
  siteDistribution: cloudfront.Distribution
62
- siteSecretAlgolia: secretsmanager.ISecret
63
59
  siteInternalDomainName: string
64
60
  siteExternalDomainName: string
65
61
  siteDomainNames: string[]
@@ -245,48 +241,27 @@ export class SiteWithEcsBackend extends CommonConstruct {
245
241
  * @protected
246
242
  */
247
243
  protected createEcsService() {
248
- const fargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, `${this.id}-ecs-service`, {
249
- cluster: this.siteEcsCluster,
250
- desiredCount: this.props.siteTask.desiredCount,
251
- enableECSManagedTags: true,
252
- serviceName: `${this.id}-${this.props.stage}`,
253
- cpu: this.props.siteTask.cpu,
254
- loadBalancerName: `${this.id}-${this.props.stage}`,
255
- domainName: this.siteInternalDomainName,
256
- domainZone: this.siteHostedZone,
257
- listenerPort: this.props.siteTask.listenerPort,
258
- memoryLimitMiB: this.props.siteTask.memoryLimitMiB,
259
- healthCheckGracePeriod: cdk.Duration.seconds(60),
260
- assignPublicIp: true,
261
- taskImageOptions: {
262
- enableLogging: true,
263
- logDriver: ecs.LogDriver.awsLogs({
264
- logGroup: this.siteEcsLogGroup,
265
- streamPrefix: `${this.id}-${this.props.stage}/ecs`,
266
- }),
267
- image: this.siteEcsContainerImage,
268
- executionRole: this.siteEcsRole,
269
- taskRole: this.siteEcsRole,
270
- containerPort: this.props.siteTask.taskImageOptions?.containerPort,
271
- environment: this.siteEcsEnvironment,
272
- secrets: this.siteSecrets,
244
+ const fargateService = this.ecsManager.createLoadBalancedFargateService(
245
+ this.id,
246
+ this,
247
+ {
248
+ ...this.props.siteTask,
249
+ ...{
250
+ domainName: this.siteInternalDomainName,
251
+ domainZone: this.siteHostedZone,
252
+ healthCheck: this.props.siteHealthCheck,
253
+ taskImageOptions: {
254
+ environment: this.siteEcsEnvironment,
255
+ executionRole: this.siteEcsRole,
256
+ taskRole: this.siteEcsRole,
257
+ image: this.siteEcsContainerImage,
258
+ secrets: this.siteSecrets,
259
+ },
260
+ },
273
261
  },
274
- })
275
-
276
- if (this.props.siteHealthCheck) {
277
- fargateService.targetGroup.configureHealthCheck({
278
- enabled: this.props.siteHealthCheck.enabled ?? true,
279
- path: this.props.siteHealthCheck.path ?? '/',
280
- port: this.props.siteHealthCheck.port,
281
- interval: cdk.Duration.seconds(this.props.siteHealthCheck.intervalInSecs),
282
- timeout: cdk.Duration.seconds(this.props.siteHealthCheck.timeoutInSecs),
283
- healthyThresholdCount: this.props.siteHealthCheck.healthyThresholdCount,
284
- unhealthyThresholdCount: this.props.siteHealthCheck.unhealthyThresholdCount,
285
- healthyGrpcCodes: this.props.siteHealthCheck.healthyGrpcCodes,
286
- healthyHttpCodes: this.props.siteHealthCheck.healthyHttpCodes,
287
- protocol: this.props.siteHealthCheck.protocol,
288
- })
289
- }
262
+ this.siteEcsCluster,
263
+ this.siteEcsLogGroup
264
+ )
290
265
 
291
266
  this.siteEcsService = fargateService.service
292
267
  this.siteEcsTaskDefinition = fargateService.taskDefinition
@@ -1,5 +1,7 @@
1
+ import * as cdk from 'aws-cdk-lib'
1
2
  import * as ec2 from 'aws-cdk-lib/aws-ec2'
2
3
  import * as ecs from 'aws-cdk-lib/aws-ecs'
4
+ import * as ecsPatterns from 'aws-cdk-lib/aws-ecs-patterns'
3
5
  import * as iam from 'aws-cdk-lib/aws-iam'
4
6
  import * as logs from 'aws-cdk-lib/aws-logs'
5
7
  import * as common from '../../common'
@@ -117,4 +119,71 @@ export class EcsManager {
117
119
 
118
120
  return ecsTask
119
121
  }
122
+
123
+ /**
124
+ * @summary Method to create an application loadbalanced ecs fargate task
125
+ * @param {string} id scoped id of the resource
126
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
127
+ * @param {types.EcsApplicationLoadBalancedFargateServiceProps} props
128
+ * @param {ecs.ICluster} cluster
129
+ * @param {logs.ILogGroup} logGroup
130
+ */
131
+ public createLoadBalancedFargateService(
132
+ id: string,
133
+ scope: common.CommonConstruct,
134
+ props: types.EcsApplicationLoadBalancedFargateServiceProps,
135
+ cluster: ecs.ICluster,
136
+ logGroup: logs.ILogGroup
137
+ ) {
138
+ if (!props) throw `EcsLoadbalanced Fargate Serivice props undefined`
139
+ if (!props.taskImageOptions) throw `TaskImageOptions for EcsLoadbalanced Fargate Serivice props undefined`
140
+
141
+ const fargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(scope, `${id}-ecs-service`, {
142
+ cluster: cluster,
143
+ desiredCount: props.desiredCount,
144
+ enableECSManagedTags: true,
145
+ serviceName: `${id}-${scope.props.stage}`,
146
+ certificate: props.certificate,
147
+ cpu: props.cpu,
148
+ loadBalancerName: `${id}-${scope.props.stage}`,
149
+ domainName: props.domainName,
150
+ domainZone: props.domainZone,
151
+ listenerPort: props.listenerPort,
152
+ memoryLimitMiB: props.memoryLimitMiB,
153
+ healthCheckGracePeriod: props.healthCheckGracePeriod ?? cdk.Duration.seconds(60),
154
+ assignPublicIp: props.assignPublicIp ?? true,
155
+ taskImageOptions: {
156
+ enableLogging: props.taskImageOptions?.enableLogging ?? true,
157
+ logDriver:
158
+ props.taskImageOptions?.logDriver ??
159
+ ecs.LogDriver.awsLogs({
160
+ logGroup: logGroup,
161
+ streamPrefix: `${id}-${scope.props.stage}/ecs`,
162
+ }),
163
+ image: props.taskImageOptions.image,
164
+ executionRole: props.taskImageOptions?.executionRole,
165
+ taskRole: props.taskImageOptions?.taskRole,
166
+ containerPort: props.taskImageOptions?.containerPort,
167
+ environment: props.taskImageOptions?.environment,
168
+ secrets: props.taskImageOptions?.secrets,
169
+ },
170
+ })
171
+
172
+ if (props.healthCheck) {
173
+ fargateService.targetGroup.configureHealthCheck({
174
+ enabled: props.healthCheck.enabled ?? true,
175
+ path: props.healthCheck.path ?? '/',
176
+ port: props.healthCheck.port,
177
+ interval: props.healthCheck.interval ?? cdk.Duration.seconds(props.healthCheck.intervalInSecs),
178
+ timeout: props.healthCheck.timeout ?? cdk.Duration.seconds(props.healthCheck.timeoutInSecs),
179
+ healthyThresholdCount: props.healthCheck.healthyThresholdCount,
180
+ unhealthyThresholdCount: props.healthCheck.unhealthyThresholdCount,
181
+ healthyGrpcCodes: props.healthCheck.healthyGrpcCodes,
182
+ healthyHttpCodes: props.healthCheck.healthyHttpCodes,
183
+ protocol: props.healthCheck.protocol,
184
+ })
185
+ }
186
+
187
+ return fargateService
188
+ }
120
189
  }
@@ -588,6 +588,15 @@ export interface EcsClusterProps extends ecs.ClusterProps {}
588
588
  */
589
589
  export interface EcsTaskProps extends ecs.TaskDefinitionProps {}
590
590
 
591
+ /**
592
+ * @category cdk-utils.ecs-manager
593
+ * @subcategory Properties
594
+ */
595
+ export interface EcsApplicationLoadBalancedFargateServiceProps
596
+ extends ecsPatterns.ApplicationLoadBalancedFargateServiceProps {
597
+ healthCheck?: HealthCheck
598
+ }
599
+
591
600
  /**
592
601
  * @category cdk-utils.eks-manager
593
602
  * @subcategory Properties