def handler()

in lambda/lambda_function_api.py [0:0]


def handler(event, context):
  os.environ["AWS_DATA_PATH"] = os.environ["LAMBDA_TASK_ROOT"]

  client = boto3.client("location")  
  now = datetime.datetime.now().isoformat()
  yesterday = (datetime.datetime.now() - timedelta(1)).isoformat()
  
  try:
    gps_data = client.get_device_position_history(DeviceId=DEVICE_ID, TrackerName=TRACKER_NAME, StartTimeInclusive=yesterday, EndTimeExclusive=now)
    body = gps_data["DevicePositions"]
  except:
    body = ""
    print ("Error getting Device Position History")

  response = {
      "statusCode": 200,
      "body": json.dumps(body, indent=4, sort_keys=True, default=str),
      'headers': {
        'Content-Type': 'application/json',
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Credentials': 'true',
        'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent',
        'Access-Control-Allow-Methods': 'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT',
      },
  }

  return response