diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts index f5686e8c13170..79de6f8694b78 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts @@ -161,6 +161,7 @@ export class ScalableTarget extends Resource implements IScalableTarget { maxCapacity: action.maxCapacity, minCapacity: action.minCapacity, }, + timezone: action.timezone, }); } @@ -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; } /** diff --git a/packages/@aws-cdk/aws-applicationautoscaling/test/scalable-target.test.ts b/packages/@aws-cdk/aws-applicationautoscaling/test/scalable-target.test.ts index 09374187c8333..0793735ef6c85 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/test/scalable-target.test.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/test/scalable-target.test.ts @@ -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', + }); + + // 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(); diff --git a/packages/@aws-cdk/aws-dynamodb/README.md b/packages/@aws-cdk/aws-dynamodb/README.md index bc7ca16e5b182..eddb5beeca3d1 100644 --- a/packages/@aws-cdk/aws-dynamodb/README.md +++ b/packages/@aws-cdk/aws-dynamodb/README.md @@ -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/ diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json new file mode 100644 index 0000000000000..f1a05d45137d4 --- /dev/null +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json @@ -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": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.template.json b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "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." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/cdk.out b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/cdk.out new file mode 100644 index 0000000000000..8ecc185e9dbee --- /dev/null +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/demo-stack.assets.json b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/demo-stack.assets.json new file mode 100644 index 0000000000000..1123315c615d6 --- /dev/null +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/demo-stack.assets.json @@ -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": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/demo-stack.template.json b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/demo-stack.template.json new file mode 100644 index 0000000000000..8c689e27e95ef --- /dev/null +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/demo-stack.template.json @@ -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", + "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." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/integ.json b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/integ.json new file mode 100644 index 0000000000000..741df82d97580 --- /dev/null +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "21.0.0", + "testCases": { + "IntegTest/DefaultTest": { + "stacks": [ + "demo-stack" + ], + "assertionStack": "IntegTest/DefaultTest/DeployAssert", + "assertionStackName": "IntegTestDefaultTestDeployAssertE3E7D2A4" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/manifest.json b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/manifest.json new file mode 100644 index 0000000000000..81280166170b5 --- /dev/null +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/manifest.json @@ -0,0 +1,123 @@ +{ + "version": "21.0.0", + "artifacts": { + "demo-stack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "demo-stack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "demo-stack": { + "type": "aws:cloudformation:stack", + "environment": "aws://622480777524/us-east-1", + "properties": { + "templateFile": "demo-stack.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::622480777524:role/cdk-hnb659fds-deploy-role-622480777524-us-east-1", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::622480777524:role/cdk-hnb659fds-cfn-exec-role-622480777524-us-east-1", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-622480777524-us-east-1/3ef8d92d87ceb48dbc262f08c4d305a980d3f14ef7818a78dc506af4adae743c.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "demo-stack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::622480777524:role/cdk-hnb659fds-lookup-role-622480777524-us-east-1", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "demo-stack.assets" + ], + "metadata": { + "/demo-stack/Table/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TableCD117FA1" + } + ], + "/demo-stack/Target/Role/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TargetRole12E3474B" + } + ], + "/demo-stack/Target/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Target3191CF44" + } + ], + "/demo-stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/demo-stack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "demo-stack" + }, + "IntegTestDefaultTestDeployAssertE3E7D2A4.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "IntegTestDefaultTestDeployAssertE3E7D2A4": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "IntegTestDefaultTestDeployAssertE3E7D2A4.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "IntegTestDefaultTestDeployAssertE3E7D2A4.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "IntegTestDefaultTestDeployAssertE3E7D2A4.assets" + ], + "metadata": { + "/IntegTest/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/IntegTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "IntegTest/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/tree.json b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/tree.json new file mode 100644 index 0000000000000..9e05651822018 --- /dev/null +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.js.snapshot/tree.json @@ -0,0 +1,246 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "demo-stack": { + "id": "demo-stack", + "path": "demo-stack", + "children": { + "Table": { + "id": "Table", + "path": "demo-stack/Table", + "children": { + "Resource": { + "id": "Resource", + "path": "demo-stack/Table/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::DynamoDB::Table", + "aws:cdk:cloudformation:props": { + "keySchema": [ + { + "attributeName": "id", + "keyType": "HASH" + } + ], + "attributeDefinitions": [ + { + "attributeName": "id", + "attributeType": "S" + } + ], + "provisionedThroughput": { + "readCapacityUnits": 5, + "writeCapacityUnits": 5 + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-dynamodb.CfnTable", + "version": "0.0.0" + } + }, + "ScalingRole": { + "id": "ScalingRole", + "path": "demo-stack/Table/ScalingRole", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-dynamodb.Table", + "version": "0.0.0" + } + }, + "Target": { + "id": "Target", + "path": "demo-stack/Target", + "children": { + "Role": { + "id": "Role", + "path": "demo-stack/Target/Role", + "children": { + "ImportRole": { + "id": "ImportRole", + "path": "demo-stack/Target/Role/ImportRole", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "demo-stack/Target/Role/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "application-autoscaling.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "demo-stack/Target/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ApplicationAutoScaling::ScalableTarget", + "aws:cdk:cloudformation:props": { + "maxCapacity": 20, + "minCapacity": 1, + "resourceId": { + "Fn::Join": [ + "", + [ + "table/", + { + "Ref": "TableCD117FA1" + } + ] + ] + }, + "roleArn": { + "Fn::GetAtt": [ + "TargetRole12E3474B", + "Arn" + ] + }, + "scalableDimension": "dynamodb:table:ReadCapacityUnits", + "serviceNamespace": "dynamodb", + "scheduledActions": [ + { + "scheduledActionName": "scheduledScaling", + "schedule": "cron(10 0 * * ? *)", + "scalableTargetAction": { + "maxCapacity": 100, + "minCapacity": 20 + }, + "timezone": "America/New_York" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "demo-stack/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "demo-stack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + }, + "IntegTest": { + "id": "IntegTest", + "path": "IntegTest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "IntegTest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "IntegTest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.161" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "IntegTest/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "IntegTest/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "IntegTest/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.161" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.ts b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.ts new file mode 100644 index 0000000000000..3fb970b686e4d --- /dev/null +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.scalable-target.ts @@ -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(); \ No newline at end of file