-
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.
feat(scheduler-targets): add SnsPublish target
- Loading branch information
1 parent
fce26b6
commit 7946c72
Showing
15 changed files
with
35,729 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './target'; | ||
export * from './codebuild-start-build'; | ||
export * from './lambda-invoke'; | ||
export * from './sns-publish'; | ||
export * from './stepfunctions-start-execution'; | ||
export * from './codebuild-start-build'; | ||
export * from './target'; |
34 changes: 34 additions & 0 deletions
34
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ISchedule, IScheduleTarget } from '@aws-cdk/aws-scheduler-alpha'; | ||
import { Names } from 'aws-cdk-lib'; | ||
import { IRole } from 'aws-cdk-lib/aws-iam'; | ||
import { ITopic } from 'aws-cdk-lib/aws-sns'; | ||
import { ScheduleTargetBase, ScheduleTargetBaseProps } from './target'; | ||
import { sameEnvDimension } from './util'; | ||
|
||
/** | ||
* Use an SNS topic as a target for AWS EventBridge Scheduler. | ||
*/ | ||
export class SnsPublish extends ScheduleTargetBase implements IScheduleTarget { | ||
constructor( | ||
private readonly topic: ITopic, | ||
private readonly props: ScheduleTargetBaseProps = {}, | ||
) { | ||
super(props, topic.topicArn); | ||
} | ||
|
||
protected addTargetActionToRole(schedule: ISchedule, role: IRole): void { | ||
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.`); | ||
} | ||
|
||
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 ${schedule.env.region}. Both the schedule and the topic must be in the same account.`); | ||
} | ||
|
||
if (this.props.role && !sameEnvDimension(this.props.role.env.account, schedule.env.account)) { | ||
throw new Error(`Cannot grant permission to execution role in account ${this.props.role.env.account} to invoke target ${Names.nodeUniqueId(schedule.node)} in account ${schedule.env.account}. Both the target and the execution role must be in the same account.`); | ||
} | ||
|
||
this.topic.grantPublish(role); | ||
} | ||
} |
Oops, something went wrong.