Docs says:
By default, the Invoke API assumes RequestResponse invocation type. You can optionally request asynchronous execution by specifying Event as the InvocationType.
So all I can send to my function (python) is InvocationType:Event everywhere:
curl -X POST "https://X.execute-api.us-east-1.amazonaws.com/prod/Y?InvocationType=Event"
-d "InvocationType:Event"
-H "X-Amz-Invocation-Type:Event"(function sleeps 3 seconds then responses)null
But is not Async... docs also says:
When you invoke a Lambda function via the AWS console or over HTTPS using Amazon API Gateway, Lambda always uses the RequestResponse invocation type.
I know that can be possible via aws-CLI, what I dont understand if it is possible to do it from API Gateway endpoint.
Create two Lambdas and in the first use Lambda.Client.invoke with InvocationType=Event in an dedicated ApiGateway request handling Lambda. The second executes the logic you want the ApiGateway request to asynchronously invoke.
Example dedicated ApiGateway Lambda handler:
from __future__ import print_functionimport boto3
import jsondef lambda_handler(event, context):response = client.invoke(FunctionName='<your_long_task_running_function_executer>',InvocationType='Event',Payload=json.dumps(event))return { "result": "OK" }
You would likely want to detect a failure to send the request and other conditions of that sort but as I don't primarily use python, I'll leave that logic up to you.
p.s. note that invoke_async is deprecated
p.p.s. sorry, my account is new and I don't have the rep to add these as a comment: 0. I borrowed from what you answered; 1. you are using a deprecated api; and 2. you ought (clearly it's been fine) to add InvocationType = 'Event'
into your call.