-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle Container Creation Failure in
local invoke
, `local start-api…
…` and `local start-lambda` (#6719) * Refactor to run sam validate before any sam local logic * Formatting * refactor sam validate * raise docker image creation error * fix lint errors * update type hint * handle container creation error in local apigw service * reformat * handle errors in local api invoke and local lambda invoke * move exception * handle error in local invoke * remove unnecessary integration tests * fix formatting * use try/except to run lint --------- Co-authored-by: Jared Bentvelsen <[email protected]> Co-authored-by: Wing Fung Lau <[email protected]>
- Loading branch information
1 parent
1305c33
commit 9bcbc04
Showing
19 changed files
with
269 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from typing import List, Optional, Tuple | ||
|
||
|
||
def get_lint_matches(template: str, debug: Optional[bool] = None, region: Optional[str] = None) -> Tuple[List, str]: | ||
""" | ||
Parses provided SAM template and maps errors from CloudFormation template back to SAM template. | ||
Cfn-lint loggers are added to the SAM cli logging hierarchy which at the root logger | ||
configures with INFO level logging and a different formatting. This exposes and duplicates | ||
some cfn-lint logs that are not typically shown to customers. Explicitly setting the level to | ||
WARNING and propagate to be False remediates these issues. | ||
Parameters | ||
----------- | ||
template | ||
Path to the template file | ||
debug | ||
Enable debug mode | ||
region | ||
AWS region to run against | ||
""" | ||
|
||
import logging | ||
|
||
import cfnlint.core # type: ignore | ||
|
||
from samcli.commands.exceptions import UserException | ||
|
||
cfn_lint_logger = logging.getLogger("cfnlint") | ||
cfn_lint_logger.propagate = False | ||
|
||
try: | ||
lint_args = [template] | ||
if debug: | ||
lint_args.append("--debug") | ||
if region: | ||
lint_args.append("--region") | ||
lint_args.append(region) | ||
|
||
(args, filenames, formatter) = cfnlint.core.get_args_filenames(lint_args) | ||
cfn_lint_logger.setLevel(logging.WARNING) | ||
matches = list(cfnlint.core.get_matches(filenames, args)) | ||
if not matches: | ||
return matches, "" | ||
|
||
rules = cfnlint.core.get_used_rules() | ||
matches_output = formatter.print_matches(matches, rules, filenames) | ||
return matches, matches_output | ||
|
||
except cfnlint.core.InvalidRegionException as e: | ||
raise UserException( | ||
"AWS Region was not found. Please configure your region through the --region option", | ||
wrapped_from=e.__class__.__name__, | ||
) from e | ||
except cfnlint.core.CfnLintExitException as lint_error: | ||
raise UserException( | ||
lint_error, | ||
wrapped_from=lint_error.__class__.__name__, | ||
) from lint_error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.