Skip to content

Commit

Permalink
Add detailed comments for methods
Browse files Browse the repository at this point in the history
  • Loading branch information
robperc committed Jul 18, 2017
1 parent baafc53 commit 939b792
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import boto3

TOPIC_ARN = os.environ['TOPIC_ARN']
TOPIC_ARN = os.environ['TOPIC_ARN'] # ARN for SNS topic to post message to

TEMPLATE = '''At {} the IAM access key {} for user {} on account {} was deleted after it was found to have been publicly exposed on the internet.
Below are summaries of the most recent actions, resource names, and resource types associated with this user over the last 24 hours.
Expand Down Expand Up @@ -30,7 +30,7 @@ def lambda_handler(event, context):
resource_types = event['resource_types']
subject = 'Security Alert: Exposed IAM Key For User {} On Account {}'.format(username, account_id)
print("Generating message body...")
event_summary = generate_summary_str(event_names)
event_summary = generate_summary_str(event_names)
rname_summary = generate_summary_str(resource_names)
rtype_summary = generate_summary_str(resource_types)
message = TEMPLATE.format(time_discovered,
Expand All @@ -46,10 +46,30 @@ def lambda_handler(event, context):


def generate_summary_str(summary_items):
""" Generates formatted string containing CloudTrail summary info.
Args:
summary_items (list): List of tuples containing CloudTrail summary info.
Returns:
(string)
Formatted string containing CloudTrail summary info.
"""
return '\t' + '\n\t'.join('{}: {}'.format(item[0], item[1]) for item in summary_items)


def publish_msg(subject, message):
""" Publishes message to SNS topic
Args:
subject (string): Subject of message to be published to topic
message (string): Content of message to be published to topic
Returns:
(None)
"""
try:
sns.publish(
TopicArn=TOPIC_ARN,
Expand Down

0 comments on commit 939b792

Please sign in to comment.