dcl-ops-lib 7.0.0 → 8.0.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.
@@ -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
  };
@@ -372,15 +372,18 @@ function createInternalService(config) {
372
372
  })),
373
373
  ],
374
374
  }, Object.assign(Object.assign({}, extraOpts), { dependsOn }));
375
- if (!!appAutoscaling) {
376
- setAutoscaling(service, serviceName, Object.assign(Object.assign({}, appAutoscaling), { desiredCount }));
375
+ if (appAutoscaling) {
376
+ setAutoscaling(service, serviceName, { appAutoscaling, desiredCount });
377
377
  }
378
378
  return service;
379
379
  });
380
380
  }
381
381
  function setAutoscaling(service, serviceName, config) {
382
+ if ((!config.appAutoscaling.policy && !config.appAutoscaling.scheduleAction) || (config.appAutoscaling.policy && config.appAutoscaling.scheduleAction)) {
383
+ throw new Error("Invalid autoscaling configuration. You must provide either a policy OR a scheduleAction.");
384
+ }
382
385
  const ecsTarget = new aws.appautoscaling.Target(`ecs-target-${(0, stack_1.getStackScopedName)(serviceName)}`, {
383
- maxCapacity: config.maxCapacity,
386
+ maxCapacity: config.appAutoscaling.maxCapacity,
384
387
  minCapacity: config.desiredCount,
385
388
  resourceId: service.id.apply((id) => {
386
389
  return id.split(":").pop();
@@ -388,39 +391,55 @@ function setAutoscaling(service, serviceName, config) {
388
391
  scalableDimension: "ecs:service:DesiredCount",
389
392
  serviceNamespace: "ecs",
390
393
  });
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
- }),
394
+ if (config.appAutoscaling.policy) {
395
+ config.appAutoscaling.policy.forEach((item, index) => {
396
+ const CSM_ApproximateNumberOfMessagesVisible = {
397
+ metricName: item.metricName,
398
+ namespace: "AWS/SQS",
399
+ dimensions: [
400
+ {
401
+ name: "QueueName",
402
+ value: item.metricDimensionValue.apply((value) => {
403
+ return value.split("/").pop();
404
+ }),
405
+ },
406
+ ],
407
+ statistic: item.statistic,
408
+ unit: "Count",
409
+ };
410
+ let TTS_CustomizedMetricSpecification = undefined;
411
+ if (item.metricName === "ApproximateNumberOfMessagesVisible") {
412
+ TTS_CustomizedMetricSpecification =
413
+ CSM_ApproximateNumberOfMessagesVisible;
414
+ }
415
+ return new aws.appautoscaling.Policy(`ecs-autoscaling-policy-${(0, stack_1.getStackScopedName)(serviceName)}-${index.toString()}`, // distinct policies by id
416
+ {
417
+ policyType: "TargetTrackingScaling",
418
+ resourceId: ecsTarget.resourceId,
419
+ scalableDimension: pulumi.interpolate `${ecsTarget.scalableDimension}`,
420
+ serviceNamespace: "ecs",
421
+ targetTrackingScalingPolicyConfiguration: {
422
+ targetValue: item.targetValue,
423
+ customizedMetricSpecification: TTS_CustomizedMetricSpecification,
424
+ scaleOutCooldown: item.scaleOutCooldown,
425
+ scaleInCooldown: item.scaleInCooldown,
401
426
  },
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
- });
427
+ }, { dependsOn: [ecsTarget] });
428
+ });
429
+ }
430
+ else if (config.appAutoscaling.scheduleAction) {
431
+ config.appAutoscaling.scheduleAction.forEach((item, index) => {
432
+ return new aws.appautoscaling.ScheduledAction(`ecs-scheduled-action-${(0, stack_1.getStackScopedName)(serviceName)}-${index.toString()}`, {
433
+ serviceNamespace: ecsTarget.serviceNamespace,
434
+ resourceId: ecsTarget.resourceId,
435
+ scalableDimension: ecsTarget.scalableDimension,
436
+ schedule: item.schedule,
437
+ scalableTargetAction: {
438
+ minCapacity: item.minCapacity,
439
+ maxCapacity: item.maxCapacity,
440
+ },
441
+ }, { dependsOn: [ecsTarget] });
442
+ });
443
+ }
425
444
  }
426
445
  //# 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.1",
4
4
  "scripts": {
5
5
  "build": "tsc && cp bin/* . && node test.js",
6
6
  "clean": "rm *.d.ts *.js *.js.map"