-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove env check on Schedule and the target
- Loading branch information
1 parent
7815144
commit beca3d7
Showing
11 changed files
with
44 additions
and
195 deletions.
There are no files selected for viewing
23 changes: 6 additions & 17 deletions
23
packages/@aws-cdk/aws-scheduler-targets-alpha/lib/codebuild-start-build.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 6 additions & 20 deletions
26
packages/@aws-cdk/aws-scheduler-targets-alpha/lib/codepipeline-start-pipeline-execution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 3 additions & 17 deletions
20
packages/@aws-cdk/aws-scheduler-targets-alpha/lib/inspector-start-assessment-run.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 6 additions & 17 deletions
23
packages/@aws-cdk/aws-scheduler-targets-alpha/lib/kinesis-data-firehose-put-record.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 6 additions & 17 deletions
23
packages/@aws-cdk/aws-scheduler-targets-alpha/lib/lambda-invoke.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,23 @@ | ||
import { ISchedule, IScheduleTarget } from '@aws-cdk/aws-scheduler-alpha'; | ||
import { Names } from 'aws-cdk-lib'; | ||
import { IRole } from 'aws-cdk-lib/aws-iam'; | ||
import * as lambda from 'aws-cdk-lib/aws-lambda'; | ||
import { ScheduleTargetBase, ScheduleTargetBaseProps } from './target'; | ||
import { sameEnvDimension } from './util'; | ||
|
||
/** | ||
* Use an AWS Lambda function as a target for AWS EventBridge Scheduler. | ||
*/ | ||
export class LambdaInvoke extends ScheduleTargetBase implements IScheduleTarget { | ||
private readonly func: lambda.IFunction; | ||
|
||
constructor( | ||
private readonly func: lambda.IFunction, | ||
private readonly props: ScheduleTargetBaseProps, | ||
func: lambda.IFunction, | ||
props: ScheduleTargetBaseProps, | ||
) { | ||
super(props, func.functionArn); | ||
this.func = func; | ||
} | ||
|
||
protected addTargetActionToRole(schedule: ISchedule, role: IRole): void { | ||
if (!sameEnvDimension(this.func.env.region, schedule.env.region)) { | ||
throw new Error(`Cannot assign function in region ${this.func.env.region} to the schedule ${Names.nodeUniqueId(schedule.node)} in region ${schedule.env.region}. Both the schedule and the function must be in the same region.`); | ||
} | ||
|
||
if (!sameEnvDimension(this.func.env.account, schedule.env.account)) { | ||
throw new Error(`Cannot assign function in account ${this.func.env.account} to the schedule ${Names.nodeUniqueId(schedule.node)} in account ${schedule.env.region}. Both the schedule and the function must be in the same account.`); | ||
} | ||
|
||
if (this.props.role && !sameEnvDimension(this.props.role.env.account, this.func.env.account)) { | ||
throw new Error(`Cannot grant permission to execution role in account ${this.props.role.env.account} to invoke target ${Names.nodeUniqueId(this.func.node)} in account ${this.func.env.account}. Both the target and the execution role must be in the same account.`); | ||
} | ||
|
||
protected addTargetActionToRole(_schedule: ISchedule, role: IRole): void { | ||
this.func.grantInvoke(role); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 6 additions & 20 deletions
26
packages/@aws-cdk/aws-scheduler-targets-alpha/lib/sns-publish.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,23 @@ | ||
import { ISchedule, IScheduleTarget } from '@aws-cdk/aws-scheduler-alpha'; | ||
import { Names } from 'aws-cdk-lib'; | ||
import { IRole } from 'aws-cdk-lib/aws-iam'; | ||
import * as sns from 'aws-cdk-lib/aws-sns'; | ||
import { ScheduleTargetBase, ScheduleTargetBaseProps } from './target'; | ||
import { sameEnvDimension } from './util'; | ||
|
||
/** | ||
* Use an Amazon SNS topic as a target for AWS EventBridge Scheduler. | ||
*/ | ||
export class SnsPublish extends ScheduleTargetBase implements IScheduleTarget { | ||
private readonly topic: sns.ITopic; | ||
|
||
constructor( | ||
private readonly topic: sns.ITopic, | ||
private readonly props: ScheduleTargetBaseProps = {}, | ||
topic: sns.ITopic, | ||
props: ScheduleTargetBaseProps = {}, | ||
) { | ||
super(props, topic.topicArn); | ||
this.topic = topic; | ||
} | ||
|
||
protected addTargetActionToRole(schedule: ISchedule, role: IRole): void { | ||
// Check if target and schedule are in the region | ||
if (!sameEnvDimension(this.topic.env.region, schedule.env.region)) { | ||
throw new Error(`Cannot assign topic in region ${this.topic.env.region} to the schedule ${Names.nodeUniqueId(schedule.node)} in region ${schedule.env.region}. Both the schedule and the topic must be in the same region.`); | ||
} | ||
|
||
// Check if target and schedule are in the same account | ||
if (!sameEnvDimension(this.topic.env.account, schedule.env.account)) { | ||
throw new Error(`Cannot assign topic in account ${this.topic.env.account} to the schedule ${Names.nodeUniqueId(schedule.node)} in account ${role.env.account}. Both the schedule and the topic must be in the same account.`); | ||
} | ||
|
||
// Check if target and role are in the same account | ||
if (this.props.role && !sameEnvDimension(this.props.role.env.account, this.topic.env.account)) { | ||
throw new Error(`Cannot grant permission to execution role in account ${this.props.role.env.account} to publish to target ${Names.nodeUniqueId(this.topic.node)} in account ${this.topic.env.account}. Both the target and the execution role must be in the same account.`); | ||
} | ||
|
||
protected addTargetActionToRole(_schedule: ISchedule, role: IRole): void { | ||
this.topic.grantPublish(role); | ||
} | ||
} |
Oops, something went wrong.