Feedback for “EventBridge event bus” -> handler can not be found
the documentation states implementing this will create a lambda called events and create an eventRule too:
functions:
# ...
events:
handler: App\MyHandler
events:
- eventBridge:
pattern:
detail-type:
- 'MyCustomEvent'
However when I add my handlers (I gave 2 examples) I walk into two issues:
- The lambdas it makes are node 14 while (i think) it should be linux 2. I found a fix for this. You can add: runtime: php-82-fpm or any other php version to make the lambda run the correct env.
- The handlers I've made can not be found. I tried various ways of writing the path to the handler but it wont work.
My example code:
functions:
vacancy-applied-send-to-dynamics:
handler: App\EventBridgeHandlers\SendVacancyToDynamicsHandler\SendVacancyToDynamicsHandler
runtime: php-82-fpm
events:
- eventBridge:
pattern:
detail-type:
- 'VancancyApplied'
vacancy-import-cluen-scheduled:
handler: App/EventBridgeHandlers/ImportVacanciesFromCluen/ImportVacanciesFromCluenHandler
runtime: php-82-fpm
events:
- eventBridge:
name: vacancy-import-cluen-scheduled
description: Imports vacancies from external service every 60 minutes
schedule: rate(60 minutes)
What am I doing wrong here? Serverless creates the correct eventRule and couples the lambda correctly. I can see in cloudwatch that the lambda actually gets fired but the result is always the same: Handler can not be found.
I hope someone can help me out! Thanks in advance :)
Small update on the matter.
As runtime you should use:
runtime: php-82
It seems like it will go a step further then. Only problem after adding this is that I will get the following error:
{
"errorMessage": "app/EventBridgeHandlers/CreateVacancyInCraftHandler/CreateVacancyInCraftHandler",
"errorType": "Illuminate\\Container\\EntryNotFoundException",
"stackTrace": [
"#0 /var/task/vendor/bref/laravel-bridge/src/HandlerResolver.php(46): Illuminate\\Container\\Container->get('app/EventBridge...')",
"#1 /var/task/vendor/bref/bref/src/FunctionRuntime/Main.php(27): Bref\\LaravelBridge\\HandlerResolver->get('app/EventBridge...')",
"#2 /opt/bref/bootstrap.php(17): Bref\\FunctionRuntime\\Main::run()",
"#3 {main}"
]
}
It seems like the entry now cant be found? The App folder is autoloaded and all namespaces is correct. I'm wondering why it can't find the handler.
Regarding the 1st point: runtime: php-82 is the correct configuration, yes. That's something I thought was obvious when writing the docs, but actually isn't at all. This is because the EventBridge docs (like SQS and others) have been split up from a long page that told you to use this runtime. It's not the case anymore, so I understand how confusing this is.
TL/DR: the documentation should be fixed, thank you for the report 👍
Regarding the 2nd issue: App/EventBridgeHandlers/ImportVacanciesFromCluen/ImportVacanciesFromCluenHandler isn't a valid class name. You might want to use \ instead of / as the namespace separator.