moto/moto/awslambda/exceptions.py

106 lines
3.0 KiB
Python
Raw Normal View History

from moto.core.exceptions import JsonRESTError
from typing import Any
class LambdaClientError(JsonRESTError):
2022-10-22 11:40:20 +00:00
def __init__(self, error: str, message: str):
super().__init__(error, message)
class CrossAccountNotAllowed(LambdaClientError):
2022-10-22 11:40:20 +00:00
def __init__(self) -> None:
super().__init__(
"AccessDeniedException", "Cross-account pass role is not allowed."
)
class FunctionAlreadyExists(LambdaClientError):
code = 409
def __init__(self, function_name: str) -> None:
message = f"Function already exist: {function_name}"
super().__init__("ResourceConflictException", message)
class InvalidParameterValueException(LambdaClientError):
2022-10-22 11:40:20 +00:00
def __init__(self, message: str):
super().__init__("InvalidParameterValueException", message)
class InvalidRoleFormat(LambdaClientError):
pattern = r"arn:(aws[a-zA-Z-]*)?:iam::(\d{12}):role/?[a-zA-Z_0-9+=,.@\-_/]+"
2022-10-22 11:40:20 +00:00
def __init__(self, role: str):
message = f"1 validation error detected: Value '{role}' at 'role' failed to satisfy constraint: Member must satisfy regular expression pattern: {InvalidRoleFormat.pattern}"
super().__init__("ValidationException", message)
class PreconditionFailedException(JsonRESTError):
code = 412
2022-10-22 11:40:20 +00:00
def __init__(self, message: str):
super().__init__("PreconditionFailedException", message)
class ConflictException(LambdaClientError):
code = 409
def __init__(self, message: str):
super().__init__("ConflictException", message)
2022-03-17 11:32:31 -01:00
class UnknownAliasException(LambdaClientError):
code = 404
2022-10-22 11:40:20 +00:00
def __init__(self, arn: str):
2022-03-17 11:32:31 -01:00
super().__init__("ResourceNotFoundException", f"Cannot find alias arn: {arn}")
class UnknownFunctionException(LambdaClientError):
code = 404
2022-10-22 11:40:20 +00:00
def __init__(self, arn: str):
super().__init__("ResourceNotFoundException", f"Function not found: {arn}")
2022-03-17 11:32:31 -01:00
class FunctionUrlConfigNotFound(LambdaClientError):
code = 404
2022-10-22 11:40:20 +00:00
def __init__(self) -> None:
super().__init__(
"ResourceNotFoundException", "The resource you requested does not exist."
)
2022-03-17 11:32:31 -01:00
class UnknownLayerException(LambdaClientError):
code = 404
2022-10-22 11:40:20 +00:00
def __init__(self) -> None:
2022-03-17 11:32:31 -01:00
super().__init__("ResourceNotFoundException", "Cannot find layer")
class UnknownLayerVersionException(LambdaClientError):
code = 404
def __init__(self, arns: Any) -> None:
super().__init__(
"ResourceNotFoundException",
f"One or more LayerVersion does not exist {arns}",
)
2022-03-17 11:32:31 -01:00
class UnknownPolicyException(LambdaClientError):
code = 404
2022-10-22 11:40:20 +00:00
def __init__(self) -> None:
2022-03-17 11:32:31 -01:00
super().__init__(
"ResourceNotFoundException",
"No policy is associated with the given resource.",
)
class ValidationException(LambdaClientError):
def __init__(self, value: str, property_name: str, specific_message: str):
message = f"1 validation error detected: Value '{value}' at '{property_name}' failed to satisfy constraint: {specific_message}"
super().__init__("ValidationException", message)