AWS/Sam CodeURI and Handler specification issues

0

I have been having all kinds of problems using/specifying CodeUri and Handler specifications consistently.

It is my understanding that the way it supposed to work is that if you have a source tree of <project-dir>/src/api/... and <project-dir>/src/lib/... etc., you should be able to specify CodeUri: src/ and then the handlers can be specified as Handler: api....app.lambda_handler alleviating the need to prefix everything with src. This then holds true for any files we access from within a handler -- i.e., the path(s) to a template file like "./src/lib/categories/all.json" should be able to be referenced as "./lib/categories/all.json"

I have had it happen that the first function defined can use CodeUri: src/ but the remaining functions won't work unless CodeUri: is removed and then the handlers are specified as Handler: src.api...app.lambda_handler. (It does not matter if you specify '.' or '/' as the delimiter in the Handler syntax.)

Furthermore, for the instance where the first function was able to use CodeUri: src/ we found that when deployed into a different AWS/Sam stack/container by my colleague, it no longer accepted the CodeUri specification and we had to revert everything to use the Handler: src.api...app.lambda_handler form to get it to work across deployment containers.

So, my questions is "What am I missing regarding using CodeUri and Handler specifications, or my template.yaml in general, to make this more usable and consistent?. Any help would be appreciated.

jeffp
asked 9 months ago174 views
1 Answer
0

Your project, and therefore, your template file, may include multiple Lambda functions, each in its own sub folder. You usually place your template.yaml file in the root of the project, i.e., <project-dir>/template.yaml.

If your functions are located in <project-dir>/src/function1 and <project-dir>/src/function2, you will use in the CodeUri the root of the function itself, i.e., for the first function you will specify <project-dir>/src/function1 and for the second <project-dir>/src/function2. For the Handler you will specify the name of the file and the name of the handler, e.g., app.lambda_handler (where app.py is the file that contains the handler function, which is called lambda_handler)

profile pictureAWS
EXPERT
Uri
answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions