Skip to content

Commit

Permalink
Merge pull request #14 from pixelfusion/feat/scaling
Browse files Browse the repository at this point in the history
feat: add ability to set min capacity
  • Loading branch information
tractorcow authored May 16, 2024
2 parents fc0785d + 0156910 commit f9c72ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions dist/fargate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface TaskConfiguration {
desiredCount?: number;
autoScalingCpuTarget?: number;
maxCount?: number;
minCount?: number;
environment?: Record<string, string>;
secrets?: Record<string, string>;
}
Expand Down
6 changes: 5 additions & 1 deletion dist/fargate.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ class FargateService extends cdk.NestedStack {
if (taskConfiguration.autoScalingCpuTarget) {
// Default max capacity to double desired unless specified
const maxCapacity = taskConfiguration?.maxCount || desiredCount * 2;
const scaling = this.service.service.autoScaleTaskCount({ maxCapacity });
const minCapacity = taskConfiguration?.minCount || desiredCount;
const scaling = this.service.service.autoScaleTaskCount({
maxCapacity,
minCapacity,
});
scaling.scaleOnCpuUtilization(stack.getResourceID('CpuScaling'), {
targetUtilizationPercent: taskConfiguration.autoScalingCpuTarget,
scaleInCooldown: cdk.Duration.seconds(60),
Expand Down
7 changes: 6 additions & 1 deletion src/fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface TaskConfiguration {
desiredCount?: number
autoScalingCpuTarget?: number
maxCount?: number
minCount?: number
environment?: Record<string, string>
secrets?: Record<string, string>
}
Expand Down Expand Up @@ -132,7 +133,11 @@ export class FargateService extends cdk.NestedStack {
if (taskConfiguration.autoScalingCpuTarget) {
// Default max capacity to double desired unless specified
const maxCapacity = taskConfiguration?.maxCount || desiredCount * 2
const scaling = this.service.service.autoScaleTaskCount({ maxCapacity })
const minCapacity = taskConfiguration?.minCount || desiredCount
const scaling = this.service.service.autoScaleTaskCount({
maxCapacity,
minCapacity,
})
scaling.scaleOnCpuUtilization(stack.getResourceID('CpuScaling'), {
targetUtilizationPercent: taskConfiguration.autoScalingCpuTarget,
scaleInCooldown: cdk.Duration.seconds(60),
Expand Down

0 comments on commit f9c72ad

Please sign in to comment.