Skip to content

Commit

Permalink
Fix bug in PR#6719 (#6794)
Browse files Browse the repository at this point in the history
* Refactor to run sam validate before any sam local logic

* Formatting

* refactor sam validate

* raise docker image creation error

* fix lint errors

* update type hint

* handle container creation error in local apigw service

* reformat

* handle errors in local api invoke and local lambda invoke

* move exception

* handle error in local invoke

* remove unnecessary integration tests

* fix formatting

* use try/except to run lint

* fix unexpected arg in invoke context

* fix test

* fix broken test

---------

Co-authored-by: Jared Bentvelsen <[email protected]>
Co-authored-by: Haresh Nasit <[email protected]>
  • Loading branch information
3 people authored Mar 8, 2024
1 parent a0a299a commit 39240d0
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion samcli/commands/local/invoke/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def do_cli( # pylint: disable=R0914
container_host_interface=container_host_interface,
add_host=add_host,
invoke_images=processed_invoke_images,
ctx=ctx,
verbose=ctx.debug,
) as context:
# Invoke the function
context.local_lambda_runner.invoke(
Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/local/start_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def do_cli( # pylint: disable=R0914
container_host_interface=container_host_interface,
invoke_images=processed_invoke_images,
add_host=add_host,
ctx=ctx,
verbose=ctx.debug,
) as invoke_context:
ssl_context = (ssl_cert_file, ssl_key_file) if ssl_cert_file else None
service = LocalApiService(
Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/local/start_lambda/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def do_cli( # pylint: disable=R0914
container_host_interface=container_host_interface,
add_host=add_host,
invoke_images=processed_invoke_images,
ctx=ctx,
verbose=ctx.debug,
) as invoke_context:
service = LocalLambdaService(lambda_invoke_context=invoke_context, port=port, host=host)
service.start()
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/commands/local/invoke/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_cli_must_setup_context_and_invoke(self, get_event_mock, InvokeContextMo
container_host_interface=self.container_host_interface,
add_host=self.add_host,
invoke_images={None: "amazon/aws-sam-cli-emulation-image-python3.9"},
ctx=self.ctx_mock,
verbose=self.ctx_mock.debug,
)

context_mock.local_lambda_runner.invoke.assert_called_with(
Expand Down Expand Up @@ -157,7 +157,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"},
ctx=self.ctx_mock,
verbose=self.ctx_mock.debug,
)

get_event_mock.assert_not_called()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/commands/local/start_api/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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={},
ctx=self.ctx_mock,
verbose=self.ctx_mock.debug,
)

local_api_service_mock.assert_called_with(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/commands/local/start_lambda/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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={},
ctx=self.ctx_mock,
verbose=self.ctx_mock.debug,
)

local_lambda_service_mock.assert_called_with(lambda_invoke_context=context_mock, port=self.port, host=self.host)
Expand Down

0 comments on commit 39240d0

Please sign in to comment.