From d1dddb4228d1201bad506a46bfd3a14bcaa6e5da Mon Sep 17 00:00:00 2001 From: Otavio Macedo <288203+otaviomacedo@users.noreply.github.com> Date: Fri, 4 Nov 2022 15:03:13 +0000 Subject: [PATCH] chore(autoscaling): added scheduledActionName CFN attribute as a property (#22779) Addressing the awslint rule that requires that resources must represent all cloudformation attributes as attribute properties. ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-autoscaling/lib/scheduled-action.ts | 11 ++++++++++- .../aws-autoscaling/test/scheduled-action.test.ts | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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) {