Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions samcli/commands/local/cli_common/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ def invoke_common_options(f):
help="Specify the location basedir where the lambda layers used by the template will be downloaded to.",
default=get_default_layer_cache_dir(),
),
click.option(
"--filesystem",
type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True),
help="Local directory to mount as EFS filesystem for Lambda functions. "
"Maps to the LocalMountPath specified in the function's FileSystemConfigs. "
"If no FileSystemConfigs is specified, defaults to /mnt/efs",
),
]
+ docker_click_options()
+ [
Expand Down
1 change: 1 addition & 0 deletions samcli/commands/local/invoke/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"add_host",
"invoke_image",
"runtime",
"filesystem",
"mount_symlinks",
"no_memory_limit",
]
Expand Down
4 changes: 4 additions & 0 deletions samcli/commands/local/start_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def cli(
docker_network,
log_file,
layer_cache_basedir,
filesystem,
skip_pull_image,
force_image_build,
parameter_overrides,
Expand Down Expand Up @@ -164,6 +165,7 @@ def cli(
docker_network,
log_file,
layer_cache_basedir,
filesystem,
skip_pull_image,
force_image_build,
parameter_overrides,
Expand Down Expand Up @@ -197,6 +199,7 @@ def do_cli( # pylint: disable=R0914
docker_network,
log_file,
layer_cache_basedir,
filesystem,
skip_pull_image,
force_image_build,
parameter_overrides,
Expand Down Expand Up @@ -256,6 +259,7 @@ def do_cli( # pylint: disable=R0914
container_host_interface=container_host_interface,
invoke_images=processed_invoke_images,
add_host=add_host,
filesystem_dir=filesystem,
no_mem_limit=no_mem_limit,
) as invoke_context:
ssl_context = (ssl_cert_file, ssl_key_file) if ssl_cert_file else None
Expand Down
1 change: 1 addition & 0 deletions samcli/commands/local/start_api/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"docker_volume_basedir",
"skip_pull_image",
"docker_network",
"filesystem",
"force_image_build",
"no_memory_limit",
"warm_containers",
Expand Down
4 changes: 4 additions & 0 deletions samcli/commands/local/start_lambda/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def cli(
docker_network,
log_file,
layer_cache_basedir,
filesystem,
skip_pull_image,
force_image_build,
parameter_overrides,
Expand Down Expand Up @@ -122,6 +123,7 @@ def cli(
docker_network,
log_file,
layer_cache_basedir,
filesystem,
skip_pull_image,
force_image_build,
parameter_overrides,
Expand Down Expand Up @@ -151,6 +153,7 @@ def do_cli( # pylint: disable=R0914
docker_network,
log_file,
layer_cache_basedir,
filesystem,
skip_pull_image,
force_image_build,
parameter_overrides,
Expand Down Expand Up @@ -208,6 +211,7 @@ def do_cli( # pylint: disable=R0914
container_host_interface=container_host_interface,
add_host=add_host,
invoke_images=processed_invoke_images,
filesystem_dir=filesystem,
no_mem_limit=no_mem_limit,
) as invoke_context:
service = LocalLambdaService(lambda_invoke_context=invoke_context, port=port, host=host)
Expand Down
1 change: 1 addition & 0 deletions samcli/commands/local/start_lambda/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"docker_volume_basedir",
"skip_pull_image",
"docker_network",
"filesystem",
"force_image_build",
"shutdown",
"container_host",
Expand Down
21 changes: 18 additions & 3 deletions schema/samcli.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/unit/commands/local/cli_common/test_invoke_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ def test_must_create_runner_using_warm_containers(
container_host=None,
container_host_interface=None,
extra_hosts=None,
filesystem_dir=None,
)

result = self.context.local_lambda_runner
Expand Down Expand Up @@ -824,6 +825,7 @@ def test_must_create_runner_with_container_host_option(
container_host="abcdef",
container_host_interface="192.168.100.101",
extra_hosts=None,
filesystem_dir=None,
)

result = self.context.local_lambda_runner
Expand Down
1 change: 1 addition & 0 deletions tests/unit/commands/local/invoke/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def test_cli_must_invoke_with_no_event(self, get_event_mock, InvokeContextMock):
container_host_interface=self.container_host_interface,
add_host=self.add_host,
invoke_images={None: "amazon/aws-sam-cli-emulation-image-python3.9"},
filesystem_dir=self.filesystem,
mount_symlinks=self.mount_symlinks,
no_mem_limit=self.no_mem_limit,
)
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/commands/local/start_api/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_cli_must_setup_context_and_start_service(self, local_api_service_mock,
container_host_interface=self.container_host_interface,
add_host=self.add_host,
invoke_images={},
filesystem_dir=None,
no_mem_limit=self.no_mem_limit,
)

Expand Down Expand Up @@ -215,9 +216,10 @@ def call_cli(self):
docker_volume_basedir=self.docker_volume_basedir,
docker_network=self.docker_network,
log_file=self.log_file,
layer_cache_basedir=self.layer_cache_basedir,
filesystem=None,
skip_pull_image=self.skip_pull_image,
parameter_overrides=self.parameter_overrides,
layer_cache_basedir=self.layer_cache_basedir,
force_image_build=self.force_image_build,
warm_containers=self.warm_containers,
debug_function=self.debug_function,
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/commands/local/start_lambda/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def setUp(self):
self.add_host = {}
self.invoke_image = ()
self.hook_name = None
self.filesystem = None
self.no_mem_limit = False

@patch("samcli.commands.local.cli_common.invoke_context.InvokeContext")
Expand Down Expand Up @@ -85,6 +86,7 @@ def test_cli_must_setup_context_and_start_service(self, local_lambda_service_moc
container_host_interface=self.container_host_interface,
add_host=self.add_host,
invoke_images={},
filesystem_dir=self.filesystem,
no_mem_limit=self.no_mem_limit,
)

Expand Down Expand Up @@ -178,6 +180,7 @@ def call_cli(self):
skip_pull_image=self.skip_pull_image,
parameter_overrides=self.parameter_overrides,
layer_cache_basedir=self.layer_cache_basedir,
filesystem=self.filesystem,
force_image_build=self.force_image_build,
warm_containers=self.warm_containers,
debug_function=self.debug_function,
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/commands/samconfig/test_samconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ def test_local_invoke(self, do_cli_mock):
("image",),
None,
None,
None,
True,
True,
)
Expand Down Expand Up @@ -651,6 +652,7 @@ def test_local_invoke_with_runtime_params(self, do_cli_mock):
("image",),
None,
"python3.11",
None,
True,
True,
)
Expand Down Expand Up @@ -710,6 +712,7 @@ def test_local_start_api(self, do_cli_mock):
"mynetwork",
"logfile",
"basedir",
None,
True,
True,
{"Key": "Value", "Key2": "Value2"},
Expand Down Expand Up @@ -777,6 +780,7 @@ def test_local_start_lambda(self, do_cli_mock):
"mynetwork",
"logfile",
"basedir",
None,
True,
True,
{"Key": "Value"},
Expand Down Expand Up @@ -1669,6 +1673,7 @@ def test_override_with_cli_params(self, do_cli_mock):
"othernetwork",
"otherlogfile",
"otherbasedir",
None,
True,
True,
{"A": "123", "C": "D", "E": "F12!", "G": "H"},
Expand Down Expand Up @@ -1768,6 +1773,7 @@ def test_override_with_cli_params_and_envvars(self, do_cli_mock):
"envnetwork",
"otherlogfile",
"envlayercache",
None,
False,
True,
{"A": "123", "C": "D", "E": "F12!", "G": "H"},
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/local/docker/test_lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_must_configure_container_properly_zip(
get_exposed_ports_mock.assert_called_with(self.debug_options)
get_debug_settings_mock.assert_called_with(self.runtime, self.debug_options)
get_additional_options_mock.assert_called_with(self.runtime, self.debug_options)
get_additional_volumes_mock.assert_called_with(self.runtime, self.debug_options)
get_additional_volumes_mock.assert_called_with(self.runtime, self.debug_options, None)

@patch.object(LambdaContainer, "_get_config")
@patch.object(LambdaContainer, "_get_image")
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_must_configure_container_properly_image_no_debug(
)
get_exposed_ports_mock.assert_called_with(self.debug_options)
get_additional_options_mock.assert_called_with(self.runtime, self.debug_options)
get_additional_volumes_mock.assert_called_with(self.runtime, self.debug_options)
get_additional_volumes_mock.assert_called_with(self.runtime, self.debug_options, None)

@patch.object(LambdaContainer, "_get_config")
@patch.object(LambdaContainer, "_get_image")
Expand Down Expand Up @@ -269,7 +269,7 @@ def test_must_configure_container_properly_image_debug(
)
get_exposed_ports_mock.assert_called_with(self.debug_options)
get_additional_options_mock.assert_called_with(self.runtime, self.debug_options)
get_additional_volumes_mock.assert_called_with(self.runtime, self.debug_options)
get_additional_volumes_mock.assert_called_with(self.runtime, self.debug_options, None)

@patch.object(LambdaContainer, "_get_config")
@patch.object(LambdaContainer, "_get_image")
Expand Down Expand Up @@ -346,7 +346,7 @@ def test_must_configure_container_properly_image_with_imageconfig_debug(
)
get_exposed_ports_mock.assert_called_with(self.debug_options)
get_additional_options_mock.assert_called_with(self.runtime, self.debug_options)
get_additional_volumes_mock.assert_called_with(self.runtime, self.debug_options)
get_additional_volumes_mock.assert_called_with(self.runtime, self.debug_options, None)

@patch.object(LambdaContainer, "_get_config")
@patch.object(LambdaContainer, "_get_image")
Expand Down Expand Up @@ -428,7 +428,7 @@ def test_must_configure_container_properly_image_with_imageconfig_no_debug(
)
get_exposed_ports_mock.assert_called_with(self.debug_options)
get_additional_options_mock.assert_called_with(self.runtime, self.debug_options)
get_additional_volumes_mock.assert_called_with(self.runtime, self.debug_options)
get_additional_volumes_mock.assert_called_with(self.runtime, self.debug_options, None)

def test_must_fail_for_unsupported_runtime(self):
runtime = "foo"
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/local/lambdafn/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def test_must_create_lambda_container(self, LambdaContainerMock, LogMock):
extra_hosts=None,
function_full_path=self.full_path,
mount_symlinks=False,
filesystem_mounts=None,
)
# Run the container and get results
self.manager_mock.create.assert_called_with(container, ContainerContext.INVOKE)
Expand Down Expand Up @@ -145,6 +146,7 @@ def test_must_create_lambda_container_without_mem_limit(self, LambdaContainerMoc
extra_hosts=None,
function_full_path=self.full_path,
mount_symlinks=False,
filesystem_mounts=None,
)
# Run the container and get results
self.manager_mock.create.assert_called_with(container, ContainerContext.INVOKE)
Expand Down Expand Up @@ -217,6 +219,7 @@ def test_must_log_if_template_has_runtime_version(self, LambdaContainerMock, Log
extra_hosts=None,
function_full_path=self.full_path,
mount_symlinks=True,
filesystem_mounts=None,
)
# Run the container and get results
self.manager_mock.create.assert_called_with(container, ContainerContext.INVOKE)
Expand Down Expand Up @@ -403,6 +406,7 @@ def test_must_run_container_and_wait_for_result(self, LambdaContainerMock):
extra_hosts=None,
function_full_path=self.full_path,
mount_symlinks=False,
filesystem_mounts=None,
)

# Run the container and get results
Expand Down Expand Up @@ -765,6 +769,7 @@ def test_must_run_container_then_wait_for_result_and_container_not_stopped(
extra_hosts=None,
function_full_path=self.full_path,
mount_symlinks=False,
filesystem_mounts=None,
)

# Run the container and get results
Expand Down Expand Up @@ -868,6 +873,7 @@ def test_must_create_non_cached_container(self, LambdaContainerMock, LambdaFunct
extra_hosts=None,
function_full_path=self.full_path,
mount_symlinks=False,
filesystem_mounts=None,
)

self.manager_mock.create.assert_called_with(container, ContainerContext.INVOKE)
Expand Down Expand Up @@ -916,6 +922,7 @@ def test_must_create_incase_function_config_changed(self, LambdaContainerMock, L
extra_hosts=None,
function_full_path=self.full_path,
mount_symlinks=False,
filesystem_mounts=None,
),
call(
self.lang,
Expand All @@ -935,6 +942,7 @@ def test_must_create_incase_function_config_changed(self, LambdaContainerMock, L
extra_hosts=None,
function_full_path=self.full_path,
mount_symlinks=False,
filesystem_mounts=None,
),
]
)
Expand Down Expand Up @@ -1010,6 +1018,7 @@ def test_must_ignore_debug_options_if_function_name_is_not_debug_function(
extra_hosts=None,
function_full_path=self.full_path,
mount_symlinks=False,
filesystem_mounts=None,
)
self.manager_mock.create.assert_called_with(container, ContainerContext.INVOKE)
# validate that the created container got cached
Expand Down