Skip to content

Add ability to create AWS::Scheduler::Schedule triggers #11707

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

Closed
wants to merge 7 commits into from

Conversation

joelwalden
Copy link

Adds the ability to create AWS::Scheduler::Schedule triggers as an alternative to AWS::Event::Rule, which may be preferable if hitting account-wide limits on number of AWS::Event::Rule triggers per bus (Lambdas are only able to be triggered from the default bus).

Unless they need to use inputPath or inputTransformer, developers should be able to just add the method config option and seamlessly migrate to use Scheduler if the devs find themselves up against the account quotas.

Closes: #11680

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @joelwalden ! That looks really good. Please see my comments

@joelwalden
Copy link
Author

@medikoo Thanks for taking a look! Do the other changes look good as well?

@joelwalden
Copy link
Author

Also let's hold off on merging this. There's a required param that's missing from the target. Will update by EoD.

@@ -113,18 +128,38 @@ class AwsCompileScheduledEvents {
);
}

if (method === 'scheduler' && !roleArn) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the execution role that the Scheduler will use to invoke the target lambda? How would you feel about generating a default execution role if a roleArn was not provided?

As this PR currently stands, a minimal execution role would look like the following:

"ScheduleExecutionRole": {
  "Type": "AWS::IAM::Role",
  "Properties": {
    "AssumeRolePolicyDocument": {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Principal": {
            "Service": "scheduler.amazonaws.com"
          },
          "Action": ["sts:AssumeRole"]
        }
      ]
    },
    "Policies": [
      {
        "PolicyName": "invoke",
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Action": ["lambda:InvokeFunction"],
              "Resource": /* lambdaLogicalId ARN */
            }
          ]
        }
      }
    ]
  }
}

...or you could create an unscoped version ("Resource": "*") also.

If you're not open to this, could we at least update the documentation to note that this property is required when the method is set to scheduler? Thanks for your consideration.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drboyer I like this idea; I assume it'd be a good idea to check if a default role has been created (perhaps via a tag) and assign it rather than creating a new one for each function in a project? There are quotas for roles on an account, and as this PR is mainly meant to address an issue where devs can hit them, so I don't want to cause the same problem I'm trying to solve here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelwalden good point. So the idea would be check if there's a "default role" with a certain tag attached (or name possibly?), and only create a generic execution role if one does not exist? And I'd imagine the logic would be skipped entirely if a roleArn was provided.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a new role behind the scenes, wouldn't it be ok, to rely on execution role that Framework is creating ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@medikoo Sounds good; we can extend that to include the assumeRole for scheduler.amazonaws.com and use it if one isn't passed. Will update.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might I add, if we go with the idea of creating a scheduler group for all schedules in a service, we may also want to do the same with the role?

@KillDozerX2
Copy link
Contributor

KillDozerX2 commented Feb 3, 2023

These schedules would go in the default group. Can we allow for a groupName to be passed onto the scheduler? Or maybe create a group by default based on the service + lambda name?

@KillDozerX2
Copy link
Contributor

Another feature that Eventbridge scheduler supports is specifying a timezone for the schedule.
I believe that we should allow users to specify the timezone as well. Here's and example of how we did this for our plugin.

@KillDozerX2
Copy link
Contributor

Another feature that Eventbridge scheduler supports is specifying a timezone for the schedule. I believe that we should allow users to specify the timezone as well. Here's and example of how we did this for our plugin.

@joelwalden sent you a PR in your repo.

@medikoo would you be kind enough to review it as well?

@joelwalden
Copy link
Author

Another feature that Eventbridge scheduler supports is specifying a timezone for the schedule. I believe that we should allow users to specify the timezone as well. Here's and example of how we did this for our plugin.

@joelwalden sent you a PR in your repo.

@medikoo would you be kind enough to review it as well?

Will take a look this weekend; thanks!

@KillDozerX2
Copy link
Contributor

Can this get some traction please? DST is approaching soon so it might be a good time to try this out.

@medikoo
Copy link
Contributor

medikoo commented Mar 6, 2023

Can this get some traction please? DST is approaching soon so it might be a good time to try this out.

@KillDozerX2 can you continue work done in this PR?

@KillDozerX2
Copy link
Contributor

KillDozerX2 commented Mar 6, 2023

Can this get some traction please? DST is approaching soon so it might be a good time to try this out.

@KillDozerX2 can you continue work done in this PR?

@medikoo Yeah, I can pick it. Can send you a new PR soon, let me know if I should create a new PR. Had already sent a PR to @joelwalden's fork.

@tie624
Copy link
Contributor

tie624 commented Apr 25, 2023

Can this get some traction please? DST is approaching soon so it might be a good time to try this out.

@KillDozerX2 can you continue work done in this PR?

@medikoo Yeah, I can pick it. Can send you a new PR soon, let me know if I should create a new PR. Had already sent a PR to @joelwalden's fork.

DST is here now, but I would still love to see this get implemented. Let me know if there is something I can do to get this over the line.

@medikoo
Copy link
Contributor

medikoo commented May 10, 2023

Closing this PR in favor of #11935

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SLS should be able to create AWS::Scheduler::Schedule events
5 participants