Automatically notify when a lambda may timeout #1324
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
We can never be 100% sure that a timeout will happen because we need to notify with enough time for the event to be delivered. Therefore this is a best effort with a generous default value (1000ms) that errs on the side of delivering the warning at the cost of possible false positives. The default value can be changed by providing the new
lambdaTimeoutNotifyMs
parameter tocreateHandler
, e.g.:If set to "0" we don't bother adding the warning at all. This is largely arbitrary as a value of 0 would never be triggered (because the lambda would timeout at the same time so we would never be able to deliver the event) but it allows users to turn this feature off if they don't want it
Testing
This can only be covered by unit tests because of a bug in AWS' SAM CLI: aws/aws-sam-cli#2519
In short, SAM returns a Unix timestamp from
getRemainingTimeInMillis
so the timeout could never be triggered withsam local invoke
(short of mocking the function, which isn't really better than a unit test)