FyersLogger is not defined | when using lambda function

moduleName: fyersModel, ERR: could not import module : invalid syntax (base_events.py, line 296)                                         

{"timestamp": "2024-01-09T21:45:58Z", "log_level": "ERROR", "errorMessage": "name 'FyersLogger' is not defined", "errorType": "NameError", "requestId": "a558b171-b21b-447f-8ca8-ac883bf52383", "stackTrace": ["  File \"/var/task/gainer_loser.py\", line 160, in lambda_handler\n    top_gainers_lossers_runner()\n", "  File \"/var/task/gainer_loser.py\", line 152, in top_gainers_lossers_runner\n    db, fyres = Utils.get_common_resources()\n", "  File \"/var/task/utils.py\", line 62, in get_common_resources\n    fyers = fyersModel.FyersModel(token=access_token, is_async=False, client_id=client_id)\n", "  File \"/var/task/fyers_apiv3/fyersModel.py\", line 378, in init\n    self.api_logger = FyersLogger(\n"]}

I am using v3 API
Facing this error in lambda function. What is going wrong here? @Z4PBvkQGyF

I have tried almost everything. Below is my directory structure for the lambda function

Hi @granddervish

  1. Remove asyncio package (DO NOT include asyncio in your layer because it is already part of stdlib).
  • Pass log path as /temp (In AWS Lambda, the /var/task/ directory is the deployment package directory, and it is read-only. Lambda functions can’t write to this directory, and any attempt to do so will result in an error.)

Thanks @Z4PBvkQGyF! I had removed it from the requirements.txt already but still the error persist. Is there any other way from where I need to remove?

fyers = fyersModel.FyersModel(token=access_token, is_async=False, client_id=client_id, log_path='/temp')

For 2, is this fine @Z4PBvkQGyF

This is my requirement.txt

boto3==1.34.15
fyers-apiv3==3.0.6
pandas-ta==0.3.14b
numpy==1.26.3
pandas==2.1.4
PyMySQL==1.1.0
python-dotenv==1.0.0
pytz==2023.3.post1
requests==2.31.0
sentry-sdk==1.39.1
urllib3==1.26.18

Got this new error:

``

{“errorMessage”: “[Errno 2] No such file or directory: ‘/temp/fyersApi.log’”, “errorType”: “FileNotFoundError”, “requestId”: “8a540eb7-329e-4027-abd1-513cd77083f0”, “stackTrace”: [" File "/var/task/gainer_loser.py", line 159, in lambda_handler\n top_gainers_lossers_runner()\n", " File "/var/task/gainer_loser.py", line 151, in top_gainers_lossers_runner\n db, fyres = Utils.get_common_resources()\n", " File "/var/task/utils.py", line 60, in get_common_resources\n fyers = fyersModel.FyersModel(token=access_token, is_async=False, client_id=client_id, log_path=‘/temp’)\n", " File "/var/task/fyers_apiv3/fyersModel.py", line 382, in init\n logger_handler=logging.FileHandler(self.log_path + "fyersApi.log"),\n", " File "/var/lang/lib/python3.9/logging/init.py", line 1146, in init\n StreamHandler.init(self, self._open())\n", " File "/var/lang/lib/python3.9/logging/init.py", line 1175, in _open\n return open(self.baseFilename, self.mode, encoding=self.encoding,\n"]}

`


Some progress 😅

I had to manually delete the asyncio package because it was automatically installed. How do I avoid it’s installation? @Z4PBvkQGyF

Worked. had to replace temp with tmp