aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.47k stars 1.16k forks source link

sam build AttributeError #6225

Open pickfire opened 8 months ago

pickfire commented 8 months ago

Description:

AttributeError when sam build

Steps to reproduce:

sam build -u

Observed result:

2023-11-08 17:19:22,238 | Config file location: /Users/ivan/pantas-infra/samconfig.toml                                                                                                          
2023-11-08 17:19:22,241 | Loading configuration values from [default.['build'].parameters] (env.command_name.section) in config file at '/Users/ivan/pantas-infra/samconfig.toml'...             
2023-11-08 17:19:22,242 | Configuration values successfully loaded.                                                                                                                              
2023-11-08 17:19:22,242 | Configuration values are: {}                                                                                                                                           
2023-11-08 17:19:22,257 | Using SAM Template at /Users/ivan/pantas-infra/template.yaml                                                                                                           
2023-11-08 17:19:22,283 | Using config file: samconfig.toml, config environment: default                                                                                                         
2023-11-08 17:19:22,283 | Expand command line arguments to:                                                                                                                                      
2023-11-08 17:19:22,284 | --template_file=/Users/ivan/pantas-infra/template.yaml --use_container --mount_with=READ --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache                         
2023-11-08 17:19:22,379 | 'build' command is called                                                                                                                                              
2023-11-08 17:19:22,379 | Starting Build inside a container                                                                                                                                      
2023-11-08 17:19:22,394 | Collected default values for parameters: {}                                                                                                                            
2023-11-08 17:19:22,414 | There is no customer defined id or cdk path defined for resource xxx, so we will use the resource logical id as the resource id                              
...
2023-11-08 17:19:22,418 | There is no customer defined id or cdk path defined for resource xxx, so we will use the resource logical id as the resource id                                 
2023-11-08 17:19:22,420 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                                                             
2023-11-08 17:19:22,458 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                                                             
2023-11-08 17:19:22,459 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '7b3c609f-d7b0-480a-b4b8-1c0f525cabb5', 'installationId': '204703a9-cc97-473c-9255-c5e9e2355e54',         
'sessionId': '8d3b2373-883c-409d-ad4f-90fd4a61104a', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.12.0', 'samcliVersion': '1.100.0', 'awsProfileProvided': False,                 
'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName':                                        
'67aab61105387da9a19ab6fdbfee5482870508ce9656fcbbeb51acc7f71792df', 'initialCommit': None}, 'duration': 137, 'exitReason': 'AttributeError', 'exitCode': 255}}]}                                 
2023-11-08 17:19:22,459 | Unable to find Click Context for getting session_id.                                                                                                                   
2023-11-08 17:19:22,463 | Sending Telemetry: {'metrics': [{'events': {'requestId': 'f66ff866-b830-4cc9-818b-6e1658fab0c5', 'installationId': '204703a9-cc97-473c-9255-c5e9e2355e54', 'sessionId':
'8d3b2373-883c-409d-ad4f-90fd4a61104a', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.12.0', 'samcliVersion': '1.100.0', 'commandName': 'sam build', 'metricSpecificAttributes':   
{'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '85210a35b77b4cfba982ff0d5e225621', 'time_stamp': '2023-11-08 09:19:22.238', 'exception_name': None},  
{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': 'ad9a30f2e4584031a0acc59341714cce', 'time_stamp': '2023-11-08 09:19:22.282', 'exception_name': None}]}}}]}         
2023-11-08 17:19:23,312 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)                                       

Error: 'NoneType' object has no attribute 'startswith'
Traceback:
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/cli/cli_config_file.py", line 347, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/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.100.0/libexec/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/lib/telemetry/metric.py", line 184, in wrapped
    raise exception  # pylint: disable=raising-bad-type
    ^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/lib/telemetry/metric.py", line 149, in wrapped
    return_value = func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
    actual_result = func(*args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/cli/main.py", line 95, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/commands/build/command.py", line 171, in cli
    do_cli(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/commands/build/command.py", line 236, in do_cli
    with BuildContext(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/commands/build/build_context.py", line 184, in __enter__
    self.set_up()
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/commands/build/build_context.py", line 190, in set_up
    self._stacks, remote_stack_full_paths = SamLocalStackProvider.get_stacks(
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/lib/providers/sam_stack_provider.py", line 269, in get_stacks
    current = SamLocalStackProvider(
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/lib/providers/sam_stack_provider.py", line 73, in __init__
    self._extract_stacks()
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/lib/providers/sam_stack_provider.py", line 126, in _extract_stacks
    stack = SamLocalStackProvider._convert_cfn_stack_resource(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/lib/providers/sam_stack_provider.py", line 185, in _convert_cfn_stack_resource
    if SamLocalStackProvider.is_remote_url(template_url):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.100.0/libexec/lib/python3.12/site-packages/samcli/lib/providers/sam_stack_provider.py", line 296, in is_remote_url
    return any([url.startswith(prefix) for prefix in ["s3://", "http://", "https://"]])
                ^^^^^^^^^^^^^^

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

Expected result:

Build should work.

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

  1. OS: macos
  2. sam --version: 1.100.0
  3. AWS region: ap-southeast-1
{
  "version": "1.100.0",
  "system": {
    "python": "3.12.0",
    "os": "macOS-14.0-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "20.10.17",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "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"
  ]
}

Most likely caused by this

    Type: AWS::CloudFormation::Stack
    Properties:
      Parameters:
        TemplateBody: file://template.yaml
hawflau commented 8 months ago

Hi @pickfire thanks for raising the issue. Could you please provide your template to help reproduce the error?

pickfire commented 8 months ago

Sorry, I lost the template.