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.53k stars 1.17k forks source link

Running sam init fails with 'Error: Please verify your location' #1891

Closed vishnufka closed 1 year ago

vishnufka commented 4 years ago

Description

Hi, I have tried debugging this for while.

Originally started in VS Code when trying to create a new SAM application in there, moved the underlying command into terminal to try and debug.

Tried uninstalling and reinstalling SAM, AWS, and git; checking AWS/git credentials, checking windows permissions, running as administrator etc.

I am really stuck as the error message does not contain enough information to work out what is going on and I have never seen anyone else having this error on the internet. The only other person who has ever had 'Error: Please verify your location' in relation to AWS SAM, was due to not having git installed, but I do have git installed.

Git works fine across the rest of the system. Can connect to AWS via VS Code and invoke lambdas from there, so credentials seem fine.

When you run it with --location it gives me permission denied, but I have set the permissions on these folders so everyone can access it, and I have no issue in windows explorer.

Provided samples both with and without --location flag.

Thanks!

Steps to reproduce

WITHOUT --LOCATION

Run: $ sam init --debug Params are: 1, 1, blank

WITH --LOCATION

Run: $ sam init --location https://github.com/awslabs/aws-sam-cli-app-templates.git --debug

Observed result

WITHOUT --LOCATION

PS C:\WINDOWS\system32> sam init --debug Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: 1

Which runtime would you like to use? 1 - nodejs12.x 2 - python3.8 3 - ruby2.7 4 - go1.x 5 - java11 6 - dotnetcore2.1 7 - nodejs10.x 8 - python3.7 9 - python3.6 10 - python2.7 11 - ruby2.5 12 - java8 13 - dotnetcore2.0 14 - dotnetcore1.0 Runtime: 1

Project name [sam-app]:

Cloning app templates from https://github.com/awslabs/aws-sam-cli-app-templates.git

Generating application: Name: sam-app Runtime: nodejs12.x Dependency Manager: npm Application Template: hello-world Output Directory: .

Next steps can be found in the README file at ./sam-app/README.md

Parameters dict created with input given {'template': 'C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\init\templates\cookiecutter-aws-sam-hello-nodejs', 'output_dir': '.', 'no_input': True, 'extra_context': {'project_name': 'sam-app', 'runtime': 'nodejs12.x'}} Baking a new template with cookiecutter with all parameters Unable to find cookiecutter.json in the project. Downloading it directly without treating it as a cookiecutter template Downloading project from C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\init\templates\cookiecutter-aws-sam-hello-nodejs to sam-app Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam init', 'duration': 4522, 'exitReason': 'ArbitraryProjectDownloadFailed', 'exitCode': 1, 'requestId': 'ee801dd2-53d2-4f5e-b526-5c946da783eb', 'installationId': '2dc4d766-4c3e-4458-a3dc-f80756ef122f', 'sessionId': 'f5dcb8af-0906-44b8-b160-6722cc8bffda', 'executionEnvironment': 'CLI', 'pyversion': '3.7.6', 'samcliVersion': '0.46.1'}}]} HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1) Error: Please verify your location. The following types of location are supported:

WITH --LOCATION

