awslabs / aws-lambda-web-adapter

Run web applications on AWS Lambda
Apache License 2.0
1.95k stars 118 forks source link

can't force lambda failure for non http events #537

Open jordandobrev opened 19 hours ago

jordandobrev commented 19 hours ago

Hey guys, I have a trigger setup for kafka events - aws:kafka. When I return any non 200 response back from my \events endpoint it treats the execution as a success. That would prevent the automatic aws retry mechanism to kick in and will result in missed unprocessed messages.

Is there a way to return a response that would result in a lambda failure?

bnusunny commented 14 hours ago

No, returning non 200 response won't cause the Lambda invoke to fail. You need to through an exception to crash the runtime.

jordandobrev commented 9 hours ago

That works thanks! However it was not trivial to make it work with some languages like php with laravel for example. Just throwing an exception will be automatically handled in some cases and converted to a 500 http error. Even if you manage to get the php process to throw the exception anyway and kill the process, it's not the one that runs the environment really as you need an http server. The only way to do that was to locate the main parent process id and to do a pkill on it and wait, as if anything is returned before the parent process is killed it might not fail.

Hopefully there will be sth added in the future to simplify the flow via a response header or/and http status code.

bnusunny commented 4 minutes ago

I got your problem now. We could improve this for non-http event sources.