API Usage – Lambda

You will need to create a Lambda function to call our API with alert information.  This function accepts data passed to it by AWS CloudWatch in a specific format and sends it to our API.  Below is sample Python 3.6 code for this, where your API key will need to replace the "XXXXXXX" in the code:

import json
import urllib
from urllib.request import urlopen

def lambda_handler(event, context):
    data = json.dumps(event).encode("utf-8")
    headers = {"Content-Type":"application/x-www-form-urlencoded","x-api-key":"XXXXXXX"}
    url = 'https://api.custodetnimbus.com/v1/alert'
    req = urllib.request.Request(url, headers = headers, method='POST', data=data)
    urllib.request.urlopen(req)

Create the function by logging into your AWS console and selecting "Lambda" (which is under "Compute") in the AWS web console.  From the dashboard select "Create Function", and create a new function with an easy to remember name using the Python 3.6 API.  We suggest the name 'send-alert-to-cloudMonitor-api'.  You can name this function anything you wish, but you will need to remember what name you used when setting up SNS to call the Lambda function you created and call our API.

Please note that when we send you your API key, we will send you the API key embedded in the function shown.