This article is an addition to the CloudWatch Integration Article, and adds steps required only in scenarios in which the CloudWatch logs already trigger some other Lambda (e.g. a Lambda which loads the logs to Elastic). The CloudWatch-to-Lambda streaming mechanism only supports triggering a single Lambda. If you already stream your CloudWatch data to an existing lambda function, follow this guide to configure your existing Lambda to invoke Loom’s lambda by appending a small snippet at the end of the existing Lambda code.

Step 1 - create Loom Lambda

Follow the first step in the CloudWatch Integration Article to create the Loom Lambda.

Step 2 - configuring the existing Lambda to invoke the Loom Lambda

Here's a sample code on how to invoke loom's lambda

import boto3
import json

def handler(event, context):
    invoke_lambda(event, context)

def invoke_lambda(event, context):
    print('Cloudwatch listener.')
    lambda_client = boto3.client(service_name="lambda")

    res = lambda_client.invoke(FunctionName = 'loomCloudWatchListener', InvocationType = 'Event', LogType = 'Tail', Payload = json.dumps(event))
    print res


Update the FunctionName parameter matches the Loom Lambda function name.
You will also need to modify the permissions of the role that runs your existing lambda.
Edit the policy of the rule invoking the existing Lambda and add the InvokeFunction permission as follows: 

{
    "Effect": "Allow",
    "Action": [
        "lambda:InvokeFunction"
    ],
    "Resource": "*"
}

This will allow your code to perform the Lambda invoke operation.

That's it, your existing Lambda function should now forward the CloudWatch log data to the Loom Lambda, which will in turn send it to Loom.
 

Did this answer your question?