from pandas.io import json import os import hashlib import requests from requests_aws4auth import AWS4Auth import boto3 import logging log = logging.getLogger().getChild("utils.appsync_query") REGION = os.getenv("AWS_REGION", "eu-west-1") PROFILE = os.getenv("PROFILE", 'devel') API_URL_DEVEL = f"https://rqdq6pkcijbrpdqi5egplq4rvu.appsync-api.{REGION}.amazonaws.com/graphql" API_URL_TEST = f"https://bnpdfzkrn5edra4qf4wqec3qcq.appsync-api.{REGION}.amazonaws.com/graphql" API_URL_LIVE = f"https://mm43jchdrjatljpoe3hjvotfjq.appsync-api.{REGION}.amazonaws.com/graphql" profile_api_map = { 'devel': API_URL_DEVEL, 'test': API_URL_TEST, 'live': API_URL_LIVE, 'local': '' } APPSYNC_URL = profile_api_map[PROFILE] if PROFILE in profile_api_map else profile_api_map['devel'] if not APPSYNC_URL: log.warning(f"Appcync subscription notifications disabled for PROFILE='{PROFILE}'") def appsync_query_iam(query, variables=None): if APPSYNC_URL: method = 'POST' headers = {} body_json = {"query": query} if variables is not None: body_json["variables"] = variables session = boto3.session.Session() c = session.get_credentials() body = json.dumps(body_json) auth = AWS4Auth(c.access_key, c.secret_key, REGION, "appsync", session_token=c.token) response = requests.request(method, APPSYNC_URL, auth=auth, data=body, headers=headers) return response else: return None