Skip to content

fix: Lambda timeout from parameter (#925)#1202

Merged
awood45 merged 2 commits intoaws:developfrom
setrofim:develop
Oct 29, 2019
Merged

fix: Lambda timeout from parameter (#925)#1202
awood45 merged 2 commits intoaws:developfrom
setrofim:develop

Conversation

@setrofim
Copy link
Contributor

Issue #, if available:
#925

Description of changes:

This fixes the specific case used as the example in the issue of using parameters to specify the Timeout for Lambdas.

As per CloudFormation documentation (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html) the fact that the the Type of the parameter is ignored and the value is passed as a string appears to be expected behaviour. Therefore, I'm doing the numeric conversion just before passing the value to the Function.

Checklist:

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

@setrofim setrofim force-pushed the develop branch 3 times, most recently from 9b538be to 8d4b50e Compare May 31, 2019 10:00
@sriram-mv
Copy link
Contributor

sriram-mv commented May 31, 2019

are you not able pass timeout as parameter override with the current model? and thats you are evaluating Timeout?

Edit: checked with local invoke, this broke. Created a new timeout parameter, and ref'd it.

sam local invoke --parameter-overrides='ParameterKey=MyTimeOut,ParameterValue=20'

@setrofim
Copy link
Contributor Author

setrofim commented Jun 4, 2019

Please could you provide details of what broke? I tried testing sam local invoke on my setup, but it seems to be working fine for me.

@sriram-mv
Copy link
Contributor

@setrofim as in I was testing ref on a timeout parameter without applying this PR patch.

@setrofim
Copy link
Contributor Author

setrofim commented Jun 5, 2019

Ah I see. Sorry, I misunderstood.

@sriram-mv
Copy link
Contributor

Can we add an integ test for this as well, happy to merge it after its done.

@setrofim
Copy link
Contributor Author

setrofim commented Jun 7, 2019

I have added an integration test for this (and confirmed that it fails without the fix).

Copy link
Contributor

@sriram-mv sriram-mv left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Why ast here instead of doing an int() conversation?

In either case if the string can't be casted into a int, ast.literal_eval will throw SyntaxError and int(timeout) will throw ValueError. We should be catching and handling them gracefully here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did an ast.literal_eval here in case the value is a float (as the parameter type is Number). I shall catch and re-raise as ValueError -- thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the change. It looks like now appveyor tests are failing, however, looking a the errors, I don't believe it's related to my change? (Seems to be a permissions issue.)

@setrofim
Copy link
Contributor Author

setrofim commented Jul 3, 2019

@thesriram @jfuss is there anything else required from me for this?

@sriram-mv
Copy link
Contributor

No, I dont think so, I re-kicked the build now.

Copy link
Contributor

Choose a reason for hiding this comment

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

This will raise a ValueError up the chain and wont be caught. This will show up as a command failure with a stack track. We should raise a custom error/exception here to avoid that and provide a better customer experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there an existing exception used for this? Is there an existing convention for how this is handled in the codeline?

Copy link
Contributor

Choose a reason for hiding this comment

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

@setrofim You can follow what we are currently doing for Invalid Layer ARNs.

We throw there and the exception is defined here

There is currently an exception for InvalidSamTemplateException. This might be sufficient here with a good error message (what you currently have is fine). You can define a more specific to improve code readability but either works.

When defining exceptions, make sure the inherit from UserException. This will make sure the correct information is added to the exception so Click will work as expected (no stack trace and printing the error message to console). Only other this is to just update your current unit test to expect the new exception instead of ValueError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the delayed response. I have now made the change -- I stuck with InvalidSamTemplateException as that see to cover this case.

@jfuss jfuss self-assigned this Jul 25, 2019
@setrofim
Copy link
Contributor Author

setrofim commented Sep 2, 2019

Are there any outstanding issues with this?

@jfuss jfuss added the stage/accepted Accepted and will be fixed label Oct 28, 2019
@awood45 awood45 merged commit b462e06 into aws:develop Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stage/accepted Accepted and will be fixed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants