Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass the missing extra_hosts argument #6889

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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: 6 additions & 1 deletion samcli/commands/local/cli_common/invoke_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,12 @@ def _initialize_all_functions_containers(self) -> None:
def initialize_function_container(function: Function) -> None:
function_config = self.local_lambda_runner.get_invoke_config(function)
self.lambda_runtime.run(
None, function_config, self._debug_context, self._container_host, self._container_host_interface
container=None,
function_config=function_config,
debug_context=self._debug_context,
container_host=self._container_host,
container_host_interface=self._container_host_interface,
extra_hosts=self._extra_hosts,
)

try:
Expand Down
24 changes: 22 additions & 2 deletions samcli/local/lambdafn/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def create(
Debugging context for the function (includes port, args, and path)
container_host string
Host of locally emulated Lambda container
container_host_interface string
Optional. Interface that Docker host binds ports to
Comment on lines +70 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating missing documentation!

extra_hosts Dict
Optional. Dict of hostname to IP resolutions

Returns
-------
Expand Down Expand Up @@ -116,7 +120,15 @@ def create(
LOG.debug("Ctrl+C was pressed. Aborting container creation")
raise

def run(self, container, function_config, debug_context, container_host=None, container_host_interface=None):
def run(
self,
container,
function_config,
debug_context,
container_host=None,
container_host_interface=None,
extra_hosts=None,
):
"""
Find the created container for the passed Lambda function, then using the
ContainerManager run this container.
Expand All @@ -134,6 +146,8 @@ def run(self, container, function_config, debug_context, container_host=None, co
Host of locally emulated Lambda container
container_host_interface string
Optional. Interface that Docker host binds ports to
extra_hosts Dict
Optional. Dict of hostname to IP resolutions

Returns
-------
Expand All @@ -142,7 +156,13 @@ def run(self, container, function_config, debug_context, container_host=None, co
"""

if not container:
container = self.create(function_config, debug_context, container_host, container_host_interface)
container = self.create(
function_config=function_config,
debug_context=debug_context,
container_host=container_host,
container_host_interface=container_host_interface,
extra_hosts=extra_hosts,
)

if container.is_running():
LOG.info("Lambda function '%s' is already running", function_config.full_path)
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/local/lambdafn/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,13 @@ def test_must_create_container_first_if_passed_container_is_none(self):
create_mock.return_value = container

self.runtime.run(None, self.func_config, debug_context=debug_options)
create_mock.assert_called_with(self.func_config, debug_options, None, None)
create_mock.assert_called_with(
function_config=self.func_config,
debug_context=debug_options,
container_host=None,
container_host_interface=None,
extra_hosts=None,
)
self.manager_mock.run.assert_called_with(container)

def test_must_skip_run_running_container(self):
Expand Down
Loading