dcl-ops-lib 7.0.0 → 8.0.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.
@@ -56,13 +56,25 @@ export type FargateTaskOptions = {
56
56
  runtimePlatform?: aws.types.input.ecs.TaskDefinitionRuntimePlatform;
57
57
  appAutoscaling?: {
58
58
  maxCapacity: number;
59
- items: {
59
+ policy?: {
60
60
  metricName: string;
61
61
  targetValue: number;
62
62
  metricDimensionValue: pulumi.Output<string>;
63
- statistic?: "Average" | "Minimum" | "Maximum";
64
- scaleOutCooldown?: number;
65
- scaleInCooldown?: number;
63
+ statistic: "Average" | "Minimum" | "Maximum";
64
+ scaleOutCooldown: number;
65
+ scaleInCooldown: number;
66
+ }[];
67
+ scheduleAction?: {
68
+ minCapacity: number;
69
+ maxCapacity: number;
70
+ /**
71
+ * Must be in one of the following formats:
72
+ * At expressions - "at(yyyy-mm-ddThh:mm:ss)"
73
+ * Rate expressions - "rate(value unit)"
74
+ * Cron expressions - "cron(fields)"
75
+ * @type {string}
76
+ */
77
+ schedule: string;
66
78
  }[];
67
79
  };
68
80
  };
@@ -117,13 +129,25 @@ export type InternalServiceOptions = {
117
129
  runtimePlatform?: aws.types.input.ecs.TaskDefinitionRuntimePlatform;
118
130
  appAutoscaling?: {
119
131
  maxCapacity: number;
120
- items: {
132
+ policy?: {
121
133
  metricName: string;
122
134
  targetValue: number;
123
135
  metricDimensionValue: pulumi.Output<string>;
124
- statistic?: "Average" | "Minimum" | "Maximum";
125
- scaleOutCooldown?: number;
126
- scaleInCooldown?: number;
136
+ statistic: "Average" | "Minimum" | "Maximum";
137
+ scaleOutCooldown: number;
138
+ scaleInCooldown: number;
139
+ }[];
140
+ scheduleAction?: {
141
+ maxCapacity: number;
142
+ minCapacity: number;
143
+ /**
144
+ * Must be in one of the following formats:
145
+ * At expressions - "at(yyyy-mm-ddThh:mm:ss)"
146
+ * Rate expressions - "rate(value unit)"
147
+ * Cron expressions - "cron(fields)"
148
+ * @type {string}
149
+ */
150
+ schedule: string;
127
151
  }[];
128
152
  };
129
153
  };
@@ -379,8 +379,12 @@ function createInternalService(config) {
379
379
  });
380
380
  }
