How to asynchronously call aws lambda function using Python requests

Question:

I know how to invoke AWS lambda function asynchronously using boto3 in python.

Here’s the code I’m using:


import boto3
import json

lambda_client = boto3.client('lambda',
                             region_name='ap-northeast-2',
                             aws_access_key_id='XXXXXXXXXX',
                             aws_secret_access_key='XXXXXXXXXXX')
data = {"data1":"mydata"}

response = lambda_client.invoke(FunctionName="my_lambda_function",
                                InvocationType="Event",         ###for asynchronous purposes
                                Payload=json.dumps(data)
                                )

but I want to invoke lambda asynchronously using requests instead of invoke method

ex):

import requests
param= data = {"data1":"mydata"}
url = "https://xxxxx.execute-api.ap-northeast-2.amazonaws.com/my_lambda_function)"
res = requests.get(url, params=param)

Should I implement the code for asynchronous calls myself? Is there a simple asynchronous way to call lambda requests?

Asked By: 김재영

||

Answers:

You can invoke a Lambda function through an HTTP request in two ways:

Both will expose public HTTP endpoints, which you can call through a normal HTTP request. Beware that anyone on the internet will be able to invoke your function if they have the URL.

If you want the Lambda invocation by API Gateway to be asynchronous, follow these instructions: Set up asynchronous invocation of the backend Lambda function.

Answered By: Renato Byrro
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.