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 local start-api - AttributeError 'get' #6607

Closed
Zak-Roz opened this issue Jan 28, 2024 · 2 comments
Closed

Bug: sam local start-api - AttributeError 'get' #6607

Zak-Roz opened this issue Jan 28, 2024 · 2 comments
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Comments

@Zak-Roz
Copy link

Zak-Roz commented Jan 28, 2024

Error: 'NoneType' object has no attribute 'get'

Description:

switched from linux to macOS M3, installed sam

Steps to reproduce:

sudo NODE_ENV=local sam local start-api --docker-network example --warm-containers LAZY --port 3001 --invoke-image layer:latest --skip-pull-image --debug

Observed result:

sudo NODE_ENV=local sam local start-api --docker-network example --warm-containers LAZY --port 3001 --invoke-image layer:latest --skip-pull-image  --debug

2024-01-28 18:18:09,692 | No config file found in this directory.                   
2024-01-28 18:18:09,693 | OSError occurred while reading TOML file: [Errno 2] No such file or directory:                     
'/Users/user/Developer/example/samconfig.toml'                                 
2024-01-28 18:18:09,694 | Config file location: /Users/user/Developer/example/samconfig.toml                            
2024-01-28 18:18:09,694 | Config file '/Users/user/Developer/example/samconfig.toml' does not exist                     
2024-01-28 18:18:09,717 | Using SAM Template at /Users/user/Developer/example/template.yaml                             
2024-01-28 18:18:09,727 | OSError occurred while reading TOML file: [Errno 2] No such file or directory:                     
'/Users/user/Developer/example/samconfig.toml'                                 
2024-01-28 18:18:09,727 | Using config file: samconfig.toml, config environment: default                                     
2024-01-28 18:18:09,728 | Expand command line arguments to:                         
2024-01-28 18:18:09,728 | --template_file=/Users/user/Developer/example/template.yaml --docker_network=example     
--warm_containers=LAZY --port=3001 --invoke_image=('layer:latest',) --skip_pull_image --host=127.0.0.1 --static_dir=public   
--layer_cache_basedir=/Users/user/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1       
2024-01-28 18:18:09,760 | local start-api command is called                         
2024-01-28 18:18:09,782 | Collected default values for parameters: {'NodeEnv': 'default', 'AwsRegion': 'default', 'AppEnv': 'default', 'SGid': 'default', 'SubnetIds':
'default'}                                 
2024-01-28 18:18:09,874 | There is no customer defined id or cdk path defined for resource SwaggerFunction, so we will use the resource logical id as the resource id 
2024-01-28 18:18:09,875 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                                  
2024-01-28 18:18:09,896 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                                  
2024-01-28 18:18:09,897 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '8ed38610-962c-4be2-bc21-5cc2675be072', 'installationId':                      
'344747cd-700b-4bee-8dac-34f8b13d989a', 'sessionId': 'f5b30a7f-a0ca-4f61-ae82-fce0c0e8ba35', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.12.1',       
'samcliVersion': '1.108.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local start-api', 'metricSpecificAttributes':   
{'projectType': 'CFN', 'gitOrigin': None, 'projectName': '082b0254afae42a837982ff34d7cdbbeafb7a9135ec70c6a47232e51b2147d47', 'initialCommit': None}, 'duration': 147, 
'exitReason': 'AttributeError', 'exitCode': 255}}]}                                 
2024-01-28 18:18:09,897 | Unable to find Click Context for getting session_id.      
2024-01-28 18:18:09,899 | Sending Telemetry: {'metrics': [{'events': {'requestId': '6e2bd5c2-7853-444d-a7d6-d7347e9ee80e', 'installationId':                          
'344747cd-700b-4bee-8dac-34f8b13d989a', 'sessionId': 'f5b30a7f-a0ca-4f61-ae82-fce0c0e8ba35', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.12.1',       
'samcliVersion': '1.108.0', 'commandName': 'sam local start-api', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value':     
'.toml', 'thread_id': 'a2c52a5a6f7242a1b3d70b87d4a92faf', 'time_stamp': '2024-01-28 16:18:09.694', 'exception_name': None}, {'event_name': 'SamConfigFileExtension',  
'event_value': '.toml', 'thread_id': 'cc72116ef58a442da6761155af27aec6', 'time_stamp': '2024-01-28 16:18:09.727', 'exception_name': None}]}}}]}                       
2024-01-28 18:18:10,607 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)            
2024-01-28 18:18:10,610 | 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 'get'
Traceback:
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.108.0/libexec/lib/python3.12/site-packages/samcli/cli/cli_config_file.py", line 347, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.108.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.108.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.108.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.108.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.108.0/libexec/lib/python3.12/site-packages/samcli/commands/local/start_api/cli.py", line 150, in cli
    do_cli(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.108.0/libexec/lib/python3.12/site-packages/samcli/commands/local/start_api/cli.py", line 232, in do_cli
    with InvokeContext(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.108.0/libexec/lib/python3.12/site-packages/samcli/commands/local/cli_common/invoke_context.py", line 220, in __enter__
    self._stacks = self._get_stacks()
                   ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.108.0/libexec/lib/python3.12/site-packages/samcli/commands/local/cli_common/invoke_context.py", line 466, in _get_stacks
    stacks, _ = SamLocalStackProvider.get_stacks(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.108.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.108.0/libexec/lib/python3.12/site-packages/samcli/lib/providers/sam_stack_provider.py", line 61, in __init__
    self._template_dict = self.get_template(
                          ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.108.0/libexec/lib/python3.12/site-packages/samcli/lib/providers/sam_base_provider.py", line 194, in get_template
    ResourceMetadataNormalizer.normalize(template_dict)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.108.0/libexec/lib/python3.12/site-packages/samcli/lib/samlib/resource_metadata_normalizer.py", line 97, in normalize
    {SAM_RESOURCE_ID_KEY: ResourceMetadataNormalizer.get_resource_id(resource, logical_id)},
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.108.0/libexec/lib/python3.12/site-packages/samcli/lib/samlib/resource_metadata_normalizer.py", line 232, in get_resource_id
    customer_defined_id = resource_metadata.get(SAM_RESOURCE_ID_KEY)
                          ^^^^^^^^^^^^^^^^^^^^^

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

Expected result:

it works

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

  1. OS:
~ > sw_vers
ProductName:		macOS
ProductVersion:		14.2.1
BuildVersion:		        23C71
  1. sam --info:
{
  "version": "1.108.0",
  "system": {
    "python": "3.12.1",
    "os": "macOS-14.2.1-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "Not available",
    "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"
  ]
}
@Zak-Roz Zak-Roz added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Jan 28, 2024
@Zak-Roz
Copy link
Author

Zak-Roz commented Jan 29, 2024

Fixed it!
In the newer version of sam or python, you can't have empty tags like my "Metadata" in the template.yaml file:
image

@Zak-Roz Zak-Roz closed this as completed Jan 29, 2024
Copy link
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
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

No branches or pull requests

1 participant