diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/group.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/group.ts deleted file mode 100644 index 061272a3abffd..0000000000000 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/group.ts +++ /dev/null @@ -1,367 +0,0 @@ -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, Names, RemovalPolicy, Resource, Stack } from 'aws-cdk-lib/core'; -import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource'; -import { Construct } from 'constructs'; - -export interface GroupProps { - /** - * The name of the schedule group. - * - * Up to 64 letters (uppercase and lowercase), numbers, hyphens, underscores and dots are allowed. - * - * @default - A unique name will be generated - */ - readonly groupName?: string; - - /** - * The removal policy for the group. If the group is removed also all schedules are removed. - * - * @default RemovalPolicy.RETAIN - */ - readonly removalPolicy?: RemovalPolicy; -} - -export interface IGroup extends IResource { - /** - * The name of the schedule group - * - * @attribute - */ - readonly groupName: string; - - /** - * The arn of the schedule group - * - * @attribute - */ - readonly groupArn: string; - - /** - * Return the given named metric for this group schedules - * - * @default - sum over 5 minutes - */ - metric(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric; - - /** - * Metric for the number of invocations that were throttled because it exceeds your service quotas. - * - * @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/scheduler-quotas.html - * - * @default - sum over 5 minutes - */ - metricThrottled(props?: cloudwatch.MetricOptions): cloudwatch.Metric; - - /** - * Metric for all invocation attempts. - * - * @default - sum over 5 minutes - */ - metricAttempts(props?: cloudwatch.MetricOptions): cloudwatch.Metric; - - /** - * Emitted when the target returns an exception after EventBridge Scheduler calls the target API. - * - * @default - sum over 5 minutes - */ - metricTargetErrors(props?: cloudwatch.MetricOptions): cloudwatch.Metric; - - /** - * Metric for invocation failures due to API throttling by the target. - * - * @default - sum over 5 minutes - */ - metricTargetThrottled(props?: cloudwatch.MetricOptions): cloudwatch.Metric; - - /** - * Metric for dropped invocations when EventBridge Scheduler stops attempting to invoke the target after a schedule's retry policy has been exhausted. - * - * @default - sum over 5 minutes - */ - metricDropped(props?: cloudwatch.MetricOptions): cloudwatch.Metric; - - /** - * Metric for invocations delivered to the DLQ - * - * @default - sum over 5 minutes - */ - metricSentToDLQ(props?: cloudwatch.MetricOptions): cloudwatch.Metric; - - /** - * Metric for failed invocations that also failed to deliver to DLQ. - * - * @default - sum over 5 minutes - */ - metricFailedToBeSentToDLQ(errorCode?: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric; - - /** - * Metric for delivery of failed invocations to DLQ when the payload of the event sent to the DLQ exceeds the maximum size allowed by Amazon SQS. - * - * @default - sum over 5 minutes - */ - metricSentToDLQTruncated(props?: cloudwatch.MetricOptions): cloudwatch.Metric; - - /** - * Grant the indicated permissions on this group to the given principal - */ - grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant; - /** - * Grant list and get schedule permissions for schedules in this group to the given principal - */ - grantReadSchedules(identity: iam.IGrantable): iam.Grant; - /** - * Grant create and update schedule permissions for schedules in this group to the given principal - */ - grantWriteSchedules(identity: iam.IGrantable): iam.Grant; - /** - * Grant delete schedule permission for schedules in this group to the given principal - */ - grantDeleteSchedules(identity: iam.IGrantable): iam.Grant; -} - -abstract class GroupBase extends Resource implements IGroup { - /** - * The name of the schedule group - * - * @attribute - */ - public abstract readonly groupName: string; - - /** - * The arn of the schedule group - * - * @attribute - */ - public abstract readonly groupArn: string; - - /** - * Return the given named metric for this group schedules - * - * @default - sum over 5 minutes - */ - public metric(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric { - return new cloudwatch.Metric({ - namespace: 'AWS/Scheduler', - metricName, - dimensionsMap: { ScheduleGroup: this.groupName }, - statistic: 'sum', - ...props, - }).attachTo(this); - } - - /** - * Metric for the number of invocations that were throttled because it exceeds your service quotas. - * - * @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/scheduler-quotas.html - * - * @default - sum over 5 minutes - */ - public metricThrottled(props?: cloudwatch.MetricOptions): cloudwatch.Metric { - return this.metric('InvocationThrottleCount', props); - } - - /** - * Metric for all invocation attempts. - * - * @default - sum over 5 minutes - */ - public metricAttempts(props?: cloudwatch.MetricOptions): cloudwatch.Metric { - return this.metric('InvocationAttemptCount', props); - } - - /** - * Emitted when the target returns an exception after EventBridge Scheduler calls the target API. - * - * @default - sum over 5 minutes - */ - public metricTargetErrors(props?: cloudwatch.MetricOptions): cloudwatch.Metric { - return this.metric('TargetErrorCount', props); - } - - /** - * Metric for invocation failures due to API throttling by the target. - * - * @default - sum over 5 minutes - */ - public metricTargetThrottled(props?: cloudwatch.MetricOptions): cloudwatch.Metric { - return this.metric('TargetErrorThrottledCount', props); - } - - /** - * Metric for dropped invocations when EventBridge Scheduler stops attempting to invoke the target after a schedule's retry policy has been exhausted. - * - * @default - sum over 5 minutes - */ - public metricDropped(props?: cloudwatch.MetricOptions): cloudwatch.Metric { - return this.metric('InvocationDroppedCount', props); - } - - /** - * Metric for invocations delivered to the DLQ - * - * @default - sum over 5 minutes - */ - public metricSentToDLQ(props?: cloudwatch.MetricOptions): cloudwatch.Metric { - return this.metric('InvocationsSentToDeadLetterCount', props); - } - - /** - * Metric for failed invocations that also failed to deliver to DLQ. - * - * @default - sum over 5 minutes - */ - public metricFailedToBeSentToDLQ(errorCode?: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric { - if (errorCode) { - return this.metric(`InvocationsFailedToBeSentToDeadLetterCount_${errorCode}`, props); - } - - return this.metric('InvocationsFailedToBeSentToDeadLetterCount', props); - } - - /** - * Metric for delivery of failed invocations to DLQ when the payload of the event sent to the DLQ exceeds the maximum size allowed by Amazon SQS. - * - * @default - sum over 5 minutes - */ - public metricSentToDLQTruncated(props?: cloudwatch.MetricOptions): cloudwatch.Metric { - return this.metric('InvocationsSentToDeadLetterCount_Truncated_MessageSizeExceeded', props); - } - - /** - * Grant the indicated permissions on this group to the given principal - */ - public grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant { - return iam.Grant.addToPrincipal({ - grantee, - actions, - resourceArns: [this.groupArn], - scope: this, - }); - } - - private arnForScheduleInGroup(scheduleName: string): string { - return Arn.format({ - region: this.env.region, - account: this.env.account, - partition: Aws.PARTITION, - service: 'scheduler', - resource: 'schedule', - resourceName: this.groupName + '/' + scheduleName, - }); - } - - /** - * Grant list and get schedule permissions for schedules in this group to the given principal - */ - public grantReadSchedules(identity: iam.IGrantable) { - return iam.Grant.addToPrincipal({ - grantee: identity, - actions: ['scheduler:GetSchedule', 'scheduler:ListSchedules'], - resourceArns: [this.arnForScheduleInGroup('*')], - scope: this, - }); - } - - /** - * Grant create and update schedule permissions for schedules in this group to the given principal - */ - public grantWriteSchedules(identity: iam.IGrantable): iam.Grant { - return iam.Grant.addToPrincipal({ - grantee: identity, - actions: ['scheduler:CreateSchedule', 'scheduler:UpdateSchedule'], - resourceArns: [this.arnForScheduleInGroup('*')], - scope: this, - }); - } - - /** - * Grant delete schedule permission for schedules in this group to the given principal - */ - public grantDeleteSchedules(identity: iam.IGrantable): iam.Grant { - return iam.Grant.addToPrincipal({ - grantee: identity, - actions: ['scheduler:DeleteSchedule'], - resourceArns: [this.arnForScheduleInGroup('*')], - scope: this, - }); - } -} -/** - * @resource AWS::Scheduler::ScheduleGroup - * @deprecated Use `ScheduleGroup` instead. `Group` will be removed when this module is stabilized. - */ -export class Group extends GroupBase { - /** - * Import an external group by ARN. - * - * @param scope construct scope - * @param id construct id - * @param groupArn the ARN of the group to import (e.g. `arn:aws:scheduler:region:account-id:schedule-group/group-name`) - * @deprecated Use `ScheduleGroup.fromScheduleGroupArn()` instead. - */ - public static fromGroupArn(scope: Construct, id: string, groupArn: string): IGroup { - const arnComponents = Stack.of(scope).splitArn(groupArn, ArnFormat.SLASH_RESOURCE_NAME); - const groupName = arnComponents.resourceName!; - class Import extends GroupBase { - groupName = groupName; - groupArn = groupArn; - } - return new Import(scope, id); - } - - /** - * Import a default schedule group. - * - * @param scope construct scope - * @param id construct id - * @deprecated Use `ScheduleGroup.fromDefaultScheduleGroup()` instead. - */ - public static fromDefaultGroup(scope: Construct, id: string): IGroup { - return Group.fromGroupName(scope, id, 'default'); - } - - /** - * Import an existing group with a given name. - * - * @param scope construct scope - * @param id construct id - * @param groupName the name of the existing group to import - * @deprecated Use `ScheduleGroup.fromScheduleGroupName()` instead. - */ - public static fromGroupName(scope: Construct, id: string, groupName: string): IGroup { - const groupArn = Stack.of(scope).formatArn({ - service: 'scheduler', - resource: 'schedule-group', - resourceName: groupName, - }); - return Group.fromGroupArn(scope, id, groupArn); - } - - public readonly groupName: string; - public readonly groupArn: string; - - public constructor(scope: Construct, id: string, props?: GroupProps) { - super(scope, id); - // Enhanced CDK Analytics Telemetry - addConstructMetadata(this, props); - - this.groupName = props?.groupName ?? Names.uniqueResourceName(this, { - maxLength: 64, - separator: '-', - }); - - const group = new CfnScheduleGroup(this, 'Resource', { - name: this.groupName, - }); - - group.applyRemovalPolicy(props?.removalPolicy); - - this.groupArn = this.getResourceArnAttribute(group.attrArn, { - service: 'scheduler', - resource: 'schedule-group', - resourceName: this.groupName, - }); - } -} diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/index.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/index.ts index 542063013983c..2138faaff6857 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/index.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/index.ts @@ -1,6 +1,5 @@ export * from './schedule-expression'; export * from './input'; export * from './schedule'; -export * from './group'; export * from './target'; export * from './schedule-group'; diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index 87337d446dbed..3c0ccbd22c2e3 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -4,7 +4,6 @@ import * as kms from 'aws-cdk-lib/aws-kms'; import { CfnSchedule } from 'aws-cdk-lib/aws-scheduler'; import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource'; import { Construct } from 'constructs'; -import { IGroup } from './group'; import { ScheduleExpression } from './schedule-expression'; import { IScheduleGroup } from './schedule-group'; import { IScheduleTarget } from './target'; @@ -29,12 +28,6 @@ export interface ISchedule extends IResource { * The schedule group associated with this schedule. */ readonly scheduleGroup?: IScheduleGroup; - - /** - * The schedule group associated with this schedule. - * @deprecated Use `scheduleGroup` instead. `group` will be removed when this module is stabilized. - */ - readonly group?: IGroup; } /** @@ -109,14 +102,6 @@ export interface ScheduleProps { */ readonly description?: string; - /** - * The schedule's group. - * - * @default - By default a schedule will be associated with the `default` group. - * @deprecated Use `scheduleGroup` instead. `group` will be removed when this module is stabilized. - */ - readonly group?: IGroup; - /** * The schedule's group. * @@ -272,12 +257,6 @@ export class Schedule extends Resource implements ISchedule { return new Import(scope, id); } - /** - * The schedule group associated with this schedule. - * @deprecated Use `scheduleGroup` instead. `group` will be removed when this module is stabilized. - */ - public readonly group?: IGroup; - /** * The schedule group associated with this schedule. */ @@ -310,7 +289,6 @@ export class Schedule extends Resource implements ISchedule { // Enhanced CDK Analytics Telemetry addConstructMetadata(this, props); - this.group = props.group; this.scheduleGroup = props.scheduleGroup; const targetConfig = props.target.bind(this); @@ -337,7 +315,7 @@ export class Schedule extends Resource implements ISchedule { }, scheduleExpression: props.schedule.expressionString, scheduleExpressionTimezone: props.schedule.timeZone?.timezoneName, - groupName: this.scheduleGroup?.scheduleGroupName ?? this.group?.groupName, + groupName: this.scheduleGroup?.scheduleGroupName, state: (props.enabled ?? true) ? 'ENABLED' : 'DISABLED', kmsKeyArn: this.key?.keyArn, target: { @@ -361,7 +339,7 @@ export class Schedule extends Resource implements ISchedule { this.scheduleArn = this.getResourceArnAttribute(resource.attrArn, { service: 'scheduler', resource: 'schedule', - resourceName: `${this.scheduleGroup?.scheduleGroupName ?? this.group?.groupName ?? 'default'}/${this.physicalName}`, + resourceName: `${this.scheduleGroup?.scheduleGroupName ?? 'default'}/${this.physicalName}`, }); } diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/group.test.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/group.test.ts deleted file mode 100644 index 82207aa2bd65d..0000000000000 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/group.test.ts +++ /dev/null @@ -1,360 +0,0 @@ -import { testDeprecated } from '@aws-cdk/cdk-build-tools'; -import { App, Duration, RemovalPolicy, Stack } from 'aws-cdk-lib'; -import { Match, Template } from 'aws-cdk-lib/assertions'; -import * as cw from 'aws-cdk-lib/aws-cloudwatch'; -import * as iam from 'aws-cdk-lib/aws-iam'; -import * as lambda from 'aws-cdk-lib/aws-lambda'; -import { CfnScheduleGroup } from 'aws-cdk-lib/aws-scheduler'; -import { IScheduleTarget, ScheduleExpression, ScheduleTargetConfig } from '../lib'; -import { Group, GroupProps } from '../lib/group'; -import { Schedule } from '../lib/schedule'; -class SomeLambdaTarget implements IScheduleTarget { - public constructor(private readonly fn: lambda.IFunction, private readonly role: iam.IRole) { - } - - public bind(): ScheduleTargetConfig { - return { - arn: this.fn.functionArn, - role: this.role, - }; - } -} - -describe('Schedule Group', () => { - let stack: Stack; - let func: lambda.IFunction; - const expr = ScheduleExpression.at(new Date(Date.UTC(1969, 10, 20, 0, 0, 0))); - - beforeEach(() => { - const app = new App(); - stack = new Stack(app, 'Stack', { env: { region: 'us-east-1', account: '123456789012' } }); - func = new lambda.Function(stack, 'MyLambda', { - code: new lambda.InlineCode('foo'), - handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_LATEST, - tracing: lambda.Tracing.PASS_THROUGH, - }); - }); - - testDeprecated('creates a group with default properties', () => { - const props: GroupProps = {}; - const group = new Group(stack, 'TestGroup', props); - - expect(group).toBeInstanceOf(Group); - expect(group.groupName).toBeDefined(); - expect(group.groupArn).toBeDefined(); - - const resource = group.node.findChild('Resource') as CfnScheduleGroup; - expect(resource).toBeInstanceOf(CfnScheduleGroup); - expect(resource.name).toEqual(group.groupName); - }); - - testDeprecated('creates a group with removal policy', () => { - const props: GroupProps = { - removalPolicy: RemovalPolicy.RETAIN, - }; - new Group(stack, 'TestGroup', props); - - Template.fromStack(stack).hasResource('AWS::Scheduler::ScheduleGroup', { - DeletionPolicy: 'Retain', - }); - }); - - testDeprecated('creates a group with specified name', () => { - const props: GroupProps = { - groupName: 'MyGroup', - }; - const group = new Group(stack, 'TestGroup', props); - const resource = group.node.findChild('Resource') as CfnScheduleGroup; - expect(resource).toBeInstanceOf(CfnScheduleGroup); - expect(resource.name).toEqual(group.groupName); - - Template.fromStack(stack).hasResource('AWS::Scheduler::ScheduleGroup', { - Properties: { - Name: `${props.groupName}`, - }, - }); - }); - - testDeprecated('creates a group from ARN', () => { - const groupArn = 'arn:aws:scheduler:region:account-id:schedule-group/group-name'; - const group = Group.fromGroupArn(stack, 'TestGroup', groupArn); - - expect(group.groupArn).toBeDefined(); - expect(group.groupName).toEqual('group-name'); - - const groups = Template.fromStack(stack).findResources('AWS::Scheduler::ScheduleGroup'); - expect(groups).toEqual({}); - }); - - testDeprecated('creates a group from name', () => { - const groupName = 'MyGroup'; - const group = Group.fromGroupName(stack, 'TestGroup', groupName); - - expect(group.groupArn).toBeDefined(); - expect(group.groupName).toEqual(groupName); - - const groups = Template.fromStack(stack).findResources('AWS::Scheduler::ScheduleGroup'); - expect(groups).toEqual({}); - }); - - testDeprecated('creates a group from default group', () => { - const group = Group.fromDefaultGroup(stack, 'DefaultGroup'); - - expect(group.groupArn).toBeDefined(); - expect(group.groupName).toEqual('default'); - - const groups = Template.fromStack(stack).findResources('AWS::Scheduler::ScheduleGroup'); - expect(groups).toEqual({}); - }); - - testDeprecated('adds schedules to the group', () => { - const props: GroupProps = { - groupName: 'MyGroup', - }; - const group = new Group(stack, 'TestGroup', props); - 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: `${props.groupName}`, - }, - }); - }); - - testDeprecated('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, - }, - }); - }); - - testDeprecated('grantReadSchedules', () => { - // GIVEN - const props: GroupProps = { - groupName: 'MyGroup', - }; - const group = new Group(stack, 'TestGroup', props); - - const user = new iam.User(stack, 'User'); - - // WHEN - group.grantReadSchedules(user); - // THEN - Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { - PolicyDocument: { - Statement: [ - { - Action: [ - 'scheduler:GetSchedule', - 'scheduler:ListSchedules', - ], - Effect: 'Allow', - Resource: { - 'Fn::Join': [ - '', - [ - 'arn:', - { - Ref: 'AWS::Partition', - }, - ':scheduler:us-east-1:123456789012:schedule/MyGroup/*', - ], - ], - }, - }, - ], - Version: '2012-10-17', - }, - }); - }); - - testDeprecated('grantWriteSchedules', () => { - // GIVEN - const props: GroupProps = { - groupName: 'MyGroup', - }; - const group = new Group(stack, 'TestGroup', props); - - const user = new iam.User(stack, 'User'); - - // WHEN - group.grantWriteSchedules(user); - - // THEN - Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { - PolicyDocument: { - Statement: [ - { - Action: [ - 'scheduler:CreateSchedule', - 'scheduler:UpdateSchedule', - ], - Effect: 'Allow', - Resource: { - 'Fn::Join': [ - '', - [ - 'arn:', - { - Ref: 'AWS::Partition', - }, - ':scheduler:us-east-1:123456789012:schedule/MyGroup/*', - ], - ], - }, - }, - ], - Version: '2012-10-17', - }, - }); - }); - - testDeprecated('grantDeleteSchedules', () => { - // GIVEN - const props: GroupProps = { - groupName: 'MyGroup', - }; - const group = new Group(stack, 'TestGroup', props); - - const user = new iam.User(stack, 'User'); - - // WHEN - group.grantDeleteSchedules(user); - - // THEN - Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { - PolicyDocument: { - Statement: [ - { - Action: 'scheduler:DeleteSchedule', - Effect: 'Allow', - Resource: { - 'Fn::Join': [ - '', - [ - 'arn:', - { - Ref: 'AWS::Partition', - }, - ':scheduler:us-east-1:123456789012:schedule/MyGroup/*', - ], - ], - }, - }, - ], - Version: '2012-10-17', - }, - }); - }); -}); - -describe('Schedule Group Metrics', () => { - test.each([ - ['metricTargetErrors', 'TargetErrorCount'], - ['metricThrottled', 'InvocationThrottleCount'], - ['metricAttempts', 'InvocationAttemptCount'], - ['metricTargetThrottled', 'TargetErrorThrottledCount'], - ['metricDropped', 'InvocationDroppedCount'], - ['metricSentToDLQ', 'InvocationsSentToDeadLetterCount'], - ['metricSentToDLQTruncated', 'InvocationsSentToDeadLetterCount_Truncated_MessageSizeExceeded'], - ])('calling %s creates alarm for %s metric', (metricMethodName, metricName) => { - // GIVEN - const app = new App(); - const props: GroupProps = { - groupName: 'MyGroup', - }; - const stack = new Stack(app, 'Stack', { env: { region: 'us-east-1', account: '123456789012' } }); - const group = new Group(stack, 'TestGroup', props); - - // WHEN - const metricMethod = (group as any)[metricMethodName].bind(group); // Get the method dynamically - const metricTargetErrors = metricMethod({ - period: Duration.minutes(1), - }); - - new cw.Alarm(stack, `Group${metricName}Alarm`, { - metric: metricTargetErrors, - evaluationPeriods: 1, - threshold: 1, - }); - - // THEN - Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { - Dimensions: Match.arrayWith([ - Match.objectLike({ - Name: 'ScheduleGroup', - Value: 'MyGroup', - }), - ]), - MetricName: metricName, - Namespace: 'AWS/Scheduler', - }); - }); - - testDeprecated('Invocations Failed to Deliver to DLQ Metrics', () => { - // GIVEN - const app = new App(); - const props: GroupProps = { - groupName: 'MyGroup', - }; - const stack = new Stack(app, 'Stack', { env: { region: 'us-east-1', account: '123456789012' } }); - const group = new Group(stack, 'TestGroup', props); - const errorCode = '403'; - - // WHEN - const metricFailedToBeSentToDLQ = group.metricFailedToBeSentToDLQ(errorCode, { - period: Duration.minutes(1), - }); - - new cw.Alarm(stack, 'GroupFailedInvocationsToDLQAlarm', { - metric: metricFailedToBeSentToDLQ, - evaluationPeriods: 1, - threshold: 1, - }); - - // THEN - Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { - Dimensions: Match.arrayWith([ - Match.objectLike({ - Name: 'ScheduleGroup', - Value: 'MyGroup', - }), - ]), - MetricName: `InvocationsFailedToBeSentToDeadLetterCount_${errorCode}`, - Namespace: 'AWS/Scheduler', - }); - }); -}); diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts index 2e66eb6429cbe..e52a2e9ff2fe9 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts @@ -49,25 +49,25 @@ new scheduler.Schedule(stack, 'ScheduleWithCMK', { key, }); -const namedGroup = new scheduler.Group(stack, 'NamedGroup', { - groupName: 'TestGroup', +const namedGroup = new scheduler.ScheduleGroup(stack, 'NamedGroup', { + scheduleGroupName: 'TestGroup', }); namedGroup.applyRemovalPolicy(cdk.RemovalPolicy.DESTROY); -const unnamedGroup = new scheduler.Group(stack, 'UnnamedGroup', {}); +const unnamedGroup = new scheduler.ScheduleGroup(stack, 'UnnamedGroup', {}); unnamedGroup.applyRemovalPolicy(cdk.RemovalPolicy.DESTROY); const randomTargetThatWontGetInvoked = new SomeSqsTarget(queue, role); new scheduler.Schedule(stack, 'ScheduleToTestWithNamedGroup', { schedule: scheduler.ScheduleExpression.at(new Date('2060-04-15T06:30:00.000Z')), target: randomTargetThatWontGetInvoked, - group: namedGroup, + scheduleGroup: namedGroup, }); new scheduler.Schedule(stack, 'ScheduleToTestWithUnnamedGroup', { schedule: scheduler.ScheduleExpression.at(new Date('2060-04-15T06:30:00.000Z')), target: randomTargetThatWontGetInvoked, - group: unnamedGroup, + scheduleGroup: unnamedGroup, }); new scheduler.Schedule(stack, 'TestDisabledSchedule', { diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/lib/target.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/lib/target.ts index 7800bb32ca899..f91cf82300cce 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/lib/target.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/lib/target.ts @@ -114,12 +114,12 @@ export abstract class ScheduleTargetBase { conditions: { StringEquals: { 'aws:SourceAccount': schedule.env.account, - 'aws:SourceArn': schedule.scheduleGroup?.scheduleGroupArn ?? schedule.group?.groupArn ?? Stack.of(schedule).formatArn({ + 'aws:SourceArn': schedule.scheduleGroup?.scheduleGroupArn ?? Stack.of(schedule).formatArn({ service: 'scheduler', resource: 'schedule-group', region: schedule.env.region, account: schedule.env.account, - resourceName: schedule.scheduleGroup?.scheduleGroupName ?? schedule.group?.groupName ?? 'default', + resourceName: schedule.scheduleGroup?.scheduleGroupName ?? 'default', }), }, }, diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codebuild-start-build.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codebuild-start-build.test.ts index 923c66bdce095..98d9ecf50fbd1 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codebuild-start-build.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codebuild-start-build.test.ts @@ -1,4 +1,4 @@ -import { Group, Schedule, ScheduleExpression } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleGroup, Schedule, ScheduleExpression } from '@aws-cdk/aws-scheduler-alpha'; import { App, Duration, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import { BuildSpec, Project } from 'aws-cdk-lib/aws-codebuild'; @@ -193,8 +193,8 @@ describe('codebuild start build', () => { test('creates IAM role and IAM policy for two schedules with the same target but different groups', () => { const codeBuildTarget = new CodeBuildStartBuild(codebuildProject); - const group = new Group(stack, 'Group', { - groupName: 'mygroup', + const group = new ScheduleGroup(stack, 'Group', { + scheduleGroupName: 'mygroup', }); new Schedule(stack, 'MyScheduleDummy1', { @@ -205,7 +205,7 @@ describe('codebuild start build', () => { new Schedule(stack, 'MyScheduleDummy2', { schedule: expr, target: codeBuildTarget, - group, + scheduleGroup: group, }); const template = Template.fromStack(stack); diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codepipeline-start-pipeline-execution.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codepipeline-start-pipeline-execution.test.ts index 757be90b45eff..6f40a253111ce 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codepipeline-start-pipeline-execution.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codepipeline-start-pipeline-execution.test.ts @@ -1,4 +1,4 @@ -import { Group, Schedule, ScheduleExpression } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleGroup, Schedule, ScheduleExpression } from '@aws-cdk/aws-scheduler-alpha'; import { App, Duration, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import { Artifact, Pipeline } from 'aws-cdk-lib/aws-codepipeline'; @@ -203,8 +203,8 @@ describe('codepipeline start execution', () => { test('creates IAM role and IAM policy for two schedules with the same target but different groups', () => { const codepipelineTarget = new CodePipelineStartPipelineExecution(codepipeline); - const group = new Group(stack, 'Group', { - groupName: 'mygroup', + const group = new ScheduleGroup(stack, 'Group', { + scheduleGroupName: 'mygroup', }); new Schedule(stack, 'MyScheduleDummy1', { @@ -215,7 +215,7 @@ describe('codepipeline start execution', () => { new Schedule(stack, 'MyScheduleDummy2', { schedule: expr, target: codepipelineTarget, - group, + scheduleGroup: group, }); const template = Template.fromStack(stack); diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/event-bridge-put-events.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/event-bridge-put-events.test.ts index 3c0aa0013f9f2..3bb18ecb7c86e 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/event-bridge-put-events.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/event-bridge-put-events.test.ts @@ -1,4 +1,4 @@ -import { Group, Schedule, ScheduleExpression, ScheduleTargetInput } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleGroup, Schedule, ScheduleExpression, ScheduleTargetInput } from '@aws-cdk/aws-scheduler-alpha'; import { App, Duration, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import * as events from 'aws-cdk-lib/aws-events'; @@ -229,8 +229,8 @@ describe('eventBridge put events', () => { test('creates IAM role and IAM policy for two schedules with the same target but different groups', () => { const eventBusTarget = new EventBridgePutEvents(eventBusEventEntry); - const group = new Group(stack, 'Group', { - groupName: 'mygroup', + const group = new ScheduleGroup(stack, 'Group', { + scheduleGroupName: 'mygroup', }); new Schedule(stack, 'MyScheduleDummy1', { @@ -241,7 +241,7 @@ describe('eventBridge put events', () => { new Schedule(stack, 'MyScheduleDummy2', { schedule: expr, target: eventBusTarget, - group, + scheduleGroup: group, }); const template = Template.fromStack(stack); diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/firehose-put-record.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/firehose-put-record.test.ts index 329ddedf9a3e8..ec82c65ff1424 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/firehose-put-record.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/firehose-put-record.test.ts @@ -1,4 +1,4 @@ -import { ScheduleExpression, Schedule, Group } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleExpression, Schedule, ScheduleGroup } from '@aws-cdk/aws-scheduler-alpha'; import { App, CfnResource, Duration, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import { AccountRootPrincipal, Role } from 'aws-cdk-lib/aws-iam'; @@ -219,8 +219,8 @@ describe('schedule target', () => { test('creates IAM role and IAM policy for two schedules with the same target but different groups', () => { const firehoseTarget = new FirehosePutRecord(firehoseStream); - const group = new Group(stack, 'Group', { - groupName: 'mygroup', + const group = new ScheduleGroup(stack, 'Group', { + scheduleGroupName: 'mygroup', }); new Schedule(stack, 'MyScheduleDummy1', { @@ -231,7 +231,7 @@ describe('schedule target', () => { new Schedule(stack, 'MyScheduleDummy2', { schedule: expr, target: firehoseTarget, - group, + scheduleGroup: group, }); Template.fromStack(stack).resourcePropertiesCountIs('AWS::IAM::Role', { diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/inspector-start-assessment-run.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/inspector-start-assessment-run.test.ts index 4ab0b14b7e9e9..d7de9a3e3630f 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/inspector-start-assessment-run.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/inspector-start-assessment-run.test.ts @@ -1,4 +1,4 @@ -import { ScheduleExpression, Schedule, Group } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleExpression, Schedule, ScheduleGroup } from '@aws-cdk/aws-scheduler-alpha'; import { App, Duration, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import { AccountRootPrincipal, Role } from 'aws-cdk-lib/aws-iam'; @@ -192,8 +192,8 @@ describe('schedule target', () => { test('creates IAM role and IAM policy for two schedules with the same target but different groups', () => { const inspectorTarget = new InspectorStartAssessmentRun(template); - const group = new Group(stack, 'Group', { - groupName: 'mygroup', + const group = new ScheduleGroup(stack, 'Group', { + scheduleGroupName: 'mygroup', }); new Schedule(stack, 'MyScheduleDummy1', { @@ -204,7 +204,7 @@ describe('schedule target', () => { new Schedule(stack, 'MyScheduleDummy2', { schedule: expr, target: inspectorTarget, - group, + scheduleGroup: group, }); Template.fromStack(stack).resourcePropertiesCountIs('AWS::IAM::Role', { diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-stream-put-record.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-stream-put-record.test.ts index 8a1d522552636..d290beb7aa99a 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-stream-put-record.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-stream-put-record.test.ts @@ -1,4 +1,4 @@ -import { ScheduleExpression, Schedule, Group } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleExpression, Schedule, ScheduleGroup } from '@aws-cdk/aws-scheduler-alpha'; import { App, Duration, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import { AccountRootPrincipal, Role } from 'aws-cdk-lib/aws-iam'; @@ -206,8 +206,8 @@ describe('schedule target', () => { const streamTarget = new KinesisStreamPutRecord(stream, { partitionKey: 'key', }); - const group = new Group(stack, 'Group', { - groupName: 'mygroup', + const group = new ScheduleGroup(stack, 'Group', { + scheduleGroupName: 'mygroup', }); new Schedule(stack, 'MyScheduleDummy1', { @@ -218,7 +218,7 @@ describe('schedule target', () => { new Schedule(stack, 'MyScheduleDummy2', { schedule: expr, target: streamTarget, - group, + scheduleGroup: group, }); Template.fromStack(stack).resourcePropertiesCountIs('AWS::IAM::Role', { diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/lambda-invoke.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/lambda-invoke.test.ts index f8bc3cc4e6d4a..90c1147013a13 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/lambda-invoke.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/lambda-invoke.test.ts @@ -1,4 +1,4 @@ -import { ScheduleExpression, Schedule, Group } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleExpression, Schedule, ScheduleGroup } from '@aws-cdk/aws-scheduler-alpha'; import { App, Duration, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import { AccountRootPrincipal, Role } from 'aws-cdk-lib/aws-iam'; @@ -297,8 +297,8 @@ describe('schedule target', () => { test('creates IAM role and IAM policy for two schedules with the same target but different groups', () => { const lambdaTarget = new LambdaInvoke(func); - const group = new Group(stack, 'Group', { - groupName: 'mygroup', + const group = new ScheduleGroup(stack, 'Group', { + scheduleGroupName: 'mygroup', }); new Schedule(stack, 'MyScheduleDummy1', { @@ -309,7 +309,7 @@ describe('schedule target', () => { new Schedule(stack, 'MyScheduleDummy2', { schedule: expr, target: lambdaTarget, - group, + scheduleGroup: group, }); Template.fromStack(stack).resourceCountIs('AWS::Lambda::Permission', 0); diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sage-maker-start-pipeline-execution.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sage-maker-start-pipeline-execution.test.ts index 83bac8f5423a6..572a2363072c4 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sage-maker-start-pipeline-execution.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sage-maker-start-pipeline-execution.test.ts @@ -1,4 +1,4 @@ -import { ScheduleExpression, Schedule, Group } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleExpression, Schedule, ScheduleGroup } from '@aws-cdk/aws-scheduler-alpha'; import { App, Duration, Resource, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import { AccountRootPrincipal, Grant, IGrantable, Role } from 'aws-cdk-lib/aws-iam'; @@ -204,8 +204,8 @@ describe('schedule target', () => { const pipelineTarget = new SageMakerStartPipelineExecution(pipeline, { pipelineParameterList, }); - const group = new Group(stack, 'Group', { - groupName: 'mygroup', + const group = new ScheduleGroup(stack, 'Group', { + scheduleGroupName: 'mygroup', }); new Schedule(stack, 'MyScheduleDummy1', { @@ -216,7 +216,7 @@ describe('schedule target', () => { new Schedule(stack, 'MyScheduleDummy2', { schedule: expr, target: pipelineTarget, - group, + scheduleGroup: group, }); Template.fromStack(stack).resourcePropertiesCountIs('AWS::IAM::Role', { diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sns-publish.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sns-publish.test.ts index d184f72989ad9..ab0cd03c82aa3 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sns-publish.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sns-publish.test.ts @@ -1,5 +1,5 @@ import * as scheduler from '@aws-cdk/aws-scheduler-alpha'; -import { Group } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleGroup } from '@aws-cdk/aws-scheduler-alpha'; import { App, Duration, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import * as iam from 'aws-cdk-lib/aws-iam'; @@ -218,8 +218,8 @@ describe('sns topic schedule target', () => { test('creates IAM role and IAM policy for two schedules with the same target but different groups', () => { const target = new SnsPublish(topic); - const group = new Group(stack, 'Group', { - groupName: 'mygroup', + const group = new ScheduleGroup(stack, 'Group', { + scheduleGroupName: 'mygroup', }); new scheduler.Schedule(stack, 'Schedule1', { @@ -230,7 +230,7 @@ describe('sns topic schedule target', () => { new scheduler.Schedule(stack, 'Schedule2', { schedule: scheduleExpression, target, - group, + scheduleGroup: group, }); const template = Template.fromStack(stack); diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sqs-send-message.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sqs-send-message.test.ts index 5f26c5583b699..5d9964677bed0 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sqs-send-message.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sqs-send-message.test.ts @@ -1,4 +1,4 @@ -import { ScheduleExpression, Schedule, Group } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleExpression, Schedule, ScheduleGroup } from '@aws-cdk/aws-scheduler-alpha'; import { App, Duration, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import { AccountRootPrincipal, Role } from 'aws-cdk-lib/aws-iam'; @@ -192,8 +192,8 @@ describe('schedule target', () => { test('creates IAM role and IAM policy for two schedules with the same target but different groups', () => { const queueTarget = new SqsSendMessage(queue); - const group = new Group(stack, 'Group', { - groupName: 'mygroup', + const group = new ScheduleGroup(stack, 'Group', { + scheduleGroupName: 'mygroup', }); new Schedule(stack, 'MyScheduleDummy1', { @@ -204,7 +204,7 @@ describe('schedule target', () => { new Schedule(stack, 'MyScheduleDummy2', { schedule: expr, target: queueTarget, - group, + scheduleGroup: group, }); Template.fromStack(stack).resourcePropertiesCountIs('AWS::IAM::Role', { diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/stepfunction-start-execution.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/stepfunction-start-execution.test.ts index e2756b8f9d111..761101e4e4396 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/stepfunction-start-execution.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/stepfunction-start-execution.test.ts @@ -1,4 +1,4 @@ -import { Group, Schedule, ScheduleExpression } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleGroup, Schedule, ScheduleExpression } from '@aws-cdk/aws-scheduler-alpha'; import { App, Duration, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import { AccountRootPrincipal, Role } from 'aws-cdk-lib/aws-iam'; @@ -192,8 +192,8 @@ describe('stepfunction start execution', () => { test('creates IAM role and IAM policy for two schedules with the same target but different groups', () => { const stepFunctionTarget = new StepFunctionsStartExecution(stepFunction, {}); - const group = new Group(stack, 'Group', { - groupName: 'mygroup', + const group = new ScheduleGroup(stack, 'Group', { + scheduleGroupName: 'mygroup', }); new Schedule(stack, 'MyScheduleDummy1', { @@ -204,7 +204,7 @@ describe('stepfunction start execution', () => { new Schedule(stack, 'MyScheduleDummy2', { schedule: expr, target: stepFunctionTarget, - group, + scheduleGroup: group, }); const template = Template.fromStack(stack);