Skip to content
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

Fix EventSource Schedule passes Enabled to State #1666

Merged
merged 6 commits into from
Jul 22, 2022

Conversation

lightpriest
Copy link
Contributor

@lightpriest lightpriest commented Jul 27, 2020

Issue

I stumbled upon this but noticed there's an open issue: #1271

Description of changes:

In the documentation, it is stated that Enabled is passed directly to State,
and also that intrinsic functions are supported in all of the Schedule
EventSource properties.

Added the expected "passing" of the value, while maintaining the previous
behavior of True -> ENABLED and False -> DISABLED.

Description of how you validated changes:

Wrote missing tests for Schedule event source, and for this specific test.

Checklist:

  • Write/update tests
  • make pr passes
  • Update documentation
  • Verify transformed template deploys and application functions as expected

Examples?

Please reach out in the comments, if you want to add an example. Examples will be
added to sam init through https://github.com/awslabs/aws-sam-cli-app-templates/

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

In the documentation it is stated that Enabled is passed directly to State,
and also that intrinsic functions are supported in all of the Schedule
EventSource properties.

Added the expected "passing" of the value, while maintaining the previous
behavior of `True -> ENABLED` and `False -> DISABLED`.
@codecov-commenter
Copy link

Codecov Report

Merging #1666 into develop will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1666   +/-   ##
========================================
  Coverage    94.08%   94.09%           
========================================
  Files           86       86           
  Lines         5414     5416    +2     
  Branches      1082     1083    +1     
========================================
+ Hits          5094     5096    +2     
  Misses         148      148           
  Partials       172      172           
Impacted Files Coverage Δ
samtranslator/model/eventsources/push.py 90.90% <100.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39be0a6...96aa35e. Read the comment docs.

@lightpriest
Copy link
Contributor Author

I couldn't verify this change on a real template, how should I do this? I tried running the script under bin but it always failed with some different error (on packaged template, local, built, etc.) and I didn't have time to dig into each.

How do I translate a template that I have locally?

@lightpriest
Copy link
Contributor Author

lightpriest commented Jul 27, 2020

Got it to work. A fully working template renders and deploys successfully.

@lightpriest
Copy link
Contributor Author

Any comments? Something? :)

@Schwusch
Copy link

I would like to see this PR merged. We currently have no workaround other than to look at other solutions like CDK.

if isinstance(self.Enabled, bool):
events_rule.State = "ENABLED" if self.Enabled else "DISABLED"
else:
events_rule.State = self.Enabled

Choose a reason for hiding this comment

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

Can self.Enabled be an instrinsic function at this point?
If so, is there a way to evaluate it?

Copy link
Contributor Author

@lightpriest lightpriest Oct 26, 2020

Choose a reason for hiding this comment

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

I think that if it's passed directly to CloudFormation, it will apply intrinsic functions (if applicable at CF level), isn't it so?

@benkehoe
Copy link

I'd also love to see this PR merged. Ran into this today and had to explode a couple schedule event sources into constituent rules, IAM roles, and Lambda permissions.

@lightpriest
Copy link
Contributor Author

Anyone? 🥺

@milesgranger
Copy link

milesgranger commented Nov 14, 2020

Ping as a plus one for this to go in; as it is quite unexpected behavior and not ergonomic now with SAM if we're talking about 100s of events that need to be toggled via parameters. 👍
Thanks for the work here @lightpriest 👏

@jfuss jfuss requested review from a team, mingkun2020 and mildaniel and removed request for a team and mingkun2020 July 20, 2022 20:02
@jfuss jfuss requested a review from hawflau July 20, 2022 20:02
if self.Enabled is not None:
events_rule.State = "ENABLED" if self.Enabled else "DISABLED"
if isinstance(self.Enabled, bool):
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are introducing a new property to get the behavior right with intrinsic support, why don't we just leave this as it was before?

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant to revert this back but looks like it got lost in me putting this task up and down. Will update.

@@ -122,8 +123,18 @@ def to_cloudformation(self, **kwargs):
resources.append(events_rule)

events_rule.ScheduleExpression = self.Schedule

if self.State and self.Enabled:
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we should explicitly check self.Enabled is not None. Consider:

Enabled: false # bool
State: ENABLED

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch. Will make sure I add a test for this case too.

Copy link
Contributor

@hawflau hawflau left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/pm-review Waiting for review by our Product Manager, please don't work on this yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.