Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scheduler): schedule not added to group with unspecified name #27927

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/group.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';
import * as iam from 'aws-cdk-lib/aws-iam';
import { CfnScheduleGroup } from 'aws-cdk-lib/aws-scheduler';
import { Arn, ArnFormat, Aws, IResource, PhysicalName, RemovalPolicy, Resource, Stack } from 'aws-cdk-lib/core';
import { Arn, ArnFormat, Aws, IResource, Names, RemovalPolicy, Resource, Stack } from 'aws-cdk-lib/core';
import { Construct } from 'constructs';

export interface GroupProps {
Expand Down Expand Up @@ -338,21 +338,23 @@ export class Group extends GroupBase {
public readonly groupArn: string;

public constructor(scope: Construct, id: string, props: GroupProps) {
super(scope, id, {
physicalName: props.groupName ?? PhysicalName.GENERATE_IF_NEEDED,
super(scope, id);

this.groupName = props.groupName ?? Names.uniqueResourceName(this, {
maxLength: 64,
separator: '-',
});

const group = new CfnScheduleGroup(this, 'Resource', {
name: this.physicalName,
name: this.groupName,
});

group.applyRemovalPolicy(props.removalPolicy);

this.groupArn = this.getResourceArnAttribute(group.attrArn, {
service: 'scheduler',
resource: 'schedule-group',
resourceName: this.physicalName,
resourceName: this.groupName,
});
this.groupName = this.physicalName;
}
}
}
27 changes: 26 additions & 1 deletion packages/@aws-cdk/aws-scheduler-alpha/test/group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@ describe('Schedule Group', () => {
});
});

test('adds schedules to the group with unspecified name', () => {
const group = new Group(stack, 'TestGroup', {});
const role = iam.Role.fromRoleArn(stack, 'ImportedRole', 'arn:aws:iam::123456789012:role/someRole');

const schedule1 = new Schedule(stack, 'MyScheduleDummy1', {
schedule: expr,
group: group,
target: new SomeLambdaTarget(func, role),
});
const schedule2 = new Schedule(stack, 'MyScheduleDummy2', {
schedule: expr,
group: group,
target: new SomeLambdaTarget(func, role),
});

expect(schedule1.group).toEqual(group);
expect(schedule2.group).toEqual(group);

Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
Properties: {
GroupName: group.groupName,
},
});
});

test('grantReadSchedules', () => {
// GIVEN
const props: GroupProps = {
Expand Down Expand Up @@ -285,4 +310,4 @@ describe('Schedule Group', () => {
Namespace: 'AWS/Scheduler',
});
});
});
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@
]
}
},
"NamedGroupA3ABC879": {
"Type": "AWS::Scheduler::ScheduleGroup",
"Properties": {
"Name": "TestGroup"
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"UnnamedGroupBE3E48EE": {
"Type": "AWS::Scheduler::ScheduleGroup",
"Properties": {
"Name": "awscdkschedulerschedule-UnnamedGroup-97DBE50D"
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"DefaultSchedule597B0B2C": {
"Type": "AWS::Scheduler::Schedule",
"Properties": {
Expand Down Expand Up @@ -128,6 +144,68 @@
}
}
},
"NamedGroupScheduleD7EEFEBC": {
"Type": "AWS::Scheduler::Schedule",
"Properties": {
"FlexibleTimeWindow": {
"Mode": "OFF"
},
"GroupName": "TestGroup",
"ScheduleExpression": "rate(12 hours)",
"ScheduleExpressionTimezone": "Etc/UTC",
"State": "ENABLED",
"Target": {
"Arn": {
"Fn::GetAtt": [
"Function76856677",
"Arn"
]
},
"Input": "\"Input Text\"",
"RetryPolicy": {
"MaximumEventAgeInSeconds": 180,
"MaximumRetryAttempts": 3
},
"RoleArn": {
"Fn::GetAtt": [
"Role1ABCC5F0",
"Arn"
]
}
}
}
},
"UnnamedGroupSchedule19260E9B": {
"Type": "AWS::Scheduler::Schedule",
"Properties": {
"FlexibleTimeWindow": {
"Mode": "OFF"
},
"GroupName": "awscdkschedulerschedule-UnnamedGroup-97DBE50D",
"ScheduleExpression": "rate(12 hours)",
"ScheduleExpressionTimezone": "Etc/UTC",
"State": "ENABLED",
"Target": {
"Arn": {
"Fn::GetAtt": [
"Function76856677",
"Arn"
]
},
"Input": "\"Input Text\"",
"RetryPolicy": {
"MaximumEventAgeInSeconds": 180,
"MaximumRetryAttempts": 3
},
"RoleArn": {
"Fn::GetAtt": [
"Role1ABCC5F0",
"Arn"
]
}
}
}
},
"DisabledScheduleA1DF7F0F": {
"Type": "AWS::Scheduler::Schedule",
"Properties": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading