Skip to content

Commit

Permalink
fix(scheduler-targetes-alpha): multiple schedules cause resolution er…
Browse files Browse the repository at this point in the history
…ror during synth (#30634)

### Reason for this change

Creating multiple `Schedule`s causes Resolution Error during synth.
This PR does not fix the root cause (discussing at #28713), but apply a workaround to prevent the error.

### Description of changes

Use `ServicePrincipal` with conditions directly, instead of `PrincipalWithConditions`.

### Description of how you validated changes

Added a feature flag `{"@aws-cdk/aws-iam:minimizePolicies":true}` to unit tests.
Resolution errors occur before fix. No errors occur after fix.

## Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Tietew committed Jul 10, 2024
1 parent 7cd0f65 commit 727e886
Show file tree
Hide file tree
Showing 22 changed files with 9,453 additions and 10,133 deletions.
10 changes: 6 additions & 4 deletions packages/@aws-cdk/aws-scheduler-targets-alpha/lib/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ export abstract class ScheduleTargetBase {
const id = 'SchedulerRoleForTarget-' + hash;
const existingRole = stack.node.tryFindChild(id) as iam.Role;

const principal = new iam.PrincipalWithConditions(new iam.ServicePrincipal('scheduler.amazonaws.com'), {
StringEquals: {
'aws:SourceAccount': schedule.env.account,
const principal = new iam.ServicePrincipal('scheduler.amazonaws.com', {
conditions: {
StringEquals: {
'aws:SourceAccount': schedule.env.account,
},
},
});
if (existingRole) {
Expand Down Expand Up @@ -192,4 +194,4 @@ export abstract class ScheduleTargetBase {
maximumRetryAttempts: maxAttempts,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('codebuild start build', () => {
const expr = ScheduleExpression.at(new Date(Date.UTC(1991, 2, 24, 0, 0, 0)));

beforeEach(() => {
app = new App();
app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } });
stack = new Stack(app, 'Stack', { env: { region: 'us-east-1', account: '123456789012' } });
codebuildProject = new Project(stack, 'Project', {
buildSpec: BuildSpec.fromObject({}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('codepipeline start execution', () => {
const expr = ScheduleExpression.at(new Date(Date.UTC(1991, 2, 24, 0, 0, 0)));

beforeEach(() => {
app = new App();
app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } });
stack = new Stack(app, 'Stack', { env: { region: 'us-east-1', account: '123456789012' } });
codepipeline = createMinimalPipeline(stack);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('eventBridge put events', () => {
const expr = ScheduleExpression.at(new Date(Date.UTC(1991, 2, 24, 0, 0, 0)));

beforeEach(() => {
app = new App();
app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } });
stack = new Stack(app, 'Stack', { env: { region: 'us-east-1', account: '123456789012' } });
eventBus = new events.EventBus(stack, 'MyEventBus', { eventBusName: 'MyEventBus' });
eventBusEventEntry = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('schedule target', () => {
const expr = ScheduleExpression.at(new Date(Date.UTC(1969, 10, 20, 0, 0, 0)));

beforeEach(() => {
app = new App();
app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } });
stack = new Stack(app, 'Stack', { env: { region: 'us-east-1', account: '123456789012' } });
const assessmentTarget = new CfnAssessmentTarget(stack, 'MyAssessmentTarget');
template = new CfnAssessmentTemplate(stack, 'MyTemplate', {
Expand Down Expand Up @@ -506,4 +506,4 @@ describe('schedule target', () => {
target: inspectorTarget,
})).toThrow(/Number of retry attempts should be less or equal than 185/);
});
});
});
Loading

0 comments on commit 727e886

Please sign in to comment.