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?
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.
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?
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.