/ docker / aws / workflow.py
workflow.py
 1  """
 2  Lambda handler for txtai workflows
 3  """
 4  
 5  import json
 6  
 7  from txtai.api import API
 8  
 9  APP = None
10  
11  
12  # pylint: disable=W0603,W0613
13  def handler(event, context):
14      """
15      Runs a workflow using input event parameters.
16  
17      Args:
18          event: input event
19          context: input context
20  
21      Returns:
22          Workflow results
23      """
24  
25      # Create (or get) global app instance
26      global APP
27      APP = APP if APP else API("config.yml")
28  
29      # Get parameters from event body
30      event = json.loads(event["body"])
31  
32      # Run workflow and return results
33      return {"statusCode": 200, "headers": {"Content-Type": "application/json"}, "body": list(APP.workflow(event["name"], event["elements"]))}