381
381
  function setAutoscaling(service, serviceName, config) {
382
+ var _a, _b, _c;
383
+ if ((!((_a = config === null || config === void 0 ? void 0 : config.appAutoscaling) === null || _a === void 0 ? void 0 : _a.policy) && !((_b = config.appAutoscaling) === null || _b === void 0 ? void 0 : _b.scheduleAction)) || ((config === null || config === void 0 ? void 0 : config.appAutoscaling.policy) && ((_c = config.appAutoscaling) === null || _c === void 0 ? void 0 : _c.scheduleAction))) {
384
+ throw new Error("Invalid autoscaling configuration. You must provide either a policy OR a scheduleAction.");
385
+ }
382
386
  const ecsTarget = new aws.appautoscaling.Target(`ecs-target-${(0, stack_1.getStackScopedName)(serviceName)}`, {
383
- maxCapacity: config.maxCapacity,
387
+ maxCapacity: config.appAutoscaling.maxCapacity,
384
388
  minCapacity: config.desiredCount,
385
389
  resourceId: service.id.apply((id) => {
386
390
  return id.split(":").pop();
@@ -388,39 +392,55 @@ function setAutoscaling(service, serviceName, config) {
388
392
  scalableDimension: "ecs:service:DesiredCount",
389
393
  serviceNamespace: "ecs",
390
394
  });
391
- config.items.forEach((item, index) => {
392
- const CSM_ApproximateNumberOfMessagesVisible = {
393
- metricName: item.metricName,
394
- namespace: "AWS/SQS",
395
- dimensions: [
396
- {
397
- name: "QueueName",
398
- value: item.metricDimensionValue.apply((value) => {
399
- return value.split("/").pop();
400
- }),
395
+ if (config.appAutoscaling.policy) {
396
+ config.appAutoscaling.policy.forEach((item, index) => {
397
+ const CSM_ApproximateNumberOfMessagesVisible = {
398
+ metricName: item.metricName,
399
+ namespace: "AWS/SQS",
400
+ dimensions: [
401
+ {
402
+ name: "QueueName",
403
+ value: item.metricDimensionValue.apply((value) => {
404
+ return value.split("/").pop();
405
+ }),
406
+ },
407
+ ],
408
+ statistic: item.statistic,
409
+ unit: "Count",
410
+ };
411
+ let TTS_CustomizedMetricSpecification = undefined;
412
+ if (item.metricName === "ApproximateNumberOfMessagesVisible") {
413
+ TTS_CustomizedMetricSpecification =
414
+ CSM_ApproximateNumberOfMessagesVisible;
415
+ }
416
+ return new aws.appautoscaling.Policy(`ecs-autoscaling-policy-${(0, stack_1.getStackScopedName)(serviceName)}-${index.toString()}`, // distinct policies by id
417
+ {
418
+ policyType: "TargetTrackingScaling",
419
+ resourceId: ecsTarget.resourceId,
420
+ scalableDimension: pulumi.interpolate `${ecsTarget.scalableDimension}`,
421
+ serviceNamespace: "ecs",
422
+ targetTrackingScalingPolicyConfiguration: {
423
+ targetValue: item.targetValue,
424
+ customizedMetricSpecification: TTS_CustomizedMetricSpecification,
425
+ scaleOutCooldown: item.scaleOutCooldown,
426
+ scaleInCooldown: item.scaleInCooldown,
401
427
  },
402
- ],
403
- statistic: item.statistic,
404
- unit: "Count",
405
- };
406
- let TTS_CustomizedMetricSpecification = undefined;
407
- if (item.metricName === "ApproximateNumberOfMessagesVisible") {
408
- TTS_CustomizedMetricSpecification =
409
- CSM_ApproximateNumberOfMessagesVisible;
410
- }
411
- return new aws.appautoscaling.Policy(`ecs-autoscaling-policy-${(0, stack_1.getStackScopedName)(serviceName)}-${index.toString()}`, // distinct policies by id
412
- {
413
- policyType: "TargetTrackingScaling",
414
- resourceId: ecsTarget.resourceId,
415
- scalableDimension: pulumi.interpolate `${ecsTarget.scalableDimension}`,
416
- serviceNamespace: "ecs",
417
- targetTrackingScalingPolicyConfiguration: {
418
- targetValue: item.targetValue,
419
- customizedMetricSpecification: TTS_CustomizedMetricSpecification,
420
- scaleOutCooldown: item.scaleOutCooldown,
421
- scaleInCooldown: item.scaleInCooldown,
422
- },
423
- }, { dependsOn: [ecsTarget] });
424
- });
428
+ }, { dependsOn: [ecsTarget] });
429
+ });
430
+ }
431
+ else if (config.appAutoscaling.scheduleAction) {
432
+ config.appAutoscaling.scheduleAction.forEach((item, index) => {
433
+ return new aws.appautoscaling.ScheduledAction(`ecs-scheduled-action-${(0, stack_1.getStackScopedName)(serviceName)}-${index.toString()}`, {
434
+ serviceNamespace: ecsTarget.serviceNamespace,
435
+ resourceId: ecsTarget.resourceId,
436
+ scalableDimension: ecsTarget.scalableDimension,
437
+ schedule: item.schedule,
438
+ scalableTargetAction: {
439
+ minCapacity: item.minCapacity,
440
+ maxCapacity: item.maxCapacity,
441
+ },
442
+ }, { dependsOn: [ecsTarget] });
443
+ });
444
+ }
425
445
  }
426
446
  //# sourceMappingURL=createFargateTask.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dcl-ops-lib",
3
- "version": "7.0.0",
3
+ "version": "8.0.0",
4
4
  "scripts": {
5
5
  "build": "tsc && cp bin/* . && node test.js",
6
6
  "clean": "rm *.d.ts *.js *.js.map"