Skip to content
Open
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: 7 additions & 0 deletions aws_lambda_builders/workflows/python_pip/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from aws_lambda_builders.workflows.python_pip.exceptions import MissingPipError
from aws_lambda_builders.workflows.python_pip.packager import (
DependencyBuilder,
MissingDependencyError,
PackagerError,
PipRunner,
PythonPipDependencyBuilder,
Expand Down Expand Up @@ -76,6 +77,12 @@ def execute(self) -> None:
scratch_dir_path=self.scratch_dir,
requirements_path=self.manifest_path,
)
except MissingDependencyError as ex:
raise ActionFailedError(
f"{ex}\n"
"If these dependencies require native compilation, build them in a Lambda-compatible Linux "
"environment. With the AWS SAM CLI, try 'sam build --use-container'."
) from ex
except PackagerError as ex:
raise ActionFailedError(str(ex))

Expand Down
20 changes: 16 additions & 4 deletions tests/unit/workflows/python_pip/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
PythonPipBuildAction,
)
from aws_lambda_builders.workflows.python_pip.exceptions import MissingPipError
from aws_lambda_builders.workflows.python_pip.packager import PackagerError
from aws_lambda_builders.workflows.python_pip.packager import MissingDependencyError, PackagerError


class TestPythonPipBuildAction(TestCase):
Expand Down Expand Up @@ -73,11 +73,19 @@ def test_action_must_call_builder_with_architecture(
artifacts_dir_path="artifacts", scratch_dir_path="scratch_dir", requirements_path="manifest"
)

@parameterized.expand(
[
("other_packager_error", PackagerError("Pip failed"), False),
("missing_dependency", MissingDependencyError(["native-package==1.0"]), True),
]
)
@patch("aws_lambda_builders.workflows.python_pip.actions.PythonPipDependencyBuilder")
@patch("aws_lambda_builders.workflows.python_pip.actions.PythonPipBuildAction._find_runtime_with_pip")
def test_must_raise_exception_on_failure(self, find_runtime_mock, pip_dependency_builder_mock):
def test_must_raise_exception_on_failure(
self, name, error, expects_container_hint, find_runtime_mock, pip_dependency_builder_mock
):
builder_instance = pip_dependency_builder_mock.return_value
builder_instance.build_dependencies.side_effect = PackagerError()
builder_instance.build_dependencies.side_effect = error
find_runtime_mock.return_value = (Mock(), Mock())

action = PythonPipBuildAction(
Expand All @@ -89,9 +97,13 @@ def test_must_raise_exception_on_failure(self, find_runtime_mock, pip_dependency
{"python": BinaryPath(resolver=Mock(), validator=Mock(), binary="python", binary_path=sys.executable)},
)

with self.assertRaises(ActionFailedError):
with self.assertRaises(ActionFailedError) as raised:
action.execute()

message = str(raised.exception)
self.assertIn(str(error), message)
self.assertEqual("sam build --use-container" in message, expects_container_hint)

@patch("aws_lambda_builders.workflows.python_pip.actions.PythonPipDependencyBuilder")
@patch("aws_lambda_builders.workflows.python_pip.actions.PythonPipBuildAction._find_runtime_with_pip")
def test_action_must_call_builder_with_dependencies_dir(self, find_runtime_mock, pip_dependency_builder_mock):
Expand Down
Loading