Skip to content

Instantly share code, notes, and snippets.

@vvalorous
vvalorous / aws-guardduty-lambda-security
Created March 27, 2018 06:41 — forked from reza/aws-guardduty-lambda-security
I have used a lambda function to automatically deactivate any access key associated with a high severity GuardDuty alert.
#!/usr/bin/env python
#developed for blog post at http://www.cloudten.com.au/aws-guardduty-intelligent-threat-detection/
from __future__ import print_function
import boto3
import json
def lambda_handler(event, context):
print("Received event: " + json.dumps(event))
try:
@vvalorous
vvalorous / lambda_template.py
Created March 27, 2018 06:42 — forked from bh1428/lambda_template.py
AWS Lambda function template
#!/usr/bin/env python
"""Describe the function
The following environment variables can be used to steer behavior:
- LOGLEVEL: set the loglevel (INFO when not defined / missing), this
is based on the Python `logging` module
"""
import logging
import os
@vvalorous
vvalorous / lambdaAMIBackups.py
Created March 27, 2018 06:42 — forked from slmingol/lambdaAMIBackups.py
AWS Lambda AMI Backups
# Automated AMI Backups
#
# @author Robert Kozora <[email protected]>
#
# This script will search for all instances having a tag with "Backup" or "backup"
# on it. As soon as we have the instances list, we loop through each instance
# and create an AMI of it. Also, it will look for a "Retention" tag key which
# will be used as a retention policy number in days. If there is no tag with
# that name, it will use a 7 days default value for each AMI.
#
@vvalorous
vvalorous / lambdaAMIBackups.py
Created March 27, 2018 06:45 — forked from bkozora/lambdaAMIBackups.py
AWS Lambda AMI Backups
# Automated AMI Backups
#
# @author Robert Kozora <[email protected]>
#
# This script will search for all instances having a tag with "Backup" or "backup"
# on it. As soon as we have the instances list, we loop through each instance
# and create an AMI of it. Also, it will look for a "Retention" tag key which
# will be used as a retention policy number in days. If there is no tag with
# that name, it will use a 7 days default value for each AMI.
#
@vvalorous
vvalorous / ebs_stats.py
Created March 27, 2018 06:51 — forked from michealtianlan/ebs_stats.py
Get CloudWatch metrics for Amazon EBS volumes
#!/usr/bin/python
#
# Get Cloudwatch metrics for the EBS volumes attached to an instance
#
import datetime
import logging
import sys
import urllib
@vvalorous
vvalorous / lambda-concurrency-to-cloudwatch.py
Created March 27, 2018 06:53 — forked from innovia/lambda-concurrency-to-cloudwatch.py
Lambda concurrent execution custom metric on CloudWatch
#!/usr/bin/env python
import boto3
import datetime
import time
ENABLED_REGIONS = [
"us-east-1",
"us-west-2",
"eu-west-1",
"eu-central-1",
@vvalorous
vvalorous / cloudwatcher.py
Created March 27, 2018 06:53
Lambda Python Code to Monitor CloudWatch Metrics
#!/usr/bin/env python
import boto3
import json
import urllib
import urllib2
from datetime import datetime, timedelta
# #################################################
@vvalorous
vvalorous / stale_security_groups.py
Created March 27, 2018 18:08 — forked from astrikos/stale_security_groups.py
Script to detect stale AWS security groups
#!/usr/bin/env python
import boto3
import argparse
class StaleSGDetector(object):
"""
Class to hold the logic for detecting AWS security groups that are stale.
"""
def __init__(self, **kwargs):
@vvalorous
vvalorous / aws_sg_recipe.py
Created March 27, 2018 18:10 — forked from steder/aws_sg_recipe.py
Create and update AWS security groups using Python and Boto.
#!/usr/bin/env python
"""
Recipe for creating and updating security groups programmatically.
"""
import collections
import boto
@vvalorous
vvalorous / aws_resources.py
Created March 27, 2018 18:11 — forked from babo/aws_resources.py
Skeleton to list all AWS resources by security group.
#!/usr/bin/env python3
import json
import boto3
def main():
all_ec2 = {}
all_rds = {}
all_cache = {}
all_elb = {}