0
votes

I have several AWS Lambda functions in Serverless, and found I was writing the same sendEmail function over and over. Just setting up the client and composing the SES response with a few minor tweaks. I decided it would be best to abstract this to a single function that is called by the others. My folder structure resembles:

Serverless
-----> Commons
-----------> sendEmail.py
-----> AlarmsManager
---------> Alarm1.py
---------> Alarm2.py 
---------> serverless.yml
-----> BackupManager
---------> Backup1.py
---------> Backup2.py 
---------> serverless.yml

My question is, how do I call this email function from other deployments? Is it as simple as including a fully-qualified path to it in the calling function's serverless.yml file (which already has the proper SES IAM permissions), or will this need its own serverless.yml file with a trigger instead of an event schedule? Can I even make use of it from other functions if it belongs to its own deployment? Obviously, I'd prefer the former, but I'm confused as to how it should all come together.

1

1 Answers

0
votes

An option would be to package all your functions together (that is with a serverless.yml file at the root only) and declare your functions with full path like

functions:
  alarm1:
    handler: AlarmsManager/Alarm1.handler
    ...
  alarm2:
    handler: AlarmsManager/Alarm2.handler
    ...
  backup1:
    handler: BackupManager/Backup1.handler
    ...

This will create a unique archive with all your directory structure starting at root. At this point you can just access, say, your Commons source files via relative paths.