Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(applicationautoscaling): timezone property for scheduled actions #23123

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class ScalableTarget extends Resource implements IScalableTarget {
maxCapacity: action.maxCapacity,
minCapacity: action.minCapacity,
},
timezone: action.timezone,
});
}

Expand Down Expand Up @@ -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 - No specific time zone.
bora-7 marked this conversation as resolved.
Show resolved Hide resolved
*/
readonly timezone?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't necessarily love typing this as a string, because I think we can do better, but something similar was already introduced in #17330. Can we at least have the documentation explicitly state what kind of string we're looking for here, like we do in #17330?

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,35 @@ describe('scalable target', () => {
});
});

test('add scheduled scaling with timezone support', () => {
// GIVEN
const stack = new cdk.Stack();
const target = createScalableTarget(stack);

// WHEN
target.scaleOnSchedule('ScaleUp', {
schedule: appscaling.Schedule.rate(cdk.Duration.minutes(1)),
maxCapacity: 50,
minCapacity: 1,
timezone: 'America/New_York',
bora-7 marked this conversation as resolved.
Show resolved Hide resolved
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalableTarget', {
ScheduledActions: [
{
ScalableTargetAction: {
MaxCapacity: 50,
MinCapacity: 1,
},
Schedule: 'rate(1 minute)',
ScheduledActionName: 'ScaleUp',
Timezone: 'America/New_York',
},
],
});
});

test('scheduled scaling shows warning when minute is not defined in cron', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-dynamodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ times of the day:
Auto-scaling is only relevant for tables with the billing mode, PROVISIONED.

[Example of configuring autoscaling](test/integ.autoscaling.lit.ts)
[Example of configuring the table as a scalable target](test/integ.dynamodb.scalable-target.ts)
bora-7 marked this conversation as resolved.
Show resolved Hide resolved

Further reading:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/AutoScaling.html
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as appscaling from '@aws-cdk/aws-applicationautoscaling';
import { App, Stack } from '@aws-cdk/core';
import * as integ from '@aws-cdk/integ-tests';
import { AttributeType, Table } from '../lib';

const app = new App();
const env = {
region: process.env.CDK_DEFAULT_REGION,
account: process.env.CDK_DEFAULT_ACCOUNT,
};
const stack = new Stack(app, 'demo-stack', { env });

const table = new Table(stack, 'Table', {
partitionKey: {
name: 'id',
type: AttributeType.STRING,
},
});

const target = new appscaling.ScalableTarget(stack, 'Target', {
serviceNamespace: appscaling.ServiceNamespace.DYNAMODB,
scalableDimension: 'dynamodb:table:ReadCapacityUnits',
resourceId: `table/${table.tableName}`,
minCapacity: 1,
maxCapacity: 20,
});

target.scaleOnSchedule('scheduledScaling', {
timezone: 'America/New_York',
schedule: appscaling.Schedule.cron({
hour: '0',
minute: '10',
}),
minCapacity: 20,
maxCapacity: 100,
});

new integ.IntegTest(app, 'IntegTest', {
testCases: [stack],
});

app.synth();