Skip to content

Fix EventSource Schedule passes Enabled to State - #1666

Merged
jfuss merged 6 commits into
aws:developfrom
lightpriest:fix-schedule-enabled-intrinsic
Jul 22, 2022
Merged

jfuss merged 6 commits into
aws:developfrom
lightpriest:fix-schedule-enabled-intrinsic

Conversation

@lightpriest

@lightpriest lightpriest commented Jul 27, 2020 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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
Copy Markdown
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

lightpriest commented Jul 27, 2020 •

Copy link
Copy Markdown
Contributor Author

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

@lightpriest

Copy link
Copy Markdown
Contributor Author

Any comments? Something? :)

@Schwusch

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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?

@lightpriest lightpriest Oct 26, 2020 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown

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
Copy Markdown
Contributor Author

Anyone? 🥺

@milesgranger

milesgranger commented Nov 14, 2020 •

Copy link
Copy Markdown

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, mildaniel and mingkun2020 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
Copy Markdown
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
Copy Markdown
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.


events_rule.ScheduleExpression = self.Schedule

if self.State and self.Enabled:

Copy link
Copy Markdown
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
Copy Markdown
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.

@hawflau hawflau left a comment

Copy link
Copy Markdown
Contributor

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.