Importing files from different folder in python and then deploy on AWS Lambda using AWS SAM

Viewed 699

My folder structure looks like this

-Parent_folder
     -functions
         -function1
             -app.py
             -requirements.txt
     -lib
         -helpers.py
     -template.yaml

I want to use helpers.py in app.py. My code in app.py looks like below:

from os.path import dirname, abspath

#append path to inlude self-declared modules
d = dirname(dirname(abspath(__file__)))
sys.path.append(d)

from lib import helpers

This is working fine. The problem is that how shall i deploy the same using aws sam on aws lambda. Currently I am using sam build and sam deploy to deploy my work but it is not deploying lib directory as a dependency and hence not working.

AWS SAM template file :

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  test

Resources:
    ZohoTransformationFunction:
        Type: AWS::Serverless::Function
        Properties:
            FunctionName: funcName
            CodeUri: path/
            Handler: app.lambda_handler
            Runtime: python3.9
            Role: 
         
0 Answers
Related