Replies: 1 comment 4 replies
-
Wouldn't it be simpler and safer to just reference the function from the component by name? Like this: service: app
provider:
name: aws
functions:
worker:
handler: worker.handler
queues:
emails:
function: worker |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'll be using this discussion to track what we've learned about declaring Lambda functions outside of the
functions
section in serverless.yml.For example with a "queues" component, the goal is to define the "worker" function inside the queue:
The idea is to "copy" the content of
queues.emails.worker
intofunctions
. Then Serverless should process that function as usual.So far I've identified the following flow when Serverless runs:
scripts/serverless.js
Serverless.run()
(lib/Serverless.js
)Service.setFunctionNames()
(lib/classes/Service.js
)initialize
hookService.setFunctionNames()
normalizes thefunctions
. I've tried inserting functions after that (in theinitialize
hook) but my inserted functions were causing errors later (because they were not normalized).That means that:
setFunctionNames()
This is risky: we run the risk of missing some behavior, not normalizing correctly, etc.
functions
before thatIdeally we would aim for solution 2. That means we can't use the
initialize
hook.With that in mind, I've tested inserting the functions when the component boots. Simplified example:
And in unit tests this is working!
We'll probably need more testing on this, see if this really works, especially with events, variables, config validation, or any other processing Serverless might do.
To those reading: if you have other ideas, please share :)
Beta Was this translation helpful? Give feedback.
All reactions