Skip to content

Commit

Permalink
fix(autoscaling): add timezone property to Scheduled Action (#17330)
Browse files Browse the repository at this point in the history
Add timezone property to ScheduledAction.

example:
```typescript
import * as asg from '@aws-cdk/aws-autoscaling';

new asg.ScheduledAction(this, 'test', {
    autoScalingGroup: 'test',
    desiredCapacity: 1,
    minCapacity: 1,
    maxCapacity: 2,
    schedule: {
        expressionString: '0 3 * * *'
    },
    timeZone: 'Asia/Seoul'
});
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
eastNine authored Nov 9, 2021
1 parent bc10e6f commit 3154a58
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import { Schedule } from './schedule';
* Properties for a scheduled scaling action
*/
export interface BasicScheduledActionProps {
/**
* Specifies the time zone for a cron expression. If a time zone is not provided, UTC is used by default.
*
* Valid values are the canonical names of the IANA time zones, derived from the IANA Time Zone Database (such as Etc/GMT+9 or Pacific/Tahiti).
*
* For more information, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.
*
* @default - UTC
*
*/
readonly timeZone?: string;
/**
* When to perform this action.
*
Expand Down Expand Up @@ -94,6 +105,7 @@ export class ScheduledAction extends Resource {
maxSize: props.maxCapacity,
desiredCapacity: props.desiredCapacity,
recurrence: props.schedule.expressionString,
timeZone: props.timeZone,
});
}
}
Expand Down
21 changes: 21 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ describe('scheduled action', () => {

});

test('have timezone property', () => {
// GIVEN
const stack = new cdk.Stack();
const asg = makeAutoScalingGroup(stack);

// WHEN
asg.scaleOnSchedule('ScaleOutAtMiddaySeoul', {
schedule: autoscaling.Schedule.cron({ hour: '12', minute: '0' }),
minCapacity: 12,
timeZone: 'Asia/Seoul',
});

// THEN
expect(stack).to(haveResource('AWS::AutoScaling::ScheduledAction', {
MinSize: 12,
Recurrence: '0 12 * * *',
TimeZone: 'Asia/Seoul',
}));

});

test('autoscaling group has recommended updatepolicy for scheduled actions', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 3154a58

Please sign in to comment.