I'm working on an python AWS Lambda function that utilises pydantic to perform input validation. I have recently found that Lambda times out (with a timeout of 15 seconds) when executing the following code:
def _stringify(v):
return str(v)
class SomeModel(BaseModel):
a: int
_stringify = validator("a", allow_reuse=True)(_stringify)
SomeModel(a=12)
I have identified that the issue occurs when calling _stringify = validator("a", allow_reuse=True)(_stringify)
which passes the _stringify function to the validator decorator. This is fully functional in a local environment but not within AWS Lambda. The following alternative definition of 'SomeModel' also works within the AWS Lambda environment.
class SomeModel(BaseModel):
a: int
@validator("a")
def stringify(cls, v):
return str(v)
Does anyone with a better understanding of AWS Lambda have any ideas as to why _stringify = validator("a", allow_reuse=True)(_stringify)
results in a timeout and can you suggest any possible fixes?
(Note: The alternative definition of SomeModel is undesirable as it violates DRY principles as we want to use _stringify in multiple models.)
The code raises no exceptions when running both locally and in the Lambda environment.
Environment:
AWS Lambda
python 3.8 - Custom runtime build through docker. Lambda layers supporting:
Environment: python 3.8
AWS Lambda does not support Python 3.8 unless you are using your own Custom Runtime ( https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html ).
You need to make next steps:
Withour step #3 you will not be able to use third-party libraries
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.