Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Create CloudTrailEncryptionEnabled.py
Browse files Browse the repository at this point in the history
  • Loading branch information
austinsonger authored Jun 19, 2024
1 parent 73f1fab commit c4fdd1a
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from aws_cdk import core
import boto3

class CloudTrailInfoRetrievalStack(core.Stack):

def __init__(self, scope: core.Construct, id: str, info_function, **kwargs) -> None:
super().__init__(scope, id, **kwargs)

# Initialize a boto3 session
session = boto3.Session()
cloudtrail_client = session.client('cloudtrail')

# Retrieve information about CloudTrails
trails = cloudtrail_client.describe_trails()['trailList']

# Loop through every CloudTrail and call the info_function
for trail in trails:
trail_name = trail['Name']
info_function(cloudtrail_client, trail_name)

def check_cloudtrail_encryption(cloudtrail_client, trail_name):
trail_status = cloudtrail_client.get_trail_status(Name=trail_name)
encryption_enabled = trail_status.get('CloudTrailEncryptionEnabled', False)
print(f"Trail {trail_name} encryption enabled: {encryption_enabled}")

app = core.App()

# Initialize stack with the encryption check function
CloudTrailInfoRetrievalStack(app, "CloudTrailInfoRetrievalStack", check_cloudtrail_encryption)

app.synth()

0 comments on commit c4fdd1a

Please sign in to comment.