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 all 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,18 @@ export interface ScalingSchedule {
* @default No new maximum capacity
*/
readonly maxCapacity?: number;

/**
* 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;
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
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-dynamodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ Auto-scaling is only relevant for tables with the billing mode, PROVISIONED.

[Example of configuring autoscaling](test/integ.autoscaling.lit.ts)

```ts
const target = new appscaling.ScalableTarget(this, '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,
});
```

Further reading:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/AutoScaling.html
https://aws.amazon.com/blogs/database/how-to-use-aws-cloudformation-to-configure-auto-scaling-for-amazon-dynamodb-tables-and-indexes/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "21.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
"path": "IntegTestDefaultTestDeployAssertE3E7D2A4.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"21.0.0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "21.0.0",
"files": {
"3ef8d92d87ceb48dbc262f08c4d305a980d3f14ef7818a78dc506af4adae743c": {
"source": {
"path": "demo-stack.template.json",
"packaging": "file"
},
"destinations": {
"622480777524-us-east-1": {
"bucketName": "cdk-hnb659fds-assets-622480777524-us-east-1",
"objectKey": "3ef8d92d87ceb48dbc262f08c4d305a980d3f14ef7818a78dc506af4adae743c.json",
"region": "us-east-1",
"assumeRoleArn": "arn:${AWS::Partition}:iam::622480777524:role/cdk-hnb659fds-file-publishing-role-622480777524-us-east-1"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"Resources": {
"TableCD117FA1": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"KeySchema": [
{
"AttributeName": "id",
"KeyType": "HASH"
}
],
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
}
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"TargetRole12E3474B": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "application-autoscaling.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"Target3191CF44": {
"Type": "AWS::ApplicationAutoScaling::ScalableTarget",
"Properties": {
"MaxCapacity": 20,
"MinCapacity": 1,
"ResourceId": {
"Fn::Join": [
"",
[
"table/",
{
"Ref": "TableCD117FA1"
}
]
]
},
"RoleARN": {
"Fn::GetAtt": [
"TargetRole12E3474B",
"Arn"
]
},
"ScalableDimension": "dynamodb:table:ReadCapacityUnits",
"ServiceNamespace": "dynamodb",
"ScheduledActions": [
{
"ScalableTargetAction": {
"MaxCapacity": 100,
"MinCapacity": 20
},
"Schedule": "cron(10 0 * * ? *)",
"ScheduledActionName": "scheduledScaling",
"Timezone": "America/New_York"
}
]
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "21.0.0",
"testCases": {
"IntegTest/DefaultTest": {
"stacks": [
"demo-stack"
],
"assertionStack": "IntegTest/DefaultTest/DeployAssert",
"assertionStackName": "IntegTestDefaultTestDeployAssertE3E7D2A4"
}
}
}
Loading