PS C:\WINDOWS\system32> sam init --location https://github.com/awslabs/aws-sam-cli-app-templates.git --debug Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics Parameters dict created with input given {'template': 'https://github.com/awslabs/aws-sam-cli-app-templates.git', 'output_dir': '.', 'no_input': False} Baking a new template with cookiecutter with all parameters You've downloaded C:\Users\c0gnac.cookiecutters\aws-sam-cli-app-templates before. Is it okay to delete and re-download it? [yes]: Unable to find cookiecutter.json in the project. Downloading it directly without treating it as a cookiecutter template Downloading project from https://github.com/awslabs/aws-sam-cli-app-templates.git to . https://github.com/awslabs/aws-sam-cli-app-templates.git location is a source control repository Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam init', 'duration': 7145, 'exitReason': 'PermissionError', 'exitCode': 255, 'requestId': 'c902ee29-b47a-4ca2-a598-f4e952a6ab16', 'installationId': '2dc4d766-4c3e-4458-a3dc-f80756ef122f', 'sessionId': '9ea6298c-0a0a-4df6-81cb-e34ab49b1311', 'executionEnvironment': 'CLI', 'pyversion': '3.7.6', 'samcliVersion': '0.46.1'}}]} HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1) Traceback (most recent call last): File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\init__init__.py", line 80, in generate_project cookiecutter(**params) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\cookiecutter\main.py", line 63, in cookiecutter password=password File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\cookiecutter\repository.py", line 122, in determine_repo_dir '\n'.join(repository_candidates) cookiecutter.exceptions.RepositoryNotFound: A valid repository for "https://github.com/awslabs/aws-sam-cli-app-templates.git" could not be found in the following locations: C:\Users\c0gnac.cookiecutters\aws-sam-cli-app-templates

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\utils\osutils.py", line 42, in mkdir_temp yield temp_dir File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\init\arbitrary_project.py", line 107, in _download_and_copy downloaded_dir = download_fn(clone_to_dir=tempdir) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\cookiecutter\vcs.py", line 99, in clone stderr=subprocess.STDOUT, File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\subprocess.py", line 411, in check_output File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\subprocess.py", line 512, in run subprocess.CalledProcessError: Command '['git', 'clone', 'https://github.com/awslabs/aws-sam-cli-app-templates.git']' returned non-zero exit status 128.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\runpy.py", line 193, in _run_module_as_main File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\runpy.py", line 85, in _run_code File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli__main.py", line 12, in cli(prog_name="sam") File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 829, in call return self.main(args, kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 782, in main rv = self.invoke(ctx) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1066, in invoke return ctx.invoke(self.callback, ctx.params) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke return callback(args, kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\decorators.py", line 73, in new_func return ctx.invoke(f, obj, *args, *kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke return callback(args, kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metrics.py", line 96, in wrapped raise exception # pylint: disable=raising-bad-type File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metrics.py", line 62, in wrapped return_value = func(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\init__init__.py", line 119, in cli extra_context, File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\init__init__.py", line 162, in do_cli do_generate(location, runtime, dependency_manager, output_dir, name, no_input, extra_context) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\init\init_generator.py", line 12, in do_generate generate_project(location, runtime, dependency_manager, output_dir, name, no_input, extra_context) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\init\init.py", line 89, in generate_project generate_non_cookiecutter_project(location=params["template"], output_dir=project_output_dir) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\init\arbitrary_project.py", line 81, in generate_non_cookiecutter_project return _download_and_copy(download_fn, output_dir) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\init\arbitrary_project.py", line 108, in _download_and_copy osutils.copytree(downloaded_dir, output_dir, ignore=shutil.ignore_patterns("*.git")) File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\contextlib.py", line 130, in exit__ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\utils\osutils.py", line 49, in mkdir_temp shutil.rmtree(temp_dir) File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\shutil.py", line 516, in rmtree File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\shutil.py", line 395, in _rmtree_unsafe File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\shutil.py", line 395, in _rmtree_unsafe File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\shutil.py", line 395, in _rmtree_unsafe [Previous line repeated 1 more time] File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\shutil.py", line 400, in _rmtree_unsafe File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\shutil.py", line 398, in _rmtree_unsafe PermissionError: [WinError 5] Access is denied: 'C:\Users\c0gnac\AppData\Local\Temp\tmpbs4_bh0j\aws-sam-cli-app-templates\.git\objects\pack\pack-e4995d8b97945c3793307f4329c28a14d2775e90.idx'

Expected result

Creates new SAM project.

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

  1. OS: Windows 10 v1909 build.18363.720
  2. sam --version: 0.46.1

Happens as a regular user and as an administrator.

sriram-mv commented 4 years ago

Interesting, this issue should have been solved some time ago. I wonder if this some case we are missing out on now.

gmbuchanan commented 4 years ago

I am experiencing this as well, same scenario and messages. Totally new environment.

boyersnet commented 4 years ago

Same experience with 0.47.0. When running without location parameter and turning debug on I see this output:

Unable to find cookiecutter.json in the project. Downloading it directly without treating it as a cookiecutter template Downloading project from C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\init\templates\cookiecutter-aws-sam-hello-nodejs to sam-app-example

When I look at that path on my local system, there is no init folder in local.

When looking closer at the install directory I found the init folder in this location: C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\.

Note the difference at ...\samcli\local\ vs ...\samcli\lib

I installed with the MSI, but the zip bundle has the same discrepancy.

boyersnet commented 4 years ago

Update, I uninstalled the msi package and used the pip install method and I was able to get up and running.

vishnufka commented 4 years ago

I tried uninstalling the msi and installing via pip and unfortunately I still get the same error.

murashin2012 commented 4 years ago

I came across the same error, and I could solve it making a symbolic link.

Enviroment: ・Windows 10 Version 1809 64bit ・AWS SAM CLI Version 0.47.0

Note the difference at ...\samcli\local\ vs ...\samcli\lib

Same here. I could solve this problem as follows:

mklink /D "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\local\init" "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\init"

Note:

I tried uninstalling the msi and installing via pip and unfortunately I still get the same error.

If your windows is 64 bit, I think you would need to install the AWS SAM CLI 64-bit from the link below as described here "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-windows.html":

https://github.com/awslabs/aws-sam-cli/releases/latest/download/AWS_SAM_CLI_64_PY3.msi

Hope this helps.

vishnufka commented 4 years ago

I created the symlink above in cmd and it works now!

Also I made sure I was using the msi version and not the pip version of the AWS CLI.

Thanks @murashin2012 for the fix, and thanks everyone else for contributions.

bigghe commented 4 years ago

Hi all, I have the same issue and can't create the link because I'm not admin on my company's workstation.

Can you suggest me some other workaround? Maybe skip the sam init step by cloning the templates repo directly?

Thanks!

AlexisColes commented 4 years ago

Thanks @murashin2012 although mklink was not a known command for me, a little copy did the trick for me.

Copy-Item "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\init" "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\local" -Recurse

Very annoying this is still an issue 2 months later.

seandkendall commented 4 years ago

Im seeing this issue with: sam init 1 - AWS Quick Start Templates 5 - java11 2 - gradle sam-app 4 - Step Functions Sample App (Stock Trader): Gradle Region: us-east-1 Schema: 1 - aws.athena@AthenaQueryStateChange


Generating application:

Name: sam-app Runtime: java11 Dependency Manager: gradle Application Template: step-functions-sample-app Output Directory: .

Next steps can be found in the README file at ./sam-app/README.md

Error: Please verify your location. The following types of location are supported:

SophonAlpha commented 4 years ago

Same issue with SAM CLI, version 1.0.0 on Windows 10 Enterprise. I tried with installation via pip and MSI. Problem remains.

As @boyersnet mentioned, the issue is the path from where SAM CLI tries to copy the template code. It tries to copy from a non-existing 'local' folder:

C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\init\templates\...

... but the template is in:

C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\init\templates\...

I was able to get around the issue by creating a symbolic link as suggested by @murashin2012.

Nnamdi-sys commented 4 years ago

Same issue with SAM CLI, version 1.0.0 on Windows 10 Enterprise. I tried with installation via pip and MSI. Problem remains.

As @boyersnet mentioned, the issue is the path from where SAM CLI tries to copy the template code. It tries to copy from a non-existing 'local' folder:

C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\init\templates\...

... but the template is in:

C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\init\templates\...

I was able to get around the issue by creating a symbolic link as suggested by @murashin2012.

I tried this, but i got 'Access Denied', what do i do?

Nnamdi-sys commented 4 years ago

Same issue with SAM CLI, version 1.0.0 on Windows 10 Enterprise. I tried with installation via pip and MSI. Problem remains. As @boyersnet mentioned, the issue is the path from where SAM CLI tries to copy the template code. It tries to copy from a non-existing 'local' folder: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\init\templates\... ... but the template is in: C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\init\templates\... I was able to get around the issue by creating a symbolic link as suggested by @murashin2012.

I tried this, but i got 'Access Denied', what do i do?

running command prompt as administrator solved this issue for me. incase there's anyone with similar problem

pcchannz commented 4 years ago

Tried with @boyersnet method to resolve the template from "lib" folder but the templates were limited. Got mine issue sorted by connecting outside of corporate network when doing "sam init"

Sergio2R commented 4 years ago

Same issue with SAM CLI, version 1.0.0 on Windows 10 Enterprise. I tried with installation via pip and MSI. Problem remains.

As @boyersnet mentioned, the issue is the path from where SAM CLI tries to copy the template code. It tries to copy from a non-existing 'local' folder:

C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\init\templates\...

... but the template is in:

C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\init\templates\...

I was able to get around the issue by creating a symbolic link as suggested by @murashin2012.

TY I created the direcotry and copied the content and it also worked

sriram-mv commented 3 years ago

Is this issue still occurring?

sam init should pull in templates from aws-sam-cli-app-templates repo. the templates that are present within SAM CLI are purely fallback are not exhaustive.

SophonAlpha commented 3 years ago

Same issue with SAM CLI, version 1.0.0 on Windows 10 Enterprise. I tried with installation via pip and MSI. Problem remains. As @boyersnet mentioned, the issue is the path from where SAM CLI tries to copy the template code. It tries to copy from a non-existing 'local' folder: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\init\templates\... ... but the template is in: C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\init\templates\... I was able to get around the issue by creating a symbolic link as suggested by @murashin2012.

I tried this, but i got 'Access Denied', what do i do?

Start a command window (cmd) with administrator permissions.

test-n-prodd commented 3 years ago

I had this issue using sam init, though my error did not include the bits right after Parameters dict created with input given [...]

The fix was to install the git cli with brew install git

raffian commented 3 years ago

Solved; see below. Caused by invalid default path for cookiecutter templates.

Windows 10 x64 Enterprise aws-cli/1.20.35 (pip installed) sam-cli 1.31.0 (pip installed) Python/3.7.4 botocore/1.21.35

C:\Users\dude\Documents\Projects\x-sc\x-notgit\demo-app>sam init --output-dir .  --name demo-app --debug
2021-10-26 15:11:26,585 | Expand command line arguments to:
2021-10-26 15:11:26,585 | --output_dir=. --name=demo-app --package_type=Zip
2021-10-26 15:11:34,545 |
Cloning from https://github.com/aws/aws-sam-cli-app-templates
    -----------------------
    Generating application:
    -----------------------
    Name: demo-app
    Base Image: amazon/nodejs12.x-base
    Dependency Manager: npm
    Output Directory: .

2021-10-26 15:11:35,078 | Parameters dict created with input given
2021-10-26 15:11:35,079 | {'template': 'c:\\users\\dude\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\samcli\\lib\\init\\image_templates\\nodejs12.x\\cookiecutter-aws-sam-hello-nodejs-lambda-image', 'output_dir': '.', 'no_input': True, 'extra_context': {'project_name': 'demo-app', 'runtime': 'nodejs12.x'}}
2021-10-26 15:11:35,079 | Baking a new template with cookiecutter with all parameters
2021-10-26 15:11:35,080 | Unable to find cookiecutter.json in the project. Downloading it directly without treating it as a cookiecutter template
2021-10-26 15:11:35,080 | Downloading project from c:\users\dude\appdata\local\programs\python\python37-32\lib\site-packages\samcli\lib\init\image_templates\nodejs12.x\cookiecutter-aws-sam-hello-nodejs-lambda-image to demo-app

Error: Please verify your location. The following types of location are supported:

Debug output showing default templates path was invalid:

{'template': 'c:\\users\\dude\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\samcli\\lib\\init\\image_templates\\nodejs12.x\\cookiecutter-aws-sam-hello-nodejs-lambda-image'

The templates were actually located under init\templates, not init\image-templates\nodejs12.x,

c:\users\dude\appdata\local\programs\python\python37-32\lib\site-packages\samcli\lib\init\templates\cookiecutter-aws-sam-hello-nodejs

Ran again with --location parameter with the correct template path, bye bye error :-)

sam init --output-dir . --name demo-app --location c:/users/dude/appdata/local/programs/python/python37-32/lib/site-packages/samcli/lib/init/templates/cookiecutter-aws-sam-hello-nodejs --debug

rogergangawork commented 2 years ago

Solved; see below. Caused by invalid default path for cookiecutter templates.

Windows 10 x64 Enterprise aws-cli/1.20.35 (pip installed) sam-cli 1.31.0 (pip installed) Python/3.7.4 botocore/1.21.35

C:\Users\dude\Documents\Projects\x-sc\x-notgit\demo-app>sam init --output-dir .  --name demo-app --debug
2021-10-26 15:11:26,585 | Expand command line arguments to:
2021-10-26 15:11:26,585 | --output_dir=. --name=demo-app --package_type=Zip
2021-10-26 15:11:34,545 |
Cloning from https://github.com/aws/aws-sam-cli-app-templates
    -----------------------
    Generating application:
    -----------------------
    Name: demo-app
    Base Image: amazon/nodejs12.x-base
    Dependency Manager: npm
    Output Directory: .

2021-10-26 15:11:35,078 | Parameters dict created with input given
2021-10-26 15:11:35,079 | {'template': 'c:\\users\\dude\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\samcli\\lib\\init\\image_templates\\nodejs12.x\\cookiecutter-aws-sam-hello-nodejs-lambda-image', 'output_dir': '.', 'no_input': True, 'extra_context': {'project_name': 'demo-app', 'runtime': 'nodejs12.x'}}
2021-10-26 15:11:35,079 | Baking a new template with cookiecutter with all parameters
2021-10-26 15:11:35,080 | Unable to find cookiecutter.json in the project. Downloading it directly without treating it as a cookiecutter template
2021-10-26 15:11:35,080 | Downloading project from c:\users\dude\appdata\local\programs\python\python37-32\lib\site-packages\samcli\lib\init\image_templates\nodejs12.x\cookiecutter-aws-sam-hello-nodejs-lambda-image to demo-app

Error: Please verify your location. The following types of location are supported:

Debug output showing default templates path was invalid:

{'template': 'c:\\users\\dude\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\samcli\\lib\\init\\image_templates\\nodejs12.x\\cookiecutter-aws-sam-hello-nodejs-lambda-image'

The templates were actually located under init\templates, not init\image-templates\nodejs12.x,

c:\users\dude\appdata\local\programs\python\python37-32\lib\site-packages\samcli\lib\init\templates\cookiecutter-aws-sam-hello-nodejs

Ran again with --location parameter with the correct template path, bye bye error :-)

sam init --output-dir . --name demo-app --location c:/users/dude/appdata/local/programs/python/python37-32/lib/site-packages/samcli/lib/init/templates/cookiecutter-aws-sam-hello-nodejs --debug

@raffian Thanks a ton for this mate. Was initially confused as there were no image folder. They have to fix this issue as well.

carlosern commented 2 years ago

Solved; see below. Caused by invalid default path for cookiecutter templates.

Windows 10 x64 Enterprise aws-cli/1.20.35 (pip installed) sam-cli 1.31.0 (pip installed) Python/3.7.4 botocore/1.21.35

C:\Users\dude\Documents\Projects\x-sc\x-notgit\demo-app>sam init --output-dir .  --name demo-app --debug
2021-10-26 15:11:26,585 | Expand command line arguments to:
2021-10-26 15:11:26,585 | --output_dir=. --name=demo-app --package_type=Zip
2021-10-26 15:11:34,545 |
Cloning from https://github.com/aws/aws-sam-cli-app-templates
    -----------------------
    Generating application:
    -----------------------
    Name: demo-app
    Base Image: amazon/nodejs12.x-base
    Dependency Manager: npm
    Output Directory: .

2021-10-26 15:11:35,078 | Parameters dict created with input given
2021-10-26 15:11:35,079 | {'template': 'c:\\users\\dude\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\samcli\\lib\\init\\image_templates\\nodejs12.x\\cookiecutter-aws-sam-hello-nodejs-lambda-image', 'output_dir': '.', 'no_input': True, 'extra_context': {'project_name': 'demo-app', 'runtime': 'nodejs12.x'}}
2021-10-26 15:11:35,079 | Baking a new template with cookiecutter with all parameters
2021-10-26 15:11:35,080 | Unable to find cookiecutter.json in the project. Downloading it directly without treating it as a cookiecutter template
2021-10-26 15:11:35,080 | Downloading project from c:\users\dude\appdata\local\programs\python\python37-32\lib\site-packages\samcli\lib\init\image_templates\nodejs12.x\cookiecutter-aws-sam-hello-nodejs-lambda-image to demo-app

Error: Please verify your location. The following types of location are supported:

Debug output showing default templates path was invalid:

{'template': 'c:\\users\\dude\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\samcli\\lib\\init\\image_templates\\nodejs12.x\\cookiecutter-aws-sam-hello-nodejs-lambda-image'

The templates were actually located under init\templates, not init\image-templates\nodejs12.x,

c:\users\dude\appdata\local\programs\python\python37-32\lib\site-packages\samcli\lib\init\templates\cookiecutter-aws-sam-hello-nodejs

Ran again with --location parameter with the correct template path, bye bye error :-)

sam init --output-dir . --name demo-app --location c:/users/dude/appdata/local/programs/python/python37-32/lib/site-packages/samcli/lib/init/templates/cookiecutter-aws-sam-hello-nodejs --debug

Same issue here. SAM CLI 1.50.0 Python 3.10.4

It's works with --location parameter

dcyprianrw commented 2 years ago

This worked for me as well, doing NodeJS on Windows 11. sam init --name lambda-nodejs16.x --location "C:\Users\xxx\AppData\Roaming\AWS SAM\aws-sam-cli-app-templates\nodejs16.x-image\cookiecutter-aws-sam-hello-nodejs-lambda-image"

john-zenden commented 2 years ago

Don't know if anyone else has noticed, but the path in Windows has a space that causes the location to bomb: See "AWS SAM" here.

C:\Users[my username]\AppData\Roaming\AWS SAM\aws-sam-cli-app-templates\python3.9\cookiecutter-aws-sam-hello-python

By calling the --location arg and puting the full path in double quotes it works...

sam init --location "C:\Users[my username]\AppData\Roaming\AWS SAM\aws-sam-cli-app-templates\python3.9\cookiecutter-aws-sam-hello-python"

utkucanaytac commented 2 years ago

sam init --location "C:\Users[my username]\AppData\Roaming\AWS SAM\aws-sam-cli-app-templates\python3.9\cookiecutter-aws-sam-hello-python"

this saved my day. Thank you

john-zenden commented 2 years ago

Can someone point me to the part of the codebase here where files are written to the ...\AppData\Roaming... area of the Windows file system?

keithnicholson commented 2 years ago

Need fixed please...Just starting to play with AWS and this will be a hassle.

It needs to build the path with quotes without us doing it by hand.

john-zenden commented 2 years ago

@keithnicholson your fix is here: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell#enable-long-paths-in-windows-10-version-1607-and-later

keithnicholson commented 2 years ago

@john-zenden Great! This will solve some other issues over the years.

Note to others, I only had to do the registry entry and not the application manifest step.

qingchm commented 2 years ago

Saw some valuable discussion here, some of the discussions can also be tracked in https://github.com/aws/aws-sam-cli/issues/4031. Also please let us know if the original issue was still relevant! @vishnufka

karthik1691-ui commented 2 years ago

This command worked for me to bypass the permissions to create or delete the PowerShell/cmd prompt on Windows machine without fail. sam init --location C:\Users{ }\AppData\Roaming\AWS_SAM\aws-sam-cli-app-templates\java11\cookiecutter-aws-sam-hello-java-maven

As there was a space error in the C drive file of the above path with the name AWS SAM. So I added hash to fill in, and it worked perfectly. Hope this helps!

jfuss commented 1 year ago

Things are vastly different from when this was originally created and we have fixed various issues in this same space.

Given the age, I am going to close this. You should not need to provide any --location to get the default apps. If something is still off here, please create a new issue so we can investigate deeper.

github-actions[bot] commented 1 year ago

⚠️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.