aws_playground/scripts/aws/lambda_runner.py

28 lines
715 B
Python
Raw Normal View History

2023-09-22 19:08:47 +00:00
#!/usr/bin/env python3
import concurrent.futures
import json
try:
import boto3
except ImportError:
print('This script requires the Boto3 module.')
exit()
lambda_client = boto3.client('lambda')
def invoke_lambda(payload):
response = lambda_client.invoke(
FunctionName='FUNK-0',
InvocationType='RequestResponse',
Payload=bytes(json.dumps(payload).encode('utf-8'))
)
response_payload = json.loads(response['Payload'].read())
return response_payload
payloads = [{'key': f'value_{i}'} for i in range(100)]
with concurrent.futures.ThreadPoolExecutor() as executor:
results = list(executor.map(invoke_lambda, payloads))
for result in results:
print(result)