CloudTrail Automation Example

Length: 00:11:10

Lesson Summary:

CloudTrail is very important in the security realm because it records every API call executed on our resources. Making sure that you enable CloudTrail logging is a best security practice. This video is a walkthrough of how to set up automation that starts logging if CloudTrail is stopped.

Lambda function code:

import json
import boto3
import sys

print('Loading function')
""" Function to define Lambda Handler """
def lambda_handler(event, context):
    try:

        client = boto3.client('cloudtrail')
        if event['detail']['eventName'] == 'StopLogging':
            response = client.start_logging(Name=event['detail']['requestParameters']['name'])

    except Exception, e:
        sys.exit();


This lesson is only available to Linux Academy members.

Sign Up To View This Lesson
Or Log In

Looking For Team Training?

Learn More