Skip to content

Commit 0006615

Browse files
Merge from aws/aws-sam-cli/develop
2 parents 9a2a2bd + 0f50bea commit 0006615

10 files changed

Lines changed: 32 additions & 15 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ pre-dev = [
6868
dev = [
6969
"aws-sam-cli[pre-dev]",
7070
"coverage==7.13.4",
71-
"pytest-cov==7.0.0",
71+
"pytest-cov==7.1.0",
7272
"mypy==1.19.1",
73-
"types-pywin32==311.0.0.20260316",
73+
"types-pywin32==311.0.0.20260323",
7474
"types-PyYAML==6.0.12.20250915",
7575
"types-chevron==0.14.2.20250103",
7676
"types-psutil==7.2.2.20260130",

samcli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
SAM CLI version
33
"""
44

5-
__version__ = "1.157.0"
5+
__version__ = "1.157.1"

samcli/commands/local/cli_common/invoke_context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ def function_identifier(self) -> str:
563563
@property
564564
def lambda_runtime(self) -> LambdaRuntime:
565565
if not self._lambda_runtimes:
566-
layer_downloader = LayerDownloader(self._layer_cache_basedir, self.get_cwd(), self._stacks)
566+
layer_downloader = LayerDownloader(
567+
self._layer_cache_basedir, self.get_cwd(), self._stacks, mount_symlinks=self._mount_symlinks
568+
)
567569
image_builder = LambdaImage(
568570
layer_downloader, self._skip_pull_image, self._force_image_build, invoke_images=self._invoke_images
569571
)

samcli/local/lambdafn/remote_files.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
import requests
1010

11+
from samcli.commands.exceptions import UserException
1112
from samcli.lib.utils.progressbar import progressbar
1213
from samcli.local.lambdafn.zip import unzip
1314

1415
LOG = logging.getLogger(__name__)
1516

1617

17-
def unzip_from_uri(uri, layer_zip_path, unzip_output_dir, progressbar_label):
18+
def unzip_from_uri(uri, layer_zip_path, unzip_output_dir, progressbar_label, mount_symlinks=False):
1819
"""
1920
Download the LayerVersion Zip to the Layer Pkg Cache
2021
@@ -44,7 +45,9 @@ def unzip_from_uri(uri, layer_zip_path, unzip_output_dir, progressbar_label):
4445

4546
# Forcefully set the permissions to 700 on files and directories. This is to ensure the owner
4647
# of the files is the only one that can read, write, or execute the files.
47-
unzip(layer_zip_path, unzip_output_dir, permission=0o700)
48+
unzip(layer_zip_path, unzip_output_dir, permission=0o700, mount_symlinks=mount_symlinks)
49+
except ValueError as ex:
50+
raise UserException(str(ex), wrapped_from=ex.__class__.__name__) from ex
4851

4952
finally:
5053
# Remove the downloaded zip file

samcli/local/lambdafn/runtime.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import threading
1212
from typing import Dict, Optional, Union
1313

14+
from samcli.commands.exceptions import UserException
1415
from samcli.lib.telemetry.metric import capture_parameter
1516
from samcli.lib.utils.file_observer import LambdaFunctionObserver
1617
from samcli.lib.utils.invocation_type import EVENT, REQUEST_RESPONSE
@@ -724,8 +725,10 @@ def _unzip_file(filepath, mount_symlinks=False):
724725
os.chmod(temp_dir, 0o755)
725726

726727
LOG.info("Decompressing %s", filepath)
727-
728-
unzip(filepath, temp_dir, mount_symlinks=mount_symlinks)
728+
try:
729+
unzip(filepath, temp_dir, mount_symlinks=mount_symlinks)
730+
except ValueError as ex:
731+
raise UserException(str(ex), wrapped_from=ex.__class__.__name__) from ex
729732

730733
# The directory that Python returns might have symlinks. The Docker File sharing settings will not resolve
731734
# symlinks. Hence get the real path before passing to Docker.

samcli/local/layers/layer_downloader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class LayerDownloader:
24-
def __init__(self, layer_cache, cwd, stacks: List[Stack], lambda_client=None):
24+
def __init__(self, layer_cache, cwd, stacks: List[Stack], lambda_client=None, mount_symlinks=False):
2525
"""
2626
2727
Parameters
@@ -39,6 +39,7 @@ def __init__(self, layer_cache, cwd, stacks: List[Stack], lambda_client=None):
3939
self.cwd = cwd
4040
self._stacks = stacks
4141
self._lambda_client = lambda_client
42+
self._mount_symlinks = mount_symlinks
4243

4344
@property
4445
def lambda_client(self):
@@ -133,6 +134,7 @@ def download(self, layer: LayerVersion, force=False) -> LayerVersion:
133134
layer_zip_path,
134135
unzip_output_dir=layer.codeuri,
135136
progressbar_label="Downloading {}".format(layer.layer_arn),
137+
mount_symlinks=self._mount_symlinks,
136138
)
137139

138140
download_lock.release_lock(success=True)

tests/integration/local/invoke/invoke_integ_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def get_command_list(
4848
tenant_id=None,
4949
container_host_interface=None,
5050
durable_execution_name=None,
51+
mount_symlinks=False,
5152
):
5253
command_list = [get_sam_command(), "local", "invoke", function_to_invoke]
5354

@@ -63,6 +64,9 @@ def get_command_list(
6364
if no_event:
6465
command_list = command_list + ["--no-event"]
6566

67+
if mount_symlinks:
68+
command_list = command_list + ["--mount-symlinks"]
69+
6670
if profile:
6771
command_list = command_list + ["--profile", profile]
6872

tests/integration/local/invoke/test_integrations_cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,13 @@ def test_skip_pull_image_in_env_var(self):
554554

555555
# For Windows, this test must run with administrator privilege
556556
@skipIf(SKIP_LAYERS_TESTS, "Skip layers tests in Appveyor only")
557-
@pytest.mark.flaky(reruns=3)
558557
@pytest.mark.requires_credential
559558
def test_invoke_returns_expected_results_from_git_function(self):
560559
command_list = InvokeIntegBase.get_command_list(
561-
"GitLayerFunction", template_path=self.template_path, event_path=self.event_path
560+
"GitLayerFunction",
561+
template_path=self.template_path,
562+
event_path=self.event_path,
563+
mount_symlinks=True,
562564
)
563565

564566
process = Popen(command_list, stdout=PIPE)
@@ -573,14 +575,14 @@ def test_invoke_returns_expected_results_from_git_function(self):
573575

574576
# For Windows, this test must run with administrator privilege
575577
@skipIf(SKIP_LAYERS_TESTS, "Skip layers tests in Appveyor only")
576-
@pytest.mark.flaky(reruns=3)
577578
@pytest.mark.requires_credential
578579
def test_invoke_returns_expected_results_from_git_function_with_parameters(self):
579580
command_list = InvokeIntegBase.get_command_list(
580581
"GitLayerFunctionParameters",
581582
template_path=self.template_path,
582583
event_path=self.event_path,
583584
parameter_overrides={"LayerVersion": "5"},
585+
mount_symlinks=True,
584586
)
585587

586588
process = Popen(command_list, stdout=PIPE)

tests/unit/local/lambdafn/test_remote_files.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_successfully_unzip_from_uri(
3535
progressbar_mock.update.assert_called_with(5)
3636
path_patch.assert_called_with("layer_zip_path")
3737
path_mock.unlink.assert_called()
38-
unzip_patch.assert_called_with("layer_zip_path", "output_zip_dir", permission=0o700)
38+
unzip_patch.assert_called_with("layer_zip_path", "output_zip_dir", permission=0o700, mount_symlinks=False)
3939
os_patch.environ.get.assert_called_with("AWS_CA_BUNDLE")
4040

4141
@patch("samcli.local.lambdafn.remote_files.unzip")
@@ -68,7 +68,7 @@ def test_not_unlink_file_when_file_doesnt_exist(
6868
progressbar_mock.update.assert_called_with(5)
6969
path_patch.assert_called_with("layer_zip_path")
7070
path_mock.unlink.assert_not_called()
71-
unzip_patch.assert_called_with("layer_zip_path", "output_zip_dir", permission=0o700)
71+
unzip_patch.assert_called_with("layer_zip_path", "output_zip_dir", permission=0o700, mount_symlinks=False)
7272
os_patch.environ.get.assert_called_with("AWS_CA_BUNDLE")
7373

7474
@patch("samcli.local.lambdafn.remote_files.unzip")
@@ -101,5 +101,5 @@ def test_unzip_from_uri_reads_AWS_CA_BUNDLE_env_var(
101101
progressbar_mock.update.assert_called_with(5)
102102
path_patch.assert_called_with("layer_zip_path")
103103
path_mock.unlink.assert_called()
104-
unzip_patch.assert_called_with("layer_zip_path", "output_zip_dir", permission=0o700)
104+
unzip_patch.assert_called_with("layer_zip_path", "output_zip_dir", permission=0o700, mount_symlinks=False)
105105
os_patch.environ.get.assert_called_with("AWS_CA_BUNDLE")

tests/unit/local/layers/test_download_layers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def __eq__(self, other):
142142
AnyStringWith(str(Path("/tmp/cache/layer1_"))),
143143
unzip_output_dir=str(Path("/tmp/cache/layer1").resolve()),
144144
progressbar_label="Downloading arn:layer:layer1",
145+
mount_symlinks=False,
145146
)
146147

147148
@patch("samcli.local.layers.layer_downloader.LayerDownloader._create_cache")

0 commit comments

Comments
 (0)