Skip to content

Commit

Permalink
added scheduledActionName as implemented in #22779
Browse files Browse the repository at this point in the history
Also updated test by replacing the deprecated option  `updateType` with `updatePolicy`.
  • Loading branch information
ryparker committed Nov 26, 2022
1 parent 2b4207b commit a0dee3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
12 changes: 10 additions & 2 deletions packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ export interface ScheduledActionProps extends BasicScheduledActionProps {
* Define a scheduled scaling action
*/
export class ScheduledAction extends Resource {
/**
* The name of the scheduled action.
*
* @attribute
*/
public readonly scheduledActionName: string;

constructor(scope: Construct, id: string, props: ScheduledActionProps) {
super(scope, id);

Expand All @@ -100,7 +107,7 @@ export class ScheduledAction extends Resource {
// add a warning on synth when minute is not defined in a cron schedule
props.schedule._bind(this);

new CfnScheduledAction(this, 'Resource', {
const resource = new CfnScheduledAction(this, 'Resource', {
autoScalingGroupName: props.autoScalingGroup.autoScalingGroupName,
startTime: formatISO(props.startTime),
endTime: formatISO(props.endTime),
Expand All @@ -110,6 +117,7 @@ export class ScheduledAction extends Resource {
recurrence: props.schedule.expressionString,
timeZone: props.timeZone,
});
this.scheduledActionName = resource.attrScheduledActionName;
}
}

Expand All @@ -130,4 +138,4 @@ function formatISO(date?: Date) {
}
return num;
}
}
}
17 changes: 14 additions & 3 deletions packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ describeDeprecated('scheduled action', () => {
},
UpdatePolicy: {
AutoScalingRollingUpdate: {
WaitOnResourceSignals: false,
PauseTime: 'PT0S',
SuspendProcesses: [
'HealthCheck',
'ReplaceUnhealthy',
Expand Down Expand Up @@ -156,12 +154,25 @@ describeDeprecated('scheduled action', () => {
});
});

test('ScheduledActions have a name', () => {
const stack = new cdk.Stack();
const asg = makeAutoScalingGroup(stack);

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

expect(action.scheduledActionName).toBeDefined();
});

function makeAutoScalingGroup(scope: constructs.Construct) {
const vpc = new ec2.Vpc(scope, 'VPC');
return new autoscaling.AutoScalingGroup(scope, 'ASG', {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: new ec2.AmazonLinuxImage(),
updateType: autoscaling.UpdateType.ROLLING_UPDATE,
updatePolicy: autoscaling.UpdatePolicy.rollingUpdate(),
});
}

0 comments on commit a0dee3b

Please sign in to comment.