diff --git a/samcli/local/docker/exceptions.py b/samcli/local/docker/exceptions.py index cc00698083..7cf0cbb3c0 100644 --- a/samcli/local/docker/exceptions.py +++ b/samcli/local/docker/exceptions.py @@ -25,3 +25,9 @@ class ContainerFailureError(UserException): """ Raised when the invoke container fails execution """ + + +class InvalidRuntimeException(UserException): + """ + Raised when an invalid runtime is specified for a Lambda Function + """ diff --git a/samcli/local/docker/lambda_container.py b/samcli/local/docker/lambda_container.py index 3eea56c72d..609d5bfbb3 100644 --- a/samcli/local/docker/lambda_container.py +++ b/samcli/local/docker/lambda_container.py @@ -7,6 +7,7 @@ from typing import List from samcli.lib.utils.packagetype import IMAGE +from samcli.local.docker.exceptions import InvalidRuntimeException from samcli.local.docker.lambda_debug_settings import LambdaDebugSettings from .container import DEFAULT_CONTAINER_HOST_INTERFACE, Container @@ -15,6 +16,7 @@ LOG = logging.getLogger(__name__) RIE_LOG_LEVEL_ENV_VAR = "SAM_CLI_RIE_DEV" +INVALID_RUNTIME_MESSAGE = "Unsupported Lambda runtime: {runtime}. For a list of supported runtimes, please visit https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html" class LambdaContainer(Container): @@ -95,7 +97,7 @@ def __init__( Optional. The function full path, unique in all stacks """ if not Runtime.has_value(runtime) and not packagetype == IMAGE: - raise ValueError("Unsupported Lambda runtime {}".format(runtime)) + raise InvalidRuntimeException(INVALID_RUNTIME_MESSAGE.format(runtime=runtime)) image = LambdaContainer._get_image( lambda_image, runtime, packagetype, imageuri, layers, architecture, function_full_path diff --git a/tests/unit/local/docker/test_lambda_container.py b/tests/unit/local/docker/test_lambda_container.py index 681931402d..f5261ecd13 100644 --- a/tests/unit/local/docker/test_lambda_container.py +++ b/tests/unit/local/docker/test_lambda_container.py @@ -9,6 +9,7 @@ from samcli.commands.local.lib.debug_context import DebugContext from samcli.lib.utils.packagetype import IMAGE, ZIP +from samcli.local.docker.exceptions import InvalidRuntimeException from samcli.local.docker.lambda_container import LambdaContainer, Runtime, RIE_LOG_LEVEL_ENV_VAR from samcli.local.docker.lambda_debug_settings import DebuggingNotSupported from samcli.local.docker.lambda_image import RAPID_IMAGE_TAG_PREFIX @@ -433,7 +434,7 @@ def test_must_fail_for_unsupported_runtime(self): image_builder_mock = Mock() - with self.assertRaises(ValueError) as context: + with self.assertRaises(InvalidRuntimeException) as context: LambdaContainer( runtime=runtime, imageuri=self.imageuri, @@ -446,7 +447,10 @@ def test_must_fail_for_unsupported_runtime(self): architecture="x86_64", ) - self.assertEqual(str(context.exception), "Unsupported Lambda runtime foo") + self.assertEqual( + str(context.exception), + "Unsupported Lambda runtime: foo. For a list of supported runtimes, please visit https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html", + ) @parameterized.expand( [