-
I have a issue with When I call it locally in REPL it works, but inside a lambda function it keeps to raise a error In lambda hanlder.py file I have add simple prints for my from aws_lambda_powertools.utilities.parser import BaseModel, Field,
import EventModel
def handler(event, context):
print(event)
print(EventModel)
print(EventModel.__mro__)
print(EventModel.__dict__)
ret = parse(event=event, model=EventModel) The class EventModel(BaseModel):
version: str
id: str
detail_type: str = Field(..., alias='detail-type')
source: str
account: str
time: str
region: str
resources: List[str]
detail: Union[Dummy,
Dummy1,
Dummy2,
Dummy3,
Dummy4]
class Dummy(BaseModel):
status: Literal["KickoffPipelines"]
pipeline: str
.... I intentionally hide real names of dummy models. The error log with printed values: <class 'utils.validation.EventModel'>
(<class 'utils.validation.EventModel'>, <class 'pydantic.main.BaseModel'>, <class 'pydantic.utils.Representation'>, <class 'object'>)
InvalidModelTypeError: Input model must implement BaseModel, model=<class 'utils.validation.EventModel' P.S I have tried to use from aws_lambda_powertools.utilities.parser.models import EventBridgeModel
class EventModel(EventBridgeModel):
detail: Union[Dummy,
Dummy1,
Dummy2,
Dummy3,
Dummy4] |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The error occurred earlier but lambda only report last The issue was that my lambda was missing class Dummy(BaseModel):
status: Literal["KickoffPipelines"]
pipeline: str
user_uuid :str
user_email : str
@root_validator
def cognito_user_validation(cls, values):
user_uuid, user_email = values.get('user_uuid'), values.get('user_email ')
if validate_cognito_user(user_uuid, user_email):
raise ValueError("User must be valid!Cognito user existence failed!")
return values
def validate_cognito_user(user_uuid, user_email):
try:
response = CONGNITO_CLIENT.admin_get_user(
UserPoolId=USER_POOL_ID,
Username=user_uuid
)
except CONGNITO_CLIENT.exceptions.UserNotFoundException:
msg = f"User name :{user_uuid} is not valid! Event will not be processed"
raise UserNotExistsInCognitoPollException(msg)
print(response)
expected_email = [attribute["Value"] for attribute in response["UserAttributes"]
if attribute["Name"] == "email"][0]
if user_email != expected_email:
msg = f"User email :{user_email} is not valid! Event will not be processed"
raise IncorrectEmailForUserInCognitoPollException(msg) |
Beta Was this translation helpful? Give feedback.
The error occurred earlier but lambda only report last
Traceback
error massage.So it so connected how lambda present the
Traceback
not with aaws_lambda_powertools
The issue was that my lambda was missing
Policy
cognito-idp:AdminGetUser