def sendAnonymousData()

in source/pinpoint-iot-campaign-hook/lambda_function.py [0:0]


def sendAnonymousData():
    logging.debug("Sending Anonymous Data")
    metric_data = {}
    metric_data['MessagesSent'] = 1
    postDict = {}
    postDict['TimeStamp'] = str(datetime.datetime.utcnow().isoformat())
    postDict['Data'] = metric_data
    postDict['Solution'] = os.environ.get('SOLUTION_ID')
    postDict['UUID'] = os.environ.get('SOLUTION_UUID')
    # API Gateway URL to make HTTP POST call
    url = 'https://metrics.awssolutionsbuilder.com/generic'
    data=json.dumps(postDict)
    data_utf8 = data.encode('utf-8')
    logging.debug('sendAnonymousData data: %s', data)
    headers = {
        'content-type': 'application/json; charset=utf-8',
        'content-length': len(data_utf8)
    }
    req = urllib.request.Request(url, data_utf8, headers)
    rsp = urllib.request.urlopen(req)
    rspcode = rsp.getcode()
    content = rsp.read()
    logging.debug("Response from APIGateway: %s, %s", rspcode, content)