aws-samples / cookiecutter-aws-sam-python

A Cookiecutter template to create a Serverless App based on Serverless Application Model (SAM) and Python 3.8
MIT No Attribution
221 stars 72 forks source link

`sam init` fails to deploy `gh:aws-samples/cookiecutter-aws-sam-python` on Windows platform #47

Closed fedor-pavlov closed 5 months ago

fedor-pavlov commented 6 months ago

Description:

A sam init fails to bootstrap a simple python hello-world template on Windows platform. You may find this command example in sam init --help and also at https://github.com/aws-samples/cookiecutter-aws-sam-python:

sam init --location gh:aws-samples/cookiecutter-aws-sam-python

this command produces the following error:

'C:\Users\{USER}\AppData\Local\Temp\tmppht_go78' is not recognized as an internal or external command,
operable program or batch file.
2024-05-04 12:11:51 Stopping generation because post_gen_project hook script didn't exit successfully
Error: An error occurred while generating this project : Hook script failed (exit status: 1)

Steps to reproduce:

  1. Run cmd (Win+R, cmd)
  2. Run sam init --location gh:aws-samples/cookiecutter-aws-sam-python
  3. Type in a project name: sam-demo

Observed result:

You've downloaded C:\Users\{USER}\.cookiecutters\cookiecutter-aws-sam-python before. Is it okay to delete and
re-download it? [y/n] (y): y
  [1/2] project_name (Name of the project): sam-demo
  [2/2] include_safe_deployment (n):
'C:\Users\{USER}\AppData\Local\Temp\tmppht_go78' is not recognized as an internal or external command,
operable program or batch file.
2024-05-04 12:11:51 Stopping generation because post_gen_project hook script didn't exit successfully
Error: An error occurred while generating this project : Hook script failed (exit status: 1)

Expected result:

A sample template should be deployed to sam-demo folder.

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

Platform: Windows 11 Enterprise, 22H2, build 22621.3447

  1. OS: Windows 11 Enterprise, 22H2, build 22621.3447
  2. sam --version: SAM CLI, version 1.116.0
  3. AWS region: eu-central-1
# Paste the output of `sam --info` here
{
  "version": "1.116.0",
  "system": {
    "python": "3.11.8",
    "os": "Windows-10-10.0.22621-SP0"
  },
  "additional_dependencies": {
    "docker_engine": "25.0.3",
    "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"
  ]
}

Add --debug flag to command you are running

D:\code>sam init --debug --location gh:aws-samples/cookiecutter-aws-sam-python
2024-05-04 12:32:51,916 | No config file found in this directory.
2024-05-04 12:32:51,922 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: 'D:\\code\\samconfig.toml'
2024-05-04 12:32:51,926 | Config file location: D:\code\samconfig.toml
2024-05-04 12:32:51,928 | Config file 'D:\code\samconfig.toml' does not exist
2024-05-04 12:32:51,931 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: 'D:\\code\\samconfig.toml'
2024-05-04 12:32:51,934 | Using config file: samconfig.toml, config environment: default
2024-05-04 12:32:51,937 | Expand command line arguments to:
2024-05-04 12:32:51,940 | --location=gh:aws-samples/cookiecutter-aws-sam-python --package_type=Zip --output_dir=.
2024-05-04 12:32:54,309 | Parameters dict created with input given
2024-05-04 12:32:54,311 | {'template': 'gh:aws-samples/cookiecutter-aws-sam-python', 'output_dir': '.', 'no_input': False,
'extra_context': {'architectures': {'value': ['x86_64']}}}
2024-05-04 12:32:54,314 | Baking a new template with cookiecutter with all parameters
You've downloaded C:\Users\{USER}\.cookiecutters\cookiecutter-aws-sam-python before. Is it okay to delete and re-download it? [y/n]
(y):
  [1/2] project_name (Name of the project): sam-demo
  [2/2] include_safe_deployment (n): ,
'C:\Users\{USER}\AppData\Local\Temp\tmppcr4666j' is not recognized as an internal or external command,
operable program or batch file.
2024-05-04 12:33:06 Stopping generation because post_gen_project hook script didn't exit successfully
2024-05-04 12:33:06,028 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-05-04 12:33:06,037 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-05-04 12:33:06,039 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '55d97f37-4520-4617-a247-2a3567a20d54',
'installationId': 'bd80cbf9-f65d-4e2e-9994-227fa828c739', 'sessionId': '8abc2f0e-e1c8-4006-b545-01ae3f9c58c9', 'executionEnvironment':
'CLI', 'ci': False, 'pyversion': '3.11.8', 'samcliVersion': '1.116.0', 'awsProfileProvided': False, 'debugFlagProvided': True,
'region': '', 'commandName': 'sam init', 'metricSpecificAttributes': {'projectType': 'CFN'}, 'duration': 14093, 'exitReason':
'GenerateProjectFailedError', 'exitCode': 1}}]}
2024-05-04 12:33:06,039 | Unable to find Click Context for getting session_id.
2024-05-04 12:33:06,056 | Sending Telemetry: {'metrics': [{'events': {'requestId': '1d749600-69ae-477d-b6e4-d4f042161188',
'installationId': 'bd80cbf9-f65d-4e2e-9994-227fa828c739', 'sessionId': '8abc2f0e-e1c8-4006-b545-01ae3f9c58c9', 'executionEnvironment':
'CLI', 'ci': False, 'pyversion': '3.11.8', 'samcliVersion': '1.116.0', 'commandName': 'sam init', 'metricSpecificAttributes':
{'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '6aca96ee57164d33b22d768e6372370a',
'time_stamp': '2024-05-04 10:32:51.926', 'exception_name': None}, {'event_name': 'SamConfigFileExtension', 'event_value': '.toml',
'thread_id': 'f7318f23f60b49fe9830e2808ae7407e', 'time_stamp': '2024-05-04 10:32:51.934', 'exception_name': None}]}}}]}
2024-05-04 12:33:07,293 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out.
(read timeout=0.1)
2024-05-04 12:33:07,324 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out.
(read timeout=0.1)
Error: An error occurred while generating this project : Hook script failed (exit status: 1)
heitorlessa commented 5 months ago

hey @fedor-pavlov, apologies for the delay but this sample project is now superseded by the official SAM CLI template:

sam init --app-template hello-world-powertools-python --name sam-app --package-type Zip --runtime python3.12 --no-tracing

I'm closing, updating the README, and archiving it.