Skip to content
v2.278.0

Schedule ​

Class Stable

Schedule for scheduled scaling actions.

Example ​

ts
import { TimeZone } from 'aws-cdk-lib';
declare const resource: SomeScalableResource;

const capacity = resource.autoScaleCapacity({
  minCapacity: 1,
  maxCapacity: 50,
});

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,
  timeZone: TimeZone.AMERICA_DENVER,
});
python
from aws_cdk import TimeZone
# resource: SomeScalableResource


capacity = resource.auto_scale_capacity(
    min_capacity=1,
    max_capacity=50
)

capacity.scale_on_schedule("PrescaleInTheMorning",
    schedule=appscaling.Schedule.cron(hour="8", minute="0"),
    min_capacity=20,
    time_zone=TimeZone.AMERICA_DENVER
)

capacity.scale_on_schedule("AllowDownscalingAtNight",
    schedule=appscaling.Schedule.cron(hour="20", minute="0"),
    min_capacity=1,
    time_zone=TimeZone.AMERICA_DENVER
)
java
import software.amazon.awscdk.TimeZone;
SomeScalableResource resource;


ScalableAttribute capacity = resource.autoScaleCapacity(new Caps()
        .minCapacity(1)
        .maxCapacity(50)
        );

capacity.scaleOnSchedule("PrescaleInTheMorning", ScalingSchedule.builder()
        .schedule(Schedule.cron(CronOptions.builder().hour("8").minute("0").build()))
        .minCapacity(20)
        .timeZone(TimeZone.AMERICA_DENVER)
        .build());

capacity.scaleOnSchedule("AllowDownscalingAtNight", ScalingSchedule.builder()
        .schedule(Schedule.cron(CronOptions.builder().hour("20").minute("0").build()))
        .minCapacity(1)
        .timeZone(TimeZone.AMERICA_DENVER)
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK;
SomeScalableResource resource;


var capacity = resource.AutoScaleCapacity(new Caps {
    MinCapacity = 1,
    MaxCapacity = 50
});

capacity.ScaleOnSchedule("PrescaleInTheMorning", new ScalingSchedule {
    Schedule = Schedule.Cron(new CronOptions { Hour = "8", Minute = "0" }),
    MinCapacity = 20,
    TimeZone = TimeZone.AMERICA_DENVER
});

capacity.ScaleOnSchedule("AllowDownscalingAtNight", new ScalingSchedule {
    Schedule = Schedule.Cron(new CronOptions { Hour = "20", Minute = "0" }),
    MinCapacity = 1,
    TimeZone = TimeZone.AMERICA_DENVER
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
var resource someScalableResource


capacity := resource.autoScaleCapacity(&caps{
	minCapacity: jsii.Number(1),
	maxCapacity: jsii.Number(50),
})

capacity.scaleOnSchedule(jsii.String("PrescaleInTheMorning"), &ScalingSchedule{
	Schedule: appscaling.Schedule_Cron(&CronOptions{
		Hour: jsii.String("8"),
		Minute: jsii.String("0"),
	}),
	MinCapacity: jsii.Number(20),
	TimeZone: awscdk.TimeZone_AMERICA_DENVER(),
})

capacity.scaleOnSchedule(jsii.String("AllowDownscalingAtNight"), &ScalingSchedule{
	Schedule: appscaling.Schedule_*Cron(&CronOptions{
		Hour: jsii.String("20"),
		Minute: jsii.String("0"),
	}),
	MinCapacity: jsii.Number(1),
	TimeZone: awscdk.TimeZone_AMERICA_DENVER(),
})

Initializer ​

ts
new Schedule()
python
Schedule()
java
new Schedule()
csharp
new Schedule()
go
NewSchedule()

Properties ​

expressionStringstringexpression_stringstrexpressionStringStringExpressionStringstringExpressionString*string #
Retrieve the expression for this schedule.

Methods ​

at(moment: date): Schedule // chainable@staticmethod def at(moment: datetime) -> Schedulepublic static Schedule at(Instant moment)public static Schedule At(DateTime moment)func At(Moment *time.Time) Schedule static #
Construct a Schedule from a moment in time.
cron(options: CronOptions): Schedule // chainable@staticmethod def cron(options: CronOptions) -> Schedulepublic static Schedule cron(CronOptions options)public static Schedule Cron(CronOptions options)func Cron(Options CronOptions) Schedule static #
Create a schedule from a set of cron fields.
expression(expression: string): Schedule // chainable@staticmethod def expression(expression: str) -> Schedulepublic static Schedule expression(String expression)public static Schedule Expression(string expression)func Expression(Expression *string) Schedule static #
Construct a schedule from a literal schedule expression.
1 parameter

Parameters

  • expressionexpressionexpressionexpressionExpression — The expression to use.
rate(duration: Duration): Schedule // chainable@staticmethod def rate(duration: Duration) -> Schedulepublic static Schedule rate(Duration duration)public static Schedule Rate(Duration duration)func Rate(Duration Duration) Schedule static #
Construct a schedule from an interval and a time unit.