Aws function throws error version `ZLIB_1.2.9' not found

I created a lambda function using python 3.8 and installed pillow for image processing.
By default aws installs the pillow version 9.5.0 and zlib version 1.2.11.
However when I execute the function, it throws the error: version `ZLIB_1.2.9’ not found (required by Pillow.lib/
I have tried many things from the internet but cannot overcome this error.
Could you please help me?
Thank you.

After experimentation, I managed to find a solution by myself. Instead of using the latest amazon linux 2023 ami, I used the amazon linux 2022 ami and worked fine for my case.