-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(scheduler-targets-alpha): SnsPublish
scheduler target
#27838
Changes from 7 commits
b858864
6fc3d6c
7120ec4
b323246
74a786f
efcbc06
ed540ec
d5e47e7
788d5a1
8f6c5b2
0e2bafe
150ea10
efbc9ac
e86a878
7044203
e3f405f
f745f15
b235e77
a1af754
09c9713
5e8b671
c9523fe
8c8742b
c86928b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './target'; | ||
export * from './lambda-invoke'; | ||
export * from './stepfunctions-start-execution'; | ||
export * from './sns-publish'; | ||
export * from './codebuild-start-build'; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,37 @@ | ||||||
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 { | ||||||
constructor( | ||||||
private readonly topic: sns.ITopic, | ||||||
private readonly props: ScheduleTargetBaseProps, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let's add a default value to simplify initialization when no props are needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your advice! I've updated them. |
||||||
) { | ||||||
super(props, topic.topicArn); | ||||||
} | ||||||
|
||||||
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.`); | ||||||
} | ||||||
|
||||||
this.topic.grantPublish(role); | ||||||
} | ||||||
} |
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 |
---|---|---|
@@ -0,0 +1,184 @@ | ||
{ | ||
"Resources": { | ||
"TopicBFC7AF6E": { | ||
"Type": "AWS::SNS::Topic" | ||
}, | ||
"Queue4A7E3555": { | ||
"Type": "AWS::SQS::Queue", | ||
"UpdateReplacePolicy": "Delete", | ||
"DeletionPolicy": "Delete" | ||
}, | ||
"QueuePolicy25439813": { | ||
"Type": "AWS::SQS::QueuePolicy", | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sqs:SendMessage", | ||
"Condition": { | ||
"ArnEquals": { | ||
"aws:SourceArn": { | ||
"Ref": "TopicBFC7AF6E" | ||
} | ||
} | ||
}, | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "sns.amazonaws.com" | ||
}, | ||
"Resource": { | ||
"Fn::GetAtt": [ | ||
"Queue4A7E3555", | ||
"Arn" | ||
] | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"Queues": [ | ||
{ | ||
"Ref": "Queue4A7E3555" | ||
} | ||
] | ||
} | ||
}, | ||
"QueueAwsSchedulerTargetsSnsPublishTopicCB9BF6E1C346AD60": { | ||
"Type": "AWS::SNS::Subscription", | ||
"Properties": { | ||
"Endpoint": { | ||
"Fn::GetAtt": [ | ||
"Queue4A7E3555", | ||
"Arn" | ||
] | ||
}, | ||
"Protocol": "sqs", | ||
"RawMessageDelivery": true, | ||
"TopicArn": { | ||
"Ref": "TopicBFC7AF6E" | ||
} | ||
}, | ||
"DependsOn": [ | ||
"QueuePolicy25439813" | ||
] | ||
}, | ||
"Schedule83A77FD1": { | ||
"Type": "AWS::Scheduler::Schedule", | ||
"Properties": { | ||
"FlexibleTimeWindow": { | ||
"Mode": "OFF" | ||
}, | ||
"ScheduleExpression": "rate(1 minute)", | ||
"ScheduleExpressionTimezone": "Etc/UTC", | ||
"State": "ENABLED", | ||
"Target": { | ||
"Arn": { | ||
"Ref": "TopicBFC7AF6E" | ||
}, | ||
"Input": "\"Hello, Scheduler!\"", | ||
"RetryPolicy": { | ||
"MaximumEventAgeInSeconds": 86400, | ||
"MaximumRetryAttempts": 185 | ||
}, | ||
"RoleArn": { | ||
"Fn::GetAtt": [ | ||
"SchedulerRoleForTarget1441a743A31888", | ||
"Arn" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"SchedulerRoleForTarget1441a743A31888": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Condition": { | ||
"StringEquals": { | ||
"aws:SourceAccount": { | ||
"Ref": "AWS::AccountId" | ||
} | ||
} | ||
}, | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "scheduler.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
} | ||
} | ||
}, | ||
"SchedulerRoleForTarget1441a7DefaultPolicy885B6BFD": { | ||
"Type": "AWS::IAM::Policy", | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sns:Publish", | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Ref": "TopicBFC7AF6E" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"PolicyName": "SchedulerRoleForTarget1441a7DefaultPolicy885B6BFD", | ||
"Roles": [ | ||
{ | ||
"Ref": "SchedulerRoleForTarget1441a743A31888" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"ExportsOutputRefQueue4A7E3555425E8BD3": { | ||
"Value": { | ||
"Ref": "Queue4A7E3555" | ||
}, | ||
"Export": { | ||
"Name": "AwsSchedulerTargetsSnsPublish:ExportsOutputRefQueue4A7E3555425E8BD3" | ||
} | ||
} | ||
}, | ||
"Parameters": { | ||
"BootstrapVersion": { | ||
"Type": "AWS::SSM::Parameter::Value<String>", | ||
"Default": "/cdk-bootstrap/hnb659fds/version", | ||
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" | ||
} | ||
}, | ||
"Rules": { | ||
"CheckBootstrapVersion": { | ||
"Assertions": [ | ||
{ | ||
"Assert": { | ||
"Fn::Not": [ | ||
{ | ||
"Fn::Contains": [ | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5" | ||
], | ||
{ | ||
"Ref": "BootstrapVersion" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." | ||
} | ||
] | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please sort these alphabetically?