aws_playground

- experiments in aws with terraform
git clone git://git.acid.vegas/aws_playground.git
Log | Files | Refs | Archive | README

lambda_runner.py (715B)

      1 #!/usr/bin/env python3
      2 import concurrent.futures
      3 import json
      4 
      5 try:
      6     import boto3
      7 except ImportError:
      8     print('This script requires the Boto3 module.')
      9     exit()
     10 
     11 lambda_client = boto3.client('lambda')
     12 
     13 def invoke_lambda(payload):
     14     response = lambda_client.invoke(
     15         FunctionName='FUNK-0',
     16         InvocationType='RequestResponse',
     17         Payload=bytes(json.dumps(payload).encode('utf-8'))
     18     )
     19     response_payload = json.loads(response['Payload'].read())
     20     return response_payload
     21 
     22 payloads = [{'key': f'value_{i}'} for i in range(100)]
     23 
     24 with concurrent.futures.ThreadPoolExecutor() as executor:
     25     results = list(executor.map(invoke_lambda, payloads))
     26 
     27 for result in results:
     28     print(result)