-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Handle Container Creation Failure in local invoke
, local start-api
and local start-lambda
#6719
Conversation
@@ -219,6 +225,10 @@ def __enter__(self) -> "InvokeContext": | |||
|
|||
self._stacks = self._get_stacks() | |||
|
|||
if self._ctx: | |||
LOG.info("Validating template %s\n", self._template_file) | |||
run_sam_validate(ctx=self._ctx, template=self._template_file, lint=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this going to fail the command if validation fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like it could raise User Exception. Does it make sense to not be able to run invoke if a template is invalid?
local invoke
, local start-api
and local start-lambda
ctx dict | ||
Optional. Command invoke context used to invoke commands before invoking `sam local` logic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are only using to grab the debug
flag, maybe we can pass that field instead of the whole Context
object?
@@ -220,6 +226,11 @@ def __enter__(self) -> "InvokeContext": | |||
|
|||
self._stacks = self._get_stacks() | |||
|
|||
if self._ctx: | |||
_, matches_output = get_lint_matches(self._template_file, self._ctx.debug, self._aws_region) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we wrap this call with try/except
since there might be some exceptions which is thrown by linter logic? (I saw we are checking valid region configuration for instance).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing previous comments! Left an unblocking comment trying to make sure we are catching possible exceptions from this new method call.
_, matches_output = get_lint_matches(self._template_file, self._verbose, self._aws_region) | ||
if matches_output: | ||
LOG.warning("Lint Error found, containter creation might fail: %s", matches_output) | ||
except UserException as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make sure everything is wrapped as UserException
so there won't be a new exception type which might be thrown from get_lint_matches
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors within cfn-lint seem to be caught and wrapped as CfnLintExitException
which is handled in this method. I think it should be fine.
Re-raising this PR to handoff to another developer, since the previous PR was from a personal fork.
Validate function
MemorySize
to be an integer within range[128, 10240]
as per docs.Also had to fix a bunch of unit tests that previously had fake MemorySize.
Which issue(s) does this change fix?
#6510
Why is this change necessary?
Customers were permitted to build Lambda functions with invalid MemorySize, causing late/unexpected failure
How does it address the issue?
__init__
ofInvokeContext
, run lint and display any lint errors as warningDockerContainerCreationFailedException
. Eachlocal
command can handle the error differently:local invoke
will surface this error and exitlocal start-api
andlocal start-lambda
will display a warning but would not exit the processWhat side effects does this change have?
N/A
Mandatory Checklist
PRs will only be reviewed after checklist is complete
make pr
passesmake update-reproducible-reqs
if dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.