diff --git a/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts b/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts index 83aae38fc281c..0889e759b1d1e 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts @@ -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); @@ -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), @@ -110,6 +117,8 @@ export class ScheduledAction extends Resource { recurrence: props.schedule.expressionString, timeZone: props.timeZone, }); + + this.scheduledActionName = resource.attrScheduledActionName; } } diff --git a/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts b/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts index 4c76ce3a11d08..ad721317b6a67 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts +++ b/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts @@ -154,6 +154,20 @@ describeDeprecated('scheduled action', () => { const annotations = Annotations.fromStack(stack).findWarning('*', Match.anyValue()); expect(annotations.length).toBe(0); }); + + test('ScheduledActions have a name', () => { + // GIVEN + 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) {