Is there a way for a lambda function to know if it was invoked synchronously or async

Hello everyone… :wave:

Quick question here… Is there a way for a lambda function to know if it was invoked synchronously (RequestResponse) or async (Event) inside the lambda code?

Thanks

You could possibly rely on the ClientContext object in the context object passed to the handler.

You can invoke a function synchronously (and wait for the response), or asynchronously. By default, Lambda invokes your function synchronously (i.e. theInvocationType is RequestResponse). To invoke a function asynchronously, set InvocationType to Event. Lambda passes the ClientContext object to your function for synchronous invocations only.

Lack of a client context could mean it’s async, but I’m not sure how reliable that is.

https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html

I have a little code that looks at the shape of the request and can discern between the different event types I support (API Gateway, SNS, SQS)

is that code public? :grin: :crossed_fingers: