@gradientedge/cdk-utils 8.41.0 → 8.43.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.
@@ -271,6 +271,31 @@ class SiteWithEcsBackend extends common_1.CommonConstruct {
271
271
  this.siteEcsLoadBalancer = fargateService.loadBalancer;
272
272
  this.siteEcsTargetGroup = fargateService.targetGroup;
273
273
  fargateService.loadBalancer.logAccessLogs(this.siteLogBucket, 'alb');
274
+ if (this.props.siteTask.siteScaling) {
275
+ const scalableTaskCount = this.siteEcsService.autoScaleTaskCount({
276
+ minCapacity: this.props.siteTask.siteScaling.minCapacity,
277
+ maxCapacity: this.props.siteTask.siteScaling.maxCapacity ?? 4,
278
+ });
279
+ if (this.props.siteTask.siteScaling.scaleOnCpuUtilization) {
280
+ scalableTaskCount.scaleOnCpuUtilization(`${this.id}-cpu-scaling`, {
281
+ targetUtilizationPercent: this.props.siteTask.siteScaling.scaleOnCpuUtilization ?? 50,
282
+ });
283
+ }
284
+ if (this.props.siteTask.siteScaling.scaleOnMemoryUtilization) {
285
+ scalableTaskCount.scaleOnMemoryUtilization(`${this.id}-mem-scaling`, {
286
+ targetUtilizationPercent: this.props.siteTask.siteScaling.scaleOnMemoryUtilization ?? 50,
287
+ });
288
+ }
289
+ if (this.props.siteTask.siteScaling.scaleOnRequestsPerTarget) {
290
+ scalableTaskCount.scaleOnRequestCount(`${this.id}-req-count`, {
291
+ requestsPerTarget: this.props.siteTask.siteScaling.scaleOnRequestsPerTarget ?? 10000,
292
+ targetGroup: this.siteEcsTargetGroup,
293
+ });
294
+ }
295
+ if (this.props.siteTask.siteScaling.scaleOnSchedule) {
296
+ scalableTaskCount.scaleOnSchedule(`${this.id}-schedule`, this.props.siteTask.siteScaling.scaleOnSchedule);
297
+ }
298
+ }
274
299
  /* if enabled, add efs with access point and mount */
275
300
  if (this.props.siteFileSystem) {
276
301
  this.siteFileSystem = this.efsManager.createFileSystem(`${this.id}-fs`, this, this.props.siteFileSystem, this.siteVpc, this.props.siteFileSystemAccessPoints);
@@ -51,7 +51,7 @@ export declare class S3Manager {
51
51
  * @param {string} bucketName the bucket name
52
52
  * @private
53
53
  */
54
- protected static determineBucketName(scope: common.CommonConstruct, bucketName: string): string;
54
+ static determineBucketName(scope: common.CommonConstruct, bucketName: string): string;
55
55
  /**
56
56
  * @summary Method to create a s3 bucket
57
57
  * @param {string} id scoped id of the resource
@@ -28,6 +28,7 @@ import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
28
28
  import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
29
29
  import * as wafv2 from 'aws-cdk-lib/aws-wafv2';
30
30
  import * as types from '../index';
31
+ import * as appAutoscaling from 'aws-cdk-lib/aws-applicationautoscaling';
31
32
  /**
32
33
  * @category cdk-utils.app-config-manager
33
34
  * @subcategory Properties
@@ -621,6 +622,14 @@ export interface EcsClusterProps extends ecs.ClusterProps {
621
622
  export interface EcsTaskProps extends ecs.TaskDefinitionProps {
622
623
  logging?: ecs.AwsLogDriverProps;
623
624
  }
625
+ export interface EcsScalingProps {
626
+ minCapacity?: number;
627
+ maxCapacity?: number;
628
+ scaleOnCpuUtilization?: number;
629
+ scaleOnMemoryUtilization?: number;
630
+ scaleOnRequestsPerTarget?: number;
631
+ scaleOnSchedule?: appAutoscaling.ScalingSchedule;
632
+ }
624
633
  /**
625
634
  * @category cdk-utils.ecs-manager
626
635
  * @subcategory Properties
@@ -629,6 +638,7 @@ export interface EcsApplicationLoadBalancedFargateServiceProps extends ecsPatter
629
638
  healthCheck?: HealthCheck;
630
639
  logging?: ecs.AwsLogDriverProps;
631
640
  mountPoints?: ecs.MountPoint[];
641
+ siteScaling?: EcsScalingProps;
632
642
  }
633
643
  /**
634
644
  * @category cdk-utils.eks-manager
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "8.41.0",
3
+ "version": "8.43.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -36,7 +36,7 @@
36
36
  "prettier": "npx prettier --cache --check \"**/*.{ts,json,md}\"",
37
37
  "prettify": "npx prettier --cache --write \"**/*.{ts,json,md}\"",
38
38
  "test": "npx rimraf coverage && npx jest --ci --maxWorkers=100%",
39
- "update:deps": "ncu -u --deep",
39
+ "update:deps": "ncu -u --deep --reject react,react-dom",
40
40
  "validate": "pnpm prettier && pnpm test"
41
41
  },
42
42
  "husky": {
@@ -48,9 +48,9 @@
48
48
  "@types/lodash": "^4.14.192",
49
49
  "@types/node": "^18.15.11",
50
50
  "app-root-path": "^3.1.0",
51
- "aws-cdk-lib": "^2.72.0",
52
- "@aws-sdk/client-secrets-manager": "^3.301.0",
53
- "constructs": "^10.1.296",
51
+ "aws-cdk-lib": "^2.72.1",
52
+ "@aws-sdk/client-secrets-manager": "^3.303.0",
53
+ "constructs": "^10.1.300",
54
54
  "lodash": "^4.17.21",
55
55
  "moment": "^2.29.4",
56
56
  "nconf": "^0.12.0",
@@ -58,12 +58,13 @@
58
58
  "ts-node": "^10.9.1"
59
59
  },
60
60
  "devDependencies": {
61
+ "@babel/core": "^7.21.4",
62
+ "@babel/eslint-parser": "^7.21.3",
61
63
  "@babel/plugin-proposal-class-properties": "^7.18.6",
62
64
  "@types/jest": "^29.5.0",
63
65
  "@typescript-eslint/eslint-plugin": "^5.57.0",
64
66
  "@typescript-eslint/parser": "^5.57.0",
65
- "aws-cdk": "^2.72.0",
66
- "babel-eslint": "^10.1.0",
67
+ "aws-cdk": "^2.72.1",
67
68
  "better-docs": "^2.7.2",
68
69
  "codecov": "^3.8.3",
69
70
  "commitizen": "^4.3.0",
@@ -81,14 +82,13 @@
81
82
  "prettier": "^2.8.7",
82
83
  "prettier-plugin-organize-imports": "^3.2.2",
83
84
  "rimraf": "^4.4.1",
84
- "semantic-release": "^21.0.0",
85
+ "semantic-release": "^21.0.1",
85
86
  "taffydb": "^2.7.3",
86
- "ts-jest": "^29.0.5",
87
+ "ts-jest": "^29.1.0",
87
88
  "ts-node": "^10.9.1",
88
- "typescript": "5.0.2"
89
+ "typescript": "5.0.3"
89
90
  },
90
91
  "optionalDependencies": {
91
- "@babel/core": "^7.21.00",
92
92
  "prop-types": "^15.8.1",
93
93
  "react": "^17.0.0",
94
94
  "react-dom": "^17.0.0"
@@ -298,6 +298,36 @@ export class SiteWithEcsBackend extends CommonConstruct {
298
298
 
299
299
  fargateService.loadBalancer.logAccessLogs(this.siteLogBucket, 'alb')
300
300
 
301
+ if (this.props.siteTask.siteScaling) {
302
+ const scalableTaskCount = this.siteEcsService.autoScaleTaskCount({
303
+ minCapacity: this.props.siteTask.siteScaling.minCapacity,
304
+ maxCapacity: this.props.siteTask.siteScaling.maxCapacity ?? 4,
305
+ })
306
+
307
+ if (this.props.siteTask.siteScaling.scaleOnCpuUtilization) {
308
+ scalableTaskCount.scaleOnCpuUtilization(`${this.id}-cpu-scaling`, {
309
+ targetUtilizationPercent: this.props.siteTask.siteScaling.scaleOnCpuUtilization ?? 50,
310
+ })
311
+ }
312
+
313
+ if (this.props.siteTask.siteScaling.scaleOnMemoryUtilization) {
314
+ scalableTaskCount.scaleOnMemoryUtilization(`${this.id}-mem-scaling`, {
315
+ targetUtilizationPercent: this.props.siteTask.siteScaling.scaleOnMemoryUtilization ?? 50,
316
+ })
317
+ }
318
+
319
+ if (this.props.siteTask.siteScaling.scaleOnRequestsPerTarget) {
320
+ scalableTaskCount.scaleOnRequestCount(`${this.id}-req-count`, {
321
+ requestsPerTarget: this.props.siteTask.siteScaling.scaleOnRequestsPerTarget ?? 10000,
322
+ targetGroup: this.siteEcsTargetGroup,
323
+ })
324
+ }
325
+
326
+ if (this.props.siteTask.siteScaling.scaleOnSchedule) {
327
+ scalableTaskCount.scaleOnSchedule(`${this.id}-schedule`, this.props.siteTask.siteScaling.scaleOnSchedule)
328
+ }
329
+ }
330
+
301
331
  /* if enabled, add efs with access point and mount */
302
332
  if (this.props.siteFileSystem) {
303
333
  this.siteFileSystem = this.efsManager.createFileSystem(
@@ -86,7 +86,7 @@ export class S3Manager {
86
86
  * @param {string} bucketName the bucket name
87
87
  * @private
88
88
  */
89
- protected static determineBucketName(scope: common.CommonConstruct, bucketName: string) {
89
+ public static determineBucketName(scope: common.CommonConstruct, bucketName: string) {
90
90
  const sanitisedBucketName = scope.props.excludeDomainNameForBuckets
91
91
  ? S3Manager.determineBucketNameByAccountAndRegion(scope, bucketName)
92
92
  : S3Manager.determineBucketNameByDomainName(scope, bucketName)
@@ -28,6 +28,7 @@ import * as sfn from 'aws-cdk-lib/aws-stepfunctions'
28
28
  import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks'
29
29
  import * as wafv2 from 'aws-cdk-lib/aws-wafv2'
30
30
  import * as types from '../index'
31
+ import * as appAutoscaling from 'aws-cdk-lib/aws-applicationautoscaling'
31
32
 
32
33
  /**
33
34
  * @category cdk-utils.app-config-manager
@@ -659,6 +660,15 @@ export interface EcsTaskProps extends ecs.TaskDefinitionProps {
659
660
  logging?: ecs.AwsLogDriverProps
660
661
  }
661
662
 
663
+ export interface EcsScalingProps {
664
+ minCapacity?: number
665
+ maxCapacity?: number
666
+ scaleOnCpuUtilization?: number
667
+ scaleOnMemoryUtilization?: number
668
+ scaleOnRequestsPerTarget?: number
669
+ scaleOnSchedule?: appAutoscaling.ScalingSchedule
670
+ }
671
+
662
672
  /**
663
673
  * @category cdk-utils.ecs-manager
664
674
  * @subcategory Properties
@@ -668,6 +678,7 @@ export interface EcsApplicationLoadBalancedFargateServiceProps
668
678
  healthCheck?: HealthCheck
669
679
  logging?: ecs.AwsLogDriverProps
670
680
  mountPoints?: ecs.MountPoint[]
681
+ siteScaling?: EcsScalingProps
671
682
  }
672
683
 
673
684
  /**