Skip to content

Bug: (SAM CLI) Unexpected error running 'sam validate' #8092

Closed

Description

@smathez

Description:

Since I upgraded sam cli to version 1.140, I get the error below every time I try to run sam validate on my templates.

Steps to reproduce:

run sam validate --lint on a sam template

Observed result:

Error: Tried to append rules but got an error: cannot import name 'RESOURCE_SPECS' from 'cfnlint.helpers' (/usr/local/aws-sam-cli/1.140.0/dist/_internal/cfnlint/helpers.pyc)
Traceback:
File "click/core.py", line 1082, in main
File "click/core.py", line 1697, in invoke
File "click/core.py", line 1443, in invoke
File "click/core.py", line 788, in invoke
File "samcli/cli/cli_config_file.py", line 347, in wrapper
File "click/decorators.py", line 92, in new_func
File "click/core.py", line 788, in invoke
File "samcli/lib/telemetry/metric.py", line 185, in wrapped
File "samcli/lib/telemetry/metric.py", line 150, in wrapped
File "samcli/lib/utils/version_checker.py", line 43, in wrapped
File "samcli/cli/main.py", line 95, in wrapper
File "samcli/commands/_utils/cdk_support_decorators.py", line 40, in wrapped
File "samcli/commands/_utils/command_exception_handler.py", line 89, in wrapper_command_exception_handler
File "samcli/commands/_utils/command_exception_handler.py", line 69, in wrapper_command_exception_handler
File "samcli/commands/validate/validate.py", line 70, in cli
File "samcli/commands/validate/validate.py", line 87, in do_cli
File "samcli/commands/validate/validate.py", line 176, in _lint
File "cfnlint/api.py", line 62, in lint
runner = Runner(config_mixin)
^^^^^^^^^^^^^^^^^^^^
File "cfnlint/runner.py", line 233, in init
self._get_rules()
File "cfnlint/runner.py", line 262, in _get_rules
raise UnexpectedRuleException(

An unexpected error was encountered while executing "sam validate".

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

{
  "version": "1.140.0",
  "system": {
    "python": "3.11.10",
    "os": "Linux-6.6.87.1-microsoft-standard-WSL2-x86_64-with-glibc2.35"
  },
  "additional_dependencies": {
    "docker_engine": "Not available",
    "aws_cdk": "Not available",
    "terraform": "1.12.2"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_PACKAGE_PERFORMANCE",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Activity

  1. added
    stage/needs-triageAutomatically applied to new issues and PRs, indicating they haven't been looked at.
    on Jun 13, 2025
  2. smathez commented on Jun 13, 2025

    @smathez
    Author

    After downgrade to 1.138 it works

  3. vicheey commented on Jun 16, 2025

    @vicheey
    Contributor

    Thank you for reporting. I'll try to create the issue.

  4. valerena commented on Jul 3, 2025

    @valerena
    Contributor

    Hi. Do you still have this problem? Can you upgrade your version of SAM CLI to 1.142.1 and check if the problem persist?
    If it still does, can you please tell us more about your environment? Also, how did you install SAM CLI?

    We don't see this problem on our side, so we need a little more information to try see where the problem might be

  5. LaymanTool commented on Aug 6, 2025

    @LaymanTool

    I am on 1.142.1 and problem still persist. I thought that my template was invalid but looks like the command is failing
    cannot import name 'RESOURCE_SPECS' from 'cfnlint.helpers' (/usr/local/aws-sam-cli/1.142.1/dist/_internal/cfnlint/helpers.py)

    Same lines as reported.
    18:18:39 Error: Tried to append rules but got an error: cannot import name 'RESOURCE_SPECS' from 'cfnlint.helpers' (/usr/local/aws-sam-cli/1.142.1/dist/_internal/cfnlint/helpers.py)
    18:18:39 Traceback:
    18:18:39 File "click/core.py", line 1082, in main
    18:18:39 File "click/core.py", line 1697, in invoke
    18:18:39 File "click/core.py", line 1443, in invoke
    18:18:39 File "click/core.py", line 788, in invoke
    18:18:39 File "samcli/cli/cli_config_file.py", line 347, in wrapper
    18:18:39 File "click/decorators.py", line 92, in new_func
    18:18:39 File "click/core.py", line 788, in invoke
    18:18:39 File "samcli/lib/telemetry/metric.py", line 185, in wrapped
    18:18:39 File "samcli/lib/telemetry/metric.py", line 150, in wrapped
    18:18:39 File "samcli/lib/utils/version_checker.py", line 43, in wrapped
    18:18:39 File "samcli/cli/main.py", line 95, in wrapper
    18:18:39 File "samcli/commands/_utils/cdk_support_decorators.py", line 40, in wrapped
    18:18:39 File "samcli/commands/_utils/command_exception_handler.py", line 89, in wrapper_command_exception_handler
    18:18:39 File "samcli/commands/_utils/command_exception_handler.py", line 69, in wrapper_command_exception_handler
    18:18:39 File "samcli/commands/validate/validate.py", line 70, in cli
    18:18:39 File "samcli/commands/validate/validate.py", line 87, in do_cli
    18:18:39 File "samcli/commands/validate/validate.py", line 176, in _lint
    18:18:39 File "cfnlint/api.py", line 63, in lint
    18:18:39 runner = Runner(config_mixin)
    18:18:39 ^^^^^^^^^^^^^^^^^^^^
    18:18:39 File "cfnlint/runner.py", line 233, in init
    18:18:39 self._get_rules()
    18:18:39 File "cfnlint/runner.py", line 262, in _get_rules
    18:18:39 raise UnexpectedRuleException(
    18:18:39
    18:18:39 An unexpected error was encountered while executing "sam validate".
    18:18:39 Search for an existing issue:
    18:18:39 https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20validate%20-%20UnexpectedRuleException
    18:18:39 Or create a bug report:
    18:18:39 https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20validate%20-%20UnexpectedRuleException

    It runs successfully on my earlier version which was 1.98.0

    I might try to download the code and give it a try.

  6. larsborasmussen commented on Aug 13, 2025

    @larsborasmussen

    I think this might be due the a contaminated installation environment.
    i had the same error with 1.142.1 and then i downgraded to 1.138.0 and it was the same error.
    I then removed the two versions from /usr/local/aws-sam-cli/v* and removed the sam-installation directory before installing and that fixed it. now both 1.138.0 and 1.142.1 works for me.

    TLDR: Make sure you don't keep unzipping new versions into the same sam-installation directory when doing upgrades.

  7. github-actions commented on Mar 23, 2026

    @github-actions
    Contributor

    ⚠️COMMENT VISIBILITY WARNING⚠️

    Comments on closed issues are hard for our team to see.
    If you need more assistance, please either tag a team member or open a new issue that references this one.
    If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stage/needs-triageAutomatically applied to new issues and PRs, indicating they haven't been looked at.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions