Skip to content

Bug: sam validate - TypeError #7973

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

Open
emusiienko opened this issue Apr 8, 2025 · 0 comments · May be fixed by #7983
Open

Bug: sam validate - TypeError #7973

emusiienko opened this issue Apr 8, 2025 · 0 comments · May be fixed by #7983
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Comments

@emusiienko
Copy link

Description:

Sam crashed when I call "sam validate"

Steps to reproduce:

call sam validate -t template.yaml

using my template.yaml file

Observed result:

Utility crashes

Expected result:

Utility doesn't crash

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

  1. OS: Mac OS 14.5
  2. sam --version: 1.137.0
  3. AWS region: us-east-1
# Paste the output of `sam --info` here

Add --debug flag to command you are running

2025-04-08 20:00:37,424 | Config file location: /Users/Evgeniy/Work/Projects/Wallstreet_prep/samconfig.toml
2025-04-08 20:00:37,425 | Loading configuration values from [default.['validate'].parameters] (env.command_name.section) in config file at '/Users/Evgeniy/Work/Projects/Wallstreet_prep/samconfig.toml'...
2025-04-08 20:00:37,426 | Configuration values successfully loaded.
2025-04-08 20:00:37,426 | Configuration values are: {'stack_name': 'wallstreet-prep-chatbot', 'lint': True}
2025-04-08 20:00:37,446 | Using config file: samconfig.toml, config environment: default
2025-04-08 20:00:37,446 | Expand command line arguments to:
2025-04-08 20:00:37,446 | --template_file=/Users/Evgeniy/Work/Projects/Wallstreet_prep/template.yaml --lint
2025-04-08 20:00:37 Looking for CFLINTRC before attempting to load
2025-04-08 20:00:37 Validating User CFNLINTRC
2025-04-08 20:00:37 Validating CFNLINTRC config with given JSONSchema
2025-04-08 20:00:37 Schema used: {'$id': 'https://github.com/aws-cloudformation/cfn-python-lint/blob/main/src/cfnlint/data/CfnLintCli/config/schema.json', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'CFNLINTRC configuration schema', 'properties': {'append_rules': {'description': 'Location of directories to append rules from', 'items': {'type': 'string'}, 'type': 'array'}, 'configure_rules': {'additionalProperties': False, 'description': 'Configure rules', 'patternProperties': {'^.$': {'patternProperties': {'^.$': {'anyOf': [{'type': 'string'}, {'type': 'integer'}, {'type': 'boolean'}, {'items': {'type': 'string'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'boolean'}]}}, 'type': 'object'}}, 'type': 'object'}, 'custom_rules': {'description': 'custom rule file to use', 'type': 'string'}, 'debug': {'description': 'Debug mode', 'type': 'boolean'}, 'ignore_bad_template': {'description': 'Ignore bad templates', 'type': 'boolean'}, 'ignore_checks': {'description': 'List of checks to ignore', 'items': {'type': 'string'}, 'type': 'array'}, 'ignore_templates': {'description': 'Templates to ignore', 'items': {'type': 'string'}, 'type': 'array'}, 'include_checks': {'description': 'List of checks to include', 'items': {'type': 'string'}, 'type': 'array'}, 'mandatory_checks': {'description': 'List of mandatory checks to enforce', 'items': {'type': 'string'}, 'type': 'array'}, 'merge_configs': {'description': 'Merges lists between configuration layers', 'type': 'boolean'}, 'output_file': {'description': 'Path to the file to write the main output to', 'type': 'string'}, 'override_spec': {'description': 'Path to spec file to override with', 'type': 'string'}, 'regions': {'description': 'Regions to test against', 'items': {'type': 'string'}, 'type': 'array'}, 'registry_schemas': {'description': 'One or more directories of CloudFormation Registry Resource Schemas', 'items': {'type': 'string'}, 'type': 'array'}, 'templates': {'description': 'Templates to lint', 'items': {'type': 'string'}, 'type': 'array'}}, 'title': 'CFNLINTRC JSON Schema', 'type': 'object'}
2025-04-08 20:00:37 Config used: {}
2025-04-08 20:00:37 CFNLINTRC looks valid!
2025-04-08 20:00:37 Validating Project CFNLINTRC
2025-04-08 20:00:37 Validating CFNLINTRC config with given JSONSchema
2025-04-08 20:00:37 Schema used: {'$id': 'https://github.com/aws-cloudformation/cfn-python-lint/blob/main/src/cfnlint/data/CfnLintCli/config/schema.json', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'CFNLINTRC configuration schema', 'properties': {'append_rules': {'description': 'Location of directories to append rules from', 'items': {'type': 'string'}, 'type': 'array'}, 'configure_rules': {'additionalProperties': False, 'description': 'Configure rules', 'patternProperties': {'^.$': {'patternProperties': {'^.$': {'anyOf': [{'type': 'string'}, {'type': 'integer'}, {'type': 'boolean'}, {'items': {'type': 'string'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'boolean'}]}}, 'type': 'object'}}, 'type': 'object'}, 'custom_rules': {'description': 'custom rule file to use', 'type': 'string'}, 'debug': {'description': 'Debug mode', 'type': 'boolean'}, 'ignore_bad_template': {'description': 'Ignore bad templates', 'type': 'boolean'}, 'ignore_checks': {'description': 'List of checks to ignore', 'items': {'type': 'string'}, 'type': 'array'}, 'ignore_templates': {'description': 'Templates to ignore', 'items': {'type': 'string'}, 'type': 'array'}, 'include_checks': {'description': 'List of checks to include', 'items': {'type': 'string'}, 'type': 'array'}, 'mandatory_checks': {'description': 'List of mandatory checks to enforce', 'items': {'type': 'string'}, 'type': 'array'}, 'merge_configs': {'description': 'Merges lists between configuration layers', 'type': 'boolean'}, 'output_file': {'description': 'Path to the file to write the main output to', 'type': 'string'}, 'override_spec': {'description': 'Path to spec file to override with', 'type': 'string'}, 'regions': {'description': 'Regions to test against', 'items': {'type': 'string'}, 'type': 'array'}, 'registry_schemas': {'description': 'One or more directories of CloudFormation Registry Resource Schemas', 'items': {'type': 'string'}, 'type': 'array'}, 'templates': {'description': 'Templates to lint', 'items': {'type': 'string'}, 'type': 'array'}}, 'title': 'CFNLINTRC JSON Schema', 'type': 'object'}
2025-04-08 20:00:37 Config used: {}
2025-04-08 20:00:37 CFNLINTRC looks valid!
2025-04-08 20:00:37 User configuration loaded as
2025-04-08 20:00:37 {}
2025-04-08 20:00:37 Project configuration loaded as
2025-04-08 20:00:37 {}
2025-04-08 20:00:37 Merging configurations...
2025-04-08 20:00:37 Run scan of template None
2025-04-08 20:00:37 SAM Translator: 1.96.0
2025-04-08 20:00:37 Setting AWS_DEFAULT_REGION to us-east-1
2025-04-08 20:00:37 Transformed template from AWS::Serverless-2016-10-31:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "wallstreet-prep-chatbot\nSample SAM Template for wallstreet-prep-chatbot\n",
"Outputs": {
"HelloWorldApi": {
"Description": "API Gateway endpoint URL for Prod stage for Hello World function",
"Value": "test"
}
},
"Parameters": {
"ArchitectureParameter": {
"AllowedValues": [
"x86_64",
"arm64"
],
"Default": "x86_64",
"Description": "Enter lambda architecture",
"Type": "String"
},
"AssistantId": {
"Default": "",
"Description": "The Assistant Id",
"NoEcho": true,
"Type": "String"
},
"MaxHistoryLength": {
"Default": "",
"Type": "String"
},
"MessageSimilarityThreshold": {
"Default": "",
"Type": "String"
},
"MinHistoryLength": {
"Default": "",
"Type": "String"
},
"OpenAIAPIKey": {
"Default": "",
"Description": "The OpenAI key",
"NoEcho": true,
"Type": "String"
},
"OpenSearchRedundancy": {
"Default": "ENABLED",
"Description": "Defines if opensearch collection has deployed to 2 AZ's for high availability. High availability also means *2 cost",
"Type": "String"
},
"RelatedContentSimilarityScoreThreshold": {
"Default": "",
"Type": "String"
},
"UseAssistantBasedResponses": {
"Default": "false",
"Type": "String"
}
},
"Resources": {
"ApplicationInsightsMonitoring": {
"Properties": {
"AutoConfigurationEnabled": "true",
"ResourceGroupName": {
"Ref": "ApplicationResourceGroup"
}
},
"Type": "AWS::ApplicationInsights::Application"
},
"ApplicationResourceGroup": {
"Properties": {
"Name": {
"Fn::Sub": "ApplicationInsights-SAM-${AWS::StackName}"
},
"ResourceQuery": {
"Type": "CLOUDFORMATION_STACK_1_0"
}
},
"Type": "AWS::ResourceGroups::Group"
},
"Assistant": {
"Properties": {
"Location": "./.aws/assistant.yaml",
"Parameters": {
"ArchitectureParameter": {
"Ref": "ArchitectureParameter"
},
"AssistantId": {
"Ref": "AssistantId"
},
"MaxHistoryLength": {
"Ref": "MaxHistoryLength"
},
"MessageSimilarityThreshold": {
"Ref": "MessageSimilarityThreshold"
},
"MinHistoryLength": {
"Ref": "MinHistoryLength"
},
"OpenAIAPIKey": {
"Ref": "OpenAIAPIKey"
},
"OpensearchCollectionUrl": {
"Fn::GetAtt": [
"OpenSearchCollection",
"Outputs.OpenSearchCollectionEndpointUrl"
]
},
"PrivateSubnetId": {
"Fn::GetAtt": [
"Network",
"Outputs.PrivateSubnetId"
]
},
"RelatedContentSimilarityScoreThreshold": {
"Ref": "RelatedContentSimilarityScoreThreshold"
},
"SecurityGroup": {
"Fn::GetAtt": [
"Network",
"Outputs.SecurityGroupId"
]
},
"UseAssistantBasedResponses": {
"Ref": "UseAssistantBasedResponses"
}
},
"TemplateUrl": "./.aws/assistant.yaml"
},
"Type": "AWS::Serverless::Application"
},
"CloudWatch": {
"Properties": {
"Location": "./.aws/cloudwatch.yaml",
"Parameters": {
"Lambdas": {
"Fn::GetAtt": [
"Assistant",
"Outputs.Lambdas"
]
}
},
"TemplateUrl": "./.aws/cloudwatch.yaml"
},
"Type": "AWS::Serverless::Application"
},
"Glue": {
"Properties": {
"Location": "./.aws/glue.yaml",
"Parameters": {
"ConnectionAvailabilityZone": {
"Fn::GetAtt": [
"Network",
"Outputs.PrivateSubnetAZ"
]
},
"PrivateSubnetId": {
"Fn::GetAtt": [
"Network",
"Outputs.PrivateSubnetId"
]
},
"SecurityGroup": {
"Fn::GetAtt": [
"Network",
"Outputs.SecurityGroupId"
]
}
},
"TemplateUrl": "./.aws/glue.yaml"
},
"Type": "AWS::Serverless::Application"
},
"IAM": {
"Properties": {
"Location": "./.aws/iam.yaml",
"TemplateUrl": "./.aws/iam.yaml"
},
"Type": "AWS::Serverless::Application"
},
"Network": {
"Properties": {
"Location": "./.aws/network.yaml",
"TemplateUrl": "./.aws/network.yaml"
},
"Type": "AWS::Serverless::Application"
},
"OpenSearchCollection": {
"Properties": {
"Location": "./.aws/opensearch.yaml",
"Parameters": {
"OpenSearchRedundancy": {
"Ref": "OpenSearchRedundancy"
},
"PrincipalsIAMRoleArns": {
"Fn::Join": [
",",
[
{
"Fn::GetAtt": [
"IAM",
"Outputs.ContentManagerLambdaRoleArn"
]
},
{
"Fn::GetAtt": [
"IAM",
"Outputs.ContentSearchLambdaRoleArn"
]
},
{
"Fn::GetAtt": [
"IAM",
"Outputs.AWSGlueServiceRoleArn"
]
}
]
]
},
"PrincipalsIAMRoleNames": {
"Fn::Join": [
",",
[
{
"Fn::GetAtt": [
"IAM",
"Outputs.ContentManagerLambdaRoleName"
]
},
{
"Fn::GetAtt": [
"IAM",
"Outputs.ContentSearchLambdaRoleName"
]
},
{
"Fn::GetAtt": [
"IAM",
"Outputs.AWSGlueServiceRoleName"
]
}
]
]
},
"PrivateSubnetId": {
"Fn::GetAtt": [
"Network",
"Outputs.PrivateSubnetId"
]
},
"SecurityGroup": {
"Fn::GetAtt": [
"Network",
"Outputs.SecurityGroupId"
]
},
"VpcId": {
"Fn::GetAtt": [
"Network",
"Outputs.VPCId"
]
}
},
"TemplateUrl": "./.aws/opensearch.yaml"
},
"Type": "AWS::Serverless::Application"
}
},
"Transform": "AWS::Serverless-2016-10-31"
}
2025-04-08 20:00:37 Transformed template:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "wallstreet-prep-chatbot\nSample SAM Template for wallstreet-prep-chatbot\n",
"Outputs": {
"HelloWorldApi": {
"Description": "API Gateway endpoint URL for Prod stage for Hello World function",
"Value": "test"
}
},
"Parameters": {
"ArchitectureParameter": {
"AllowedValues": [
"x86_64",
"arm64"
],
"Default": "x86_64",
"Description": "Enter lambda architecture",
"Type": "String"
},
"AssistantId": {
"Default": "",
"Description": "The Assistant Id",
"NoEcho": true,
"Type": "String"
},
"MaxHistoryLength": {
"Default": "",
"Type": "String"
},
"MessageSimilarityThreshold": {
"Default": "",
"Type": "String"
},
"MinHistoryLength": {
"Default": "",
"Type": "String"
},
"OpenAIAPIKey": {
"Default": "",
"Description": "The OpenAI key",
"NoEcho": true,
"Type": "String"
},
"OpenSearchRedundancy": {
"Default": "ENABLED",
"Description": "Defines if opensearch collection has deployed to 2 AZ's for high availability. High availability also means *2 cost",
"Type": "String"
},
"RelatedContentSimilarityScoreThreshold": {
"Default": "",
"Type": "String"
},
"UseAssistantBasedResponses": {
"Default": "false",
"Type": "String"
}
},
"Resources": {
"ApplicationInsightsMonitoring": {
"Properties": {
"AutoConfigurationEnabled": "true",
"ResourceGroupName": {
"Ref": "ApplicationResourceGroup"
}
},
"Type": "AWS::ApplicationInsights::Application"
},
"ApplicationResourceGroup": {
"Properties": {
"Name": {
"Fn::Sub": "ApplicationInsights-SAM-${AWS::StackName}"
},
"ResourceQuery": {
"Type": "CLOUDFORMATION_STACK_1_0"
}
},
"Type": "AWS::ResourceGroups::Group"
},
"Assistant": {
"Properties": {
"Parameters": {
"ArchitectureParameter": {
"Ref": "ArchitectureParameter"
},
"AssistantId": {
"Ref": "AssistantId"
},
"MaxHistoryLength": {
"Ref": "MaxHistoryLength"
},
"MessageSimilarityThreshold": {
"Ref": "MessageSimilarityThreshold"
},
"MinHistoryLength": {
"Ref": "MinHistoryLength"
},
"OpenAIAPIKey": {
"Ref": "OpenAIAPIKey"
},
"OpensearchCollectionUrl": {
"Fn::GetAtt": [
"OpenSearchCollection",
"Outputs.OpenSearchCollectionEndpointUrl"
]
},
"PrivateSubnetId": {
"Fn::GetAtt": [
"Network",
"Outputs.PrivateSubnetId"
]
},
"RelatedContentSimilarityScoreThreshold": {
"Ref": "RelatedContentSimilarityScoreThreshold"
},
"SecurityGroup": {
"Fn::GetAtt": [
"Network",
"Outputs.SecurityGroupId"
]
},
"UseAssistantBasedResponses": {
"Ref": "UseAssistantBasedResponses"
}
},
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
],
"TemplateURL": "./.aws/assistant.yaml"
},
"Type": "AWS::CloudFormation::Stack"
},
"CloudWatch": {
"Properties": {
"Parameters": {
"Lambdas": {
"Fn::GetAtt": [
"Assistant",
"Outputs.Lambdas"
]
}
},
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
],
"TemplateURL": "./.aws/cloudwatch.yaml"
},
"Type": "AWS::CloudFormation::Stack"
},
"Glue": {
"Properties": {
"Parameters": {
"ConnectionAvailabilityZone": {
"Fn::GetAtt": [
"Network",
"Outputs.PrivateSubnetAZ"
]
},
"PrivateSubnetId": {
"Fn::GetAtt": [
"Network",
"Outputs.PrivateSubnetId"
]
},
"SecurityGroup": {
"Fn::GetAtt": [
"Network",
"Outputs.SecurityGroupId"
]
}
},
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
],
"TemplateURL": "./.aws/glue.yaml"
},
"Type": "AWS::CloudFormation::Stack"
},
"IAM": {
"Properties": {
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
],
"TemplateURL": "./.aws/iam.yaml"
},
"Type": "AWS::CloudFormation::Stack"
},
"Network": {
"Properties": {
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
],
"TemplateURL": "./.aws/network.yaml"
},
"Type": "AWS::CloudFormation::Stack"
},
"OpenSearchCollection": {
"Properties": {
"Parameters": {
"OpenSearchRedundancy": {
"Ref": "OpenSearchRedundancy"
},
"PrincipalsIAMRoleArns": {
"Fn::Join": [
",",
[
{
"Fn::GetAtt": [
"IAM",
"Outputs.ContentManagerLambdaRoleArn"
]
},
{
"Fn::GetAtt": [
"IAM",
"Outputs.ContentSearchLambdaRoleArn"
]
},
{
"Fn::GetAtt": [
"IAM",
"Outputs.AWSGlueServiceRoleArn"
]
}
]
]
},
"PrincipalsIAMRoleNames": {
"Fn::Join": [
",",
[
{
"Fn::GetAtt": [
"IAM",
"Outputs.ContentManagerLambdaRoleName"
]
},
{
"Fn::GetAtt": [
"IAM",
"Outputs.ContentSearchLambdaRoleName"
]
},
{
"Fn::GetAtt": [
"IAM",
"Outputs.AWSGlueServiceRoleName"
]
}
]
]
},
"PrivateSubnetId": {
"Fn::GetAtt": [
"Network",
"Outputs.PrivateSubnetId"
]
},
"SecurityGroup": {
"Fn::GetAtt": [
"Network",
"Outputs.SecurityGroupId"
]
},
"VpcId": {
"Fn::GetAtt": [
"Network",
"Outputs.VPCId"
]
}
},
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
],
"TemplateURL": "./.aws/opensearch.yaml"
},
"Type": "AWS::CloudFormation::Stack"
}
}
}
2025-04-08 20:00:37,989 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2025-04-08 20:00:37,990 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2025-04-08 20:00:37,990 | Unable to find Click Context for getting session_id.

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 "", 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 "", line 399, in abspath

An unexpected error was encountered while executing "sam validate".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20validate%20-%20TypeError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20validate%20-%20TypeError

Archive.zip

@emusiienko emusiienko added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Apr 8, 2025
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
1 participant