Skip to content

Bug: sam build - PermissionError #6114

Open
@coyster

Description

@coyster

Description:

On attempts to run 'sam build' the build fails with a permissions error: Error: [WinError 5] Access is denied: '.aws-sam\build'

This can be fixed by deleting '.aws-sam\build' and running it again

Steps to reproduce:

  1. Open VS Code, in integrated Powershell terminal OR Open cmd Terminal and USER OR Open cmd Terminal as Admin
  2. Create new sam build using 'sam init'
  3. ^ New build does not matter if using Zip or Image
  4. run 'sam build'
  5. change anything
  6. run 'sam build'
  7. Should get "Error: [WinError 5] Access is denied: '.aws-sam\build'"

Observed result:

PS C:\Users\oyste\Desktop\Work\Code\trading\trading_historical\testing-image-app> sam build --debug
2023-10-19 07:18:28,693 | Config file location: C:\Users\oyste\Desktop\Work\Code\trading\trading_historical\testing-image-app\samconfig.toml
2023-10-19 07:18:28,701 | Loading configuration values from [default.['build'].parameters] (env.command_name.section) in config file at
'C:\Users\oyste\Desktop\Work\Code\trading\trading_historical\testing-image-app\samconfig.toml'...
2023-10-19 07:18:28,707 | Configuration values successfully loaded.
2023-10-19 07:18:28,710 | Configuration values are: {'stack_name': 'testing-image-app', 'parallel': True}
2023-10-19 07:18:28,723 | Using SAM Template at C:\Users\oyste\Desktop\Work\Code\trading\trading_historical\testing-image-app\template.yaml
2023-10-19 07:18:28,830 | Using config file: samconfig.toml, config environment: default
2023-10-19 07:18:28,833 | Expand command line arguments to:
2023-10-19 07:18:28,835 | --template_file=C:\Users\oyste\Desktop\Work\Code\trading\trading_historical\testing-image-app\template.yaml --parallel --mount_with=READ --build_dir=.aws-sam\build --cache_dir=.aws-sam\cache
2023-10-19 07:18:29,171 | 'build' command is called
2023-10-19 07:18:29,183 | No Parameters detected in the template
2023-10-19 07:18:29,245 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2023-10-19 07:18:29,248 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2023-10-19 07:18:29,252 | 0 stacks found in the template
2023-10-19 07:18:29,254 | No Parameters detected in the template
2023-10-19 07:18:29,304 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2023-10-19 07:18:29,307 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2023-10-19 07:18:29,311 | 2 resources found in the stack
2023-10-19 07:18:29,314 | Found Serverless function with name='HelloWorldFunction' and ImageUri='None'
2023-10-19 07:18:29,316 | --base-dir is not presented, adjusting uri ./hello_world relative to C:\Users\oyste\Desktop\Work\Code\trading\trading_historical\testing-image-app\template.yaml
2023-10-19 07:18:29,319 | --base-dir is not presented, adjusting uri . relative to C:\Users\oyste\Desktop\Work\Code\trading\trading_historical\testing-image-app\template.yaml
2023-10-19 07:18:29,325 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-10-19 07:18:29,602 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-10-19 07:18:29,603 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '91d1e8b1-a2cc-4531-95de-f39578735efc', 'installationId': 'daad4230-ee40-4865-8dae-f1db52188fad', 'sessionId':
'a393b7e4-7a1e-4e91-923e-4b735d123479', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.5', 'samcliVersion': '1.98.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName':
'sam build', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': '339b03518009719cfd9af84b43451ac58a5366bde11351f3c46d7fb02e3c58ce', 'projectName':
'628fb8669b10cdc284105f6306515eaa0e65695792223dc0377fd0405726631c', 'initialCommit': 'a38324bb2319e696d5d323fcaa98c7df20e0be3e87392d5e5cfbfcdf04e42596'}, 'duration': 494, 'exitReason': 'PermissionError', 'exitCode':
255}}]}
2023-10-19 07:18:29,604 | Unable to find Click Context for getting session_id.
2023-10-19 07:18:29,614 | Sending Telemetry: {'metrics': [{'events': {'requestId': '923c288f-5a8e-45f0-8291-668514dedbe4', 'installationId': 'daad4230-ee40-4865-8dae-f1db52188fad', 'sessionId':
'a393b7e4-7a1e-4e91-923e-4b735d123479', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.5', 'samcliVersion': '1.98.0', 'commandName': 'sam build', 'metricSpecificAttributes': {'events': [{'event_name':
'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': 'baf4e4aeff594a009a800009b240e845', 'time_stamp': '2023-10-19 11:18:28.693', 'exception_name': None}, {'event_name': 'SamConfigFileExtension',
'event_value': '.toml', 'thread_id': '2cfefea0dadd4ee4a638150a467aed04', 'time_stamp': '2023-10-19 11:18:28.830', 'exception_name': None}]}}}]}
2023-10-19 07:18:30,547 | Telemetry response: 200

Error: [WinError 5] Access is denied: '.aws-sam\build'
Traceback:
File "C:\Python311\Lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\click\core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\samcli\cli\cli_config_file.py", line 297, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\click\decorators.py", line 92, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\samcli\lib\telemetry\metric.py", line 184, in wrapped
raise exception # pylint: disable=raising-bad-type
^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\samcli\lib\telemetry\metric.py", line 149, in wrapped
return_value = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\samcli\lib\utils\version_checker.py", line 42, in wrapped
actual_result = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\samcli\cli\main.py", line 95, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\samcli\commands\build\command.py", line 171, in cli
do_cli(
File "C:\Python311\Lib\site-packages\samcli\commands\build\command.py", line 236, in do_cli
with BuildContext(
File "C:\Python311\Lib\site-packages\samcli\commands\build\build_context.py", line 184, in enter
self.set_up()
File "C:\Python311\Lib\site-packages\samcli\commands\build\build_context.py", line 215, in set_up
self._build_dir = self._setup_build_dir(self._build_dir, self._clean)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\samcli\commands\build\build_context.py", line 454, in _setup_build_dir
shutil.rmtree(build_dir)
File "C:\Python311\Lib\shutil.py", line 759, in rmtree
return _rmtree_unsafe(path, onerror)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\shutil.py", line 626, in _rmtree_unsafe
onerror(os.rmdir, path, sys.exc_info())
File "C:\Python311\Lib\shutil.py", line 624, in _rmtree_unsafe
os.rmdir(path)

An unexpected error was encountered while executing "sam build".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20build%20-%20PermissionError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20build%20-%20PermissionError
2023-10-19 07:18:30,583 | Telemetry response: 200

Expected result:

Rebuilding causes no issue

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

  1. OS: Windows 10, 10.0.19045-SP0
  2. sam --version: SAM CLI, version 1.98.0
  3. AWS region: us-east-2, us-east-1 (Fails on both, only 2 tried)
# Paste the output of `sam --info` here

{
"version": "1.98.0",
"system": {
"python": "3.11.5",
"os": "Windows-10-10.0.19045-SP0"
},
"additional_dependencies": {
"docker_engine": "24.0.2",
"aws_cdk": "Not available",
"terraform": "1.2.6"
},
"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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions