'Python code to get all the files under a Lambda package

I was trying to read all the files under a directory using python in AWS Lambda. The entire python package is deployed to Lambda via backend jenkins job. While trying to read the files using importlib, its showing error as __ enter __. The code tried is as below:

With importlib.resources.contents(directory_name) as ct:
    print(ct)    

Can someone please help me to understand the issue or is there a proper way by which we can read the contents of a directory deployed in AWS Lambda function.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source