sam build --build-dir . will nuke current working directory
See original GitHub issueDescription
Executing sam build --build-dir .
will fail and result in removal of all files in current working directory.
Steps to reproduce
sam init -r python3.7
cd sam-app
sam build --build-dir .
Observed result
$ sam build --debug --build-dir .
2019-04-30 02:18:11 Using SAM Template at /private/tmp/sam-app/template.yaml
2019-04-30 02:18:11 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-04-30 02:18:11 Changing event name from before-call.apigateway to before-call.api-gateway
2019-04-30 02:18:11 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-04-30 02:18:11 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-04-30 02:18:11 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-04-30 02:18:11 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-04-30 02:18:11 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-04-30 02:18:11 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-04-30 02:18:11 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-04-30 02:18:11 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-04-30 02:18:11 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-04-30 02:18:11 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-04-30 02:18:11 Changing event name from before-call.apigateway to before-call.api-gateway
2019-04-30 02:18:11 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-04-30 02:18:11 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-04-30 02:18:11 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-04-30 02:18:11 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-04-30 02:18:11 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-04-30 02:18:11 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-04-30 02:18:11 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-04-30 02:18:11 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-04-30 02:18:11 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-04-30 02:18:11 'build' command is called
2019-04-30 02:18:11 No Parameters detected in the template
2019-04-30 02:18:11 2 resources found in the template
2019-04-30 02:18:11 Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
Traceback (most recent call last):
File "/usr/local/bin/sam", line 11, in <module>
load_entry_point('aws-sam-cli==0.15.0', 'console_scripts', 'sam')()
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/samcli/commands/build/command.py", line 100, in cli
skip_pull_image, parameter_overrides, mode) # pragma: no cover
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/samcli/commands/build/command.py", line 131, in do_cli
mode=mode) as ctx:
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/samcli/commands/build/build_context.py", line 65, in __enter__
self._build_dir = self._setup_build_dir(self._build_dir, self._clean)
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/samcli/commands/build/build_context.py", line 82, in _setup_build_dir
shutil.rmtree(build_dir)
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/shutil.py", line 495, in rmtree
onerror(os.rmdir, path, sys.exc_info())
File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/shutil.py", line 493, in rmtree
os.rmdir(path)
OSError: [Errno 22] Invalid argument: '.'
Expected result
It should either:
a) fail cleanly
b) create a .aws-sam
directory inside the build-dir
which it can remove without worry in case of failure.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: macOS 10.14.4 (python via brew)
SAM CLI, version 0.15.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
sam build --build-dir . will nuke current working directory ...
Description Executing sam build --build-dir . will fail and result in removal of all files in current working directory.
Read more >sam build - AWS Serverless Application Model
To build on your workstation, run this command in the directory containing your SAM template. Built artifacts are written to the .aws-sam/build directory....
Read more >How to export PATH to "sam build" command? - Stack Overflow
I solved the problem for python3.8 (same for python3.7 I suppose) by linking executable into /usr/local/bin
Read more >sam local start-api - Amazon Serverless Application Model
The Amazon SAM CLI first tries to locate a template file built using the sam ... file named template.yaml or template.yml in the...
Read more >AWS Lambda Testing and Debugging using IntelliJ, AWS ...
But sometimes it is difficult to test and debug your Lambda code locally on ... configurations and a build directory path as .aws-sam/build....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just got bit by this bug. My intention when using
-b .
was that the build folder would be created in the location where I was runningsam build
i.e. in that location a.aws-sam/build/
folder structure would be created. This really does need some safety mechanisms before making such draconian assumptions.Thank goodness for backups 😕
@m1keil We defiantly need more safe guards here for sure. I am not arguing against that. 😃
What I was trying to understand is why you where using it and what you were trying to achieve?
build-dir
’s help text says “Path to a folder where the built artifacts will be stored”. The default here is technically.aws-sam
, which is why you saw the behavior you did.You really don’t need to override any of these values unless you really wanted to control where the artifacts are placed. In most cases, you don’t need to control this and will create more work for you as you need to pass the generated template and location into other commands (like
sam local invoke
,sam package
, etc).