diff --git a/packages/aws-cdk-lib/aws-applicationautoscaling/README.md b/packages/aws-cdk-lib/aws-applicationautoscaling/README.md index 6bc05ee9882f2..8c969ff38de76 100644 --- a/packages/aws-cdk-lib/aws-applicationautoscaling/README.md +++ b/packages/aws-cdk-lib/aws-applicationautoscaling/README.md @@ -178,6 +178,7 @@ scaling take over at night: ```ts declare const resource: SomeScalableResource; +declare const TimeZone: TimeZone; const capacity = resource.autoScaleCapacity({ minCapacity: 1, @@ -187,11 +188,13 @@ const capacity = resource.autoScaleCapacity({ capacity.scaleOnSchedule('PrescaleInTheMorning', { schedule: appscaling.Schedule.cron({ hour: '8', minute: '0' }), minCapacity: 20, + timeZone: TimeZone.AMERICA_DENVER, }); capacity.scaleOnSchedule('AllowDownscalingAtNight', { schedule: appscaling.Schedule.cron({ hour: '20', minute: '0' }), - minCapacity: 1 + minCapacity: 1, + timeZone: TimeZone.AMERICA_DENVER, }); ``` diff --git a/packages/aws-cdk-lib/aws-applicationautoscaling/lib/scalable-target.ts b/packages/aws-cdk-lib/aws-applicationautoscaling/lib/scalable-target.ts index fc806c27ac185..fe6fe8f31443e 100644 --- a/packages/aws-cdk-lib/aws-applicationautoscaling/lib/scalable-target.ts +++ b/packages/aws-cdk-lib/aws-applicationautoscaling/lib/scalable-target.ts @@ -4,7 +4,7 @@ import { Schedule } from './schedule'; import { BasicStepScalingPolicyProps, StepScalingPolicy } from './step-scaling-policy'; import { BasicTargetTrackingScalingPolicyProps, TargetTrackingScalingPolicy } from './target-tracking-scaling-policy'; import * as iam from '../../aws-iam'; -import { IResource, Lazy, Resource, withResolved } from '../../core'; +import { IResource, Lazy, Resource, TimeZone, withResolved } from '../../core'; export interface IScalableTarget extends IResource { /** @@ -161,6 +161,7 @@ export class ScalableTarget extends Resource implements IScalableTarget { maxCapacity: action.maxCapacity, minCapacity: action.minCapacity, }, + timezone: action.timeZone?.timezoneName, }); } @@ -225,6 +226,14 @@ export interface ScalingSchedule { * @default No new maximum capacity */ readonly maxCapacity?: number; + + /** + * The time zone used when referring to the date and time of a scheduled action, + * when the scheduled action uses an at or cron expression. + * + * @default - UTC + */ + readonly timeZone?: TimeZone; } /** diff --git a/packages/aws-cdk-lib/aws-applicationautoscaling/test/scalable-target.test.ts b/packages/aws-cdk-lib/aws-applicationautoscaling/test/scalable-target.test.ts index e6837fe329938..c5ac0cd4c5e8b 100644 --- a/packages/aws-cdk-lib/aws-applicationautoscaling/test/scalable-target.test.ts +++ b/packages/aws-cdk-lib/aws-applicationautoscaling/test/scalable-target.test.ts @@ -79,6 +79,38 @@ describe('scalable target', () => { }); }); + test('set timzone in scaleOnSchedule()', () => { + // GIVEN + const stack = new cdk.Stack(); + const target = createScalableTarget(stack); + + // WHEN + target.scaleOnSchedule('ScaleUp', { + schedule: appscaling.Schedule.cron({ + hour: '8', + day: '1', + }), + maxCapacity: 50, + minCapacity: 1, + timeZone: cdk.TimeZone.AMERICA_DENVER, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', { + ScheduledActions: [ + { + ScalableTargetAction: { + MaxCapacity: 50, + MinCapacity: 1, + }, + Schedule: 'cron(* 8 1 * ? *)', + ScheduledActionName: 'ScaleUp', + Timezone: 'America/Denver', + }, + ], + }); + }); + test('scheduled scaling shows warning when minute is not defined in cron', () => { // GIVEN const stack = new cdk.Stack();