Skip to content

Commit

Permalink
Merge branch 'main' into gh-26735
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 21, 2023
2 parents abbac13 + 25ee8ef commit f859f78
Show file tree
Hide file tree
Showing 13 changed files with 350 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyRestApiDeploymentB555B582d83364d66d67f510f848797cd89349d5": {
"MyRestApiDeploymentB555B58276a4103e7ef38befb395a9ace5fdce44": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"Description": "Automatically created by the RestApi construct",
Expand All @@ -208,7 +208,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B582d83364d66d67f510f848797cd89349d5"
"Ref": "MyRestApiDeploymentB555B58276a4103e7ef38befb395a9ace5fdce44"
},
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
Expand Down Expand Up @@ -306,6 +306,7 @@
"MyAuthorizer6575980E": {
"Type": "AWS::ApiGateway::Authorizer",
"Properties": {
"AuthorizerResultTtlInSeconds": 300,
"AuthorizerUri": {
"Fn::Join": [
"",
Expand Down Expand Up @@ -366,6 +367,7 @@
"MySecondAuthorizer25A69B96": {
"Type": "AWS::ApiGateway::Authorizer",
"Properties": {
"AuthorizerResultTtlInSeconds": 300,
"AuthorizerUri": {
"Fn::Join": [
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"Arn"
]
},
"AuthorizerResultTtlInSeconds": 300,
"AuthorizerUri": {
"Fn::Join": [
"",
Expand Down Expand Up @@ -233,7 +234,7 @@
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyRestApiDeploymentB555B582694e8eb3fdb7b5f988ba347d35601979": {
"MyRestApiDeploymentB555B58259401a546b13c99de2d05e5e255a9ede": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"Description": "Automatically created by the RestApi construct",
Expand All @@ -251,7 +252,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B582694e8eb3fdb7b5f988ba347d35601979"
"Ref": "MyRestApiDeploymentB555B58259401a546b13c99de2d05e5e255a9ede"
},
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"MyAuthorizer6575980E": {
"Type": "AWS::ApiGateway::Authorizer",
"Properties": {
"AuthorizerResultTtlInSeconds": 600,
"AuthorizerUri": {
"Fn::Join": [
"",
Expand Down Expand Up @@ -208,7 +209,7 @@
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyRestApiDeploymentB555B582e0e53f2547b469b538202de55968eaf0": {
"MyRestApiDeploymentB555B5827a9cde8f137f97e5aa74fca164d09d74": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"Description": "Automatically created by the RestApi construct",
Expand All @@ -226,7 +227,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B582e0e53f2547b469b538202de55968eaf0"
"Ref": "MyRestApiDeploymentB555B5827a9cde8f137f97e5aa74fca164d09d74"
},
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const authorizerFn = new lambda.Function(stack, 'MyAuthorizerFunction', {

const authorizer = new TokenAuthorizer(stack, 'MyAuthorizer', {
handler: authorizerFn,
resultsCacheTtl: Duration.minutes(10),
});

const restapi = new RestApi(stack, 'MyRestApi', {
Expand Down
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

0 comments on commit f859f78

Please sign in to comment.