Skip to content

Commit

Permalink
added scheduledActionName as implemented in #22779
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Parker <parkerzr@amazon.com>
  • Loading branch information
ryparker committed Nov 25, 2022
1 parent 1953ec2 commit fabb5b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 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;
}
}
}
13 changes: 13 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ 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', {
Expand Down

0 comments on commit fabb5b2

Please sign in to comment.