title: AWS async system with Python
body: <p>I am trying to create a async system on AWS that should have the following workflow:</p>
  <ul>
  <li>The gateway lambda (<em>invoker</em>) receives a POST request to query some data from the client.</li>
  <li>It then checks the request. If valid, send the request to the main lambda function (<em>data parsing</em>), and return 200OK to the client.</li>
  <li>The <em>data parsing</em> function returns the results in a JSON file to the <em>invoker</em>. It then fowards that very JSON file to another API for data storage.</li>
  </ul>
  <p>The system has been operating fine in sync mode. But when I switch to async, lots of problems occured.</p>
  <ul>
  <li>The <em>invoker</em> successfully invoked the <em>data parsing</em> function, but it cannot receive the JSON response from that very function.</li>
  <li>In case of success, I also have no idea how to forward the received JSON file to the needed API.</li>
  <li>There is a lot of optimization problems along the way.</li>
  </ul>
  <p>Here is my shitcode in the <em>invoker</em> function:</p>
  <pre><code>import json
  import requests
  import boto3
   
  # Define the client to interact with AWS Lambda
  client = boto3.client('lambda')
   
  def lambda_handler(event,context):
      if 'statusCode' in event:
          # Upon receiving JSON data
          # Making a PUT request
          link = 'This is the link of the API'
          r = requests.put(link, data=event)
      else:
          # Upon receiving a POST request
          response = client.invoke(
              FunctionName = 'The name of the data parsing function',
              InvocationType = 'Event',
              Payload = json.dumps(event)
          )
      return {'statusCode': 200}
  </code></pre>
  <p>Here is some piece of codes in the <em>data parsing</em> function</p>
  <pre><code>import json
  import boto3
  import time
  
  lam = boto3.client('lambda')
  
  def lambda_handler(event,context):
      # Some queries stuffs, please don't mind
  
      #3. Construct http response object
      responseObject = {}
      responseObject['statusCode'] = 200
      responseObject['headers'] = {}
      responseObject['headers']['Content-Type'] = 'application/json'
      responseObject['body'] = Output
      
      #4. Return the response object
      response = lam.invoke(
          FunctionName = 'Name of the invoker function',
          InvocationType = 'RequestResponse',
      return responseObject
  </code></pre>
  <p>Please note that all the AWS and async concepts is very new to me, as I am only an intern. What can I do now to resolve my problems? Thank you.</p>
  <p>P/s: To clarify my question, what I need to run asynchronously is the <em>invoker</em> function. Meaning, the client sends a request, then receives a 200OK response; meanwhile my <em>data parsing</em> function processes the query and send the requested data to another API.</p>