Search code examples
pythonamazon-web-servicesaws-lambdalambda

configparser for .ini file throwing key error when running using docker image in AWs Lambda


I have a Python file and a config.ini file which contain two sets of SQL queries. I am accessing those queries in the Python file. When I run these files inside the EC2 instance it's working fine. But when I built a docker image using the above files and tried to run that image in lambda, from the config.ini file I got the key error. I am using a config parser for reading the config.ini file. It is working fine in the EC2 instance but not in lambda with the docker image. Anybody aware of this issue?


Solution

  • It's because of the config parser. In docker, it's working only if we give the absolute path like this

    script_dir = os.path.dirname(os.path.abspath(__file__))
    config_file_path = os.path.join(script_dir, 'config.ini')