aws-samples / aws-sam-swift

SAM Templates for Server-side Swift on AWS
MIT No Attribution
4 stars 1 forks source link

Bug: sam init with aws-sam-swift template fails #3

Closed sebsto closed 10 months ago

sebsto commented 10 months ago

originally opened as https://github.com/aws/aws-sam-cli/issues/6398

Description:

Trying to follow the doc at https://aws-samples.github.io/aws-sam-swift/

Steps to reproduce:

sam init --location gh:aws-samples/aws-sam-swift

Observed result:

sam init --location gh:aws-samples/aws-sam-swift --debug
2023-12-05 11:51:32,302 | No config file found in this directory.                                                                                               
2023-12-05 11:51:32,304 | OSError occurred while reading TOML file: [Errno 2] No such file or directory:                                                        
'/Users/stormacq/Documents/amazon/code/swift/lambda/QuoteAPI/samconfig.toml'                                                                                    
2023-12-05 11:51:32,305 | Config file location: /Users/stormacq/Documents/amazon/code/swift/lambda/QuoteAPI/samconfig.toml                                      
2023-12-05 11:51:32,305 | Config file '/Users/stormacq/Documents/amazon/code/swift/lambda/QuoteAPI/samconfig.toml' does not exist                               
2023-12-05 11:51:32,305 | OSError occurred while reading TOML file: [Errno 2] No such file or directory:                                                        
'/Users/stormacq/Documents/amazon/code/swift/lambda/QuoteAPI/samconfig.toml'                                                                                    
2023-12-05 11:51:32,306 | Using config file: samconfig.toml, config environment: default                                                                        
2023-12-05 11:51:32,306 | Expand command line arguments to:                                                                                                     
2023-12-05 11:51:32,306 | --location=gh:aws-samples/aws-sam-swift --package_type=Zip --output_dir=.                                                             
2023-12-05 11:51:32,408 | Parameters dict created with input given                                                                                              
2023-12-05 11:51:32,409 | {'template': 'gh:aws-samples/aws-sam-swift', 'output_dir': '.', 'no_input': False, 'extra_context': {'architectures': {'value':       
['x86_64']}}}                                                                                                                                                   
2023-12-05 11:51:32,409 | Baking a new template with cookiecutter with all parameters                                                                           
Select template
    1 - Hello World
    2 - Serverless API
    Choose from [1/2] (1): 1
2023-12-05 11:51:36,599 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                            
2023-12-05 11:51:36,604 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                            
2023-12-05 11:51:36,605 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '4eb170a7-2642-4b39-b65e-d443e45ac76d', 'installationId':                
'14581a2d-e609-4037-b259-cfbf350acbbc', 'sessionId': '4eb1155e-beb6-4d95-8981-c9decd969186', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.12.0', 
'samcliVersion': '1.103.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam init', 'metricSpecificAttributes':        
{'projectType': 'CFN'}, 'duration': 4293, 'exitReason': 'AttributeError', 'exitCode': 255}}]}                                                                   
2023-12-05 11:51:36,605 | Unable to find Click Context for getting session_id.                                                                                  
2023-12-05 11:51:36,610 | Sending Telemetry: {'metrics': [{'events': {'requestId': '0a2d82ab-0335-4481-ad1c-afdaba85ee07', 'installationId':                    
'14581a2d-e609-4037-b259-cfbf350acbbc', 'sessionId': '4eb1155e-beb6-4d95-8981-c9decd969186', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.12.0', 
'samcliVersion': '1.103.0', 'commandName': 'sam init', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 
'thread_id': '0a2b1771a1c54a649e720c67fe5feff4', 'time_stamp': '2023-12-05 16:51:32.304', 'exception_name': None}, {'event_name': 'SamConfigFileExtension',     
'event_value': '.toml', 'thread_id': '915ecfa2452e452d86b85f58d2de68e2', 'time_stamp': '2023-12-05 16:51:32.306', 'exception_name': None}]}}}]}                 
2023-12-05 11:51:37,158 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)      
2023-12-05 11:51:37,165 | 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 'group'
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 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.103.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.103.0/libexec/lib/python3.12/site-packages/samcli/commands/init/command.py", line 102, in wrapped
    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.103.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.103.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.103.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.103.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.103.0/libexec/lib/python3.12/site-packages/samcli/commands/init/command.py", line 265, in cli
    do_cli(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/init/command.py", line 346, in do_cli
    do_generate(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/init/init_generator.py", line 24, in do_generate
    generate_project(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/lib/init/__init__.py", line 111, in generate_project
    cookiecutter(**params)
  File "/opt/homebrew/opt/cookiecutter/libexec/lib/python3.12/site-packages/cookiecutter/main.py", line 142, in cookiecutter
    nested_template = choose_nested_template(context, repo_dir, no_input)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/cookiecutter/libexec/lib/python3.12/site-packages/cookiecutter/prompt.py", line 361, in choose_nested_template
    template = re.search(r'\((.+)\)', val).group(1)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

Expected result:

it works :-)

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

➜  ~ sw_vers
ProductName:        macOS
ProductVersion:     14.1.2
BuildVersion:       23B92
➜  ~ sam --version 
SAM CLI, version 1.103.0

Paste the output of sam --info here

➜  ~ sam --info
{
  "version": "1.103.0",
  "system": {
    "python": "3.12.0",
    "os": "macOS-14.1.2-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "Not available",
    "aws_cdk": "2.104.0 (build 3b99abe)",
    "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"
  ]
}
sebsto commented 10 months ago

Cookiecutter upgraded the way they organize projects that contain multiple templates in v2.2 and again with 2.5. The latest version of the SAM CLI bundles with Cookiecutter v2.5.

The template library stopped working as the templates were not configured properly for the new method. We only noticed it when a user upgraded their SAM CLI to the latest version.

Here is the issue I opened, but then closed when I determined the issue: https://github.com/aws/aws-sam-cli/issues/6400

Here is info from Cookiecutter on the new technique: https://cookiecutter.readthedocs.io/en/stable/advanced/nested_config_files.html#