Skip to content
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

Bug: sam validate - TypeError during lint #7956

Closed
LucasDreyerSanlam opened this issue Mar 28, 2025 · 9 comments · Fixed by #7967
Closed

Bug: sam validate - TypeError during lint #7956

LucasDreyerSanlam opened this issue Mar 28, 2025 · 9 comments · Fixed by #7967
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Comments

@LucasDreyerSanlam
Copy link

Description:

Since version 1.136.0 (release a few hours ago), we're getting a stacktrace (from cfnlint) when trying to run the linter.

Steps to reproduce:

Create two templates, with one referring to the other:

cat << 'EOF' > template.yml
AWSTemplateFormatVersion: "2010-09-09"

Transform:
  - AWS::Serverless-2016-10-31

Resources:
  MyServerlessApi:
    Type: AWS::Serverless::Application
    Properties:
      Location: template.serverless.yml
EOF

cat << 'EOF' > template.serverless.yml
AWSTemplateFormatVersion: "2010-09-09"

Transform:
  - AWS::Serverless-2016-10-31

Resources:
  MyApi:
    Type: AWS::Serverless::Api

EOF

Run the linter on the main template:

$ sam validate -t ./template.yml --lint

Error: expected str, bytes or os.PathLike object, not NoneType

Observed result:

$ sam validate -t ./template.yml --lint

Error: expected str, bytes or os.PathLike object, not NoneType
Traceback:
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/samcli/cli/cli_config_file.py", line 347, in wrapper
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/samcli/lib/telemetry/metric.py", line 185, in wrapped
    raise exception  # pylint: disable=raising-bad-type
    ^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/samcli/lib/telemetry/metric.py", line 150, in wrapped
    return_value = func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/samcli/lib/utils/version_checker.py", line 43, in wrapped
    actual_result = func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/samcli/cli/main.py", line 95, in wrapper
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/samcli/commands/_utils/cdk_support_decorators.py", line 40, in wrapped
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/samcli/commands/_utils/command_exception_handler.py", line 89, in wrapper_command_exception_handler
    raise ex
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/samcli/commands/_utils/command_exception_handler.py", line 69, in wrapper_command_exception_handler
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/samcli/commands/validate/validate.py", line 70, in cli
    do_cli(ctx, template_file, lint)  # pragma: no cover
    ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/samcli/commands/validate/validate.py", line 87, in do_cli
    _lint(ctx, sam_template.serialized, template)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/samcli/commands/validate/validate.py", line 176, in _lint
    matches = lint(template, config=config)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/cfnlint/api.py", line 63, in lint
    return list(runner.validate_template(None, template))
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/cfnlint/runner.py", line 331, in validate_template
    yield from runner.run()
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/cfnlint/runner.py", line 143, in run
    matches = self.cfn.transform()
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/cfnlint/template/template.py", line 118, in transform
    results = transform.transform(self)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/cfnlint/template/transforms/transform.py", line 75, in transform
    cfn.context = create_context_for_template(cfn)
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/cfnlint/context/context.py", line 515, in create_context_for_template
    resources = _init_resources(cfn.template.get("Resources", {}), cfn.filename)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/cfnlint/context/context.py", line 494, in _init_resources
    obj[k] = Resource(v, filename)
             ~~~~~~~~^^^^^^^^^^^^^
  File "<string>", line 3, in __init__
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/cfnlint/context/context.py", line 458, in __post_init__
    self._nested_stack_get_atts = _nested_stack_get_atts(
                                  ~~~~~~~~~~~~~~~~~~~~~~^
        filename, template_url
        ^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.136.0/libexec/lib/python3.13/site-packages/cfnlint/context/context.py", line 402, in _nested_stack_get_atts
    base_dir = os.path.dirname(os.path.abspath(filename))
                               ~~~~~~~~~~~~~~~^^^^^^^^^^
  File "<frozen posixpath>", line 378, in abspath

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

Expected result:

Version <= 1.135.0 produces:

$ sam validate -t ./template.yml --lint
template.yml is a valid SAM Template

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

sam --info
{
  "version": "1.136.0",
  "system": {
    "python": "3.13.2",
    "os": "macOS-14.3-arm64-arm-64bit-Mach-O"
  },
  "additional_dependencies": {
    "docker_engine": "27.4.0",
    "aws_cdk": "Not available",
    "terraform": "1.9.8"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

We're seeing the exact same error in our Github actions pipeline runners, they're on Ubuntu:24.04.2

@LucasDreyerSanlam LucasDreyerSanlam added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Mar 28, 2025
@paulbrazell
Copy link

Also seeing this issue with GitHub Actions runners. SAM version 1.136.0. Works fine on 1.131.0 on local machine. This issue is blocking our deployment pipeline.

Error: expected str, bytes or os.PathLike object, not NoneType
Traceback:
  File "click/core.py", line 1078, in main
  File "click/core.py", line 1688, in invoke
  File "click/core.py", line 1434, in invoke
  File "click/core.py", line 783, 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 783, 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 63, in lint
    return list(runner.validate_template(None, template))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cfnlint/runner.py", line 331, in validate_template
    yield from runner.run()
  File "cfnlint/runner.py", line 143, in run
    matches = self.cfn.transform()
              ^^^^^^^^^^^^^^^^^^^^
  File "cfnlint/template/template.py", line 118, in transform
    results = transform.transform(self)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cfnlint/template/transforms/transform.py", line 75, in transform
    cfn.context = create_context_for_template(cfn)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cfnlint/context/context.py", line 513, in create_context_for_template
    resources = _init_resources(cfn.template.get("Resources", {}), cfn.filename)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cfnlint/context/context.py", line 492, in _init_resources
    obj[k] = Resource(v, filename)
             ^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 3, in __init__
  File "cfnlint/context/context.py", line 456, in __post_init__
    self._nested_stack_get_atts = _nested_stack_get_atts(
                                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "cfnlint/context/context.py", line 401, in _nested_stack_get_atts
    base_dir = os.path.dirname(os.path.abspath(filename))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 399, in abspath
An unexpected error was encountered while executing "sam validate".

@vicheey
Copy link
Contributor

vicheey commented Mar 28, 2025

Thank you for reporting this. Let me take a look.

@ritzj-cf
Copy link

+1

@malkitsingh
Copy link

we are also facing problem with this version in our github actions. As a temp fix/work around, we have hard coded the version to 1.135.0 like this

- uses: aws-actions/setup-sam@v2
        with:
          use-installer: true
          version: 1.135.0

@mbfreder
Copy link
Contributor

mbfreder commented Apr 1, 2025

Thank you for reporting this issue. After investigation, we've identified that this is caused by a bug in cfn-lint version 1.30.0 and newer.

We've created an (issue) in the cfn-lint repository to address this problem.

We'll be tracking the cfn-lint issue and will update SAM CLI to use the fixed version once it's available.

@marian-aircall
Copy link

Seems like cfn-lint solved the issue. Can you please provide us un update on this? Thanks

@mbfreder
Copy link
Contributor

mbfreder commented Apr 3, 2025

Hi there, we will release a new version of SAM CLI (with the updated cfn-lint version) next week.

Copy link
Contributor

github-actions bot commented Apr 4, 2025

⚠️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.

@tatsuya6502
Copy link

tatsuya6502 commented Apr 9, 2025

Hi. Thank you for working on this issue and releasing v1.137.0! However, I found that v1.137.0 still crashes with the same stack trace to v1.136.0. So, I created the following issue for v1.137.0. (I do not have permission to reopen this issue, so I created a new one)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
8 participants