3/30/2022

AWS Lambda invoke example code

 Refer to code

..

import boto3
import botocore
from botocore.exceptions import ClientError
from botocore.config import Config
import json


#params
ACCESS_KEY = 'your_key'
SECRET_KEY = 'your_sec_key'
REGION = 'your_region' #ex) 'eu-west-1'
LAMBDA_ARN = 'your lambda arn' #ex)arn:aws:lambda:eu-west-1:1211:function:functionname'
your_input_value = 'your_input_value'


#define labmda client
lambda_client = boto3.client('lambda',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
region_name = REGION,
config = Config(read_timeout=600))

#invoke
futs = lambda_client.invoke(
FunctionName = LAMBDA_ARN,
InvocationType = "RequestResponse", #event
Payload = json.dumps({'your_input_key': your_input_value})
)

#parsing result
res = futs['Payload'].read().decode()
res_dict = json.loads(res)

#print result as dict
print(res_dict, type(res_dict))

..


www.marearts.com

πŸ™‡πŸ»‍♂️