Skip to content

Instantly share code, notes, and snippets.

@vvalorous
vvalorous / cloudwatch-to-dynamodb.py
Created June 15, 2018 00:02 — forked from kokeshihub/cloudwatch-to-dynamodb.py
Data of CloudWatch (CPUUtilization of EC2) is put in DynamoDB. Please running in AWS Lambda every hour 10 minutes.
from __future__ import print_function
import boto3
import pytz
from datetime import datetime
from dateutil.relativedelta import relativedelta
print('Loading function')
def lambda_handler(event, context):
@vvalorous
vvalorous / shutdown.py
Created June 13, 2018 19:12 — forked from martinrusev/shutdown.py
Nightly EC2 shutdown
import boto3
import logging
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.INFO)
#define the connection
ec2 = boto3.resource('ec2')
@vvalorous
vvalorous / lights
Created June 13, 2018 19:11 — forked from seventhskye/lights
A python script to shutdown amazon instances, and autoscaling groups. Requires a tag called ScheduledUptime=True on resources this script need to apply to.
#!/usr/bin/env python
import sys
import boto3
def main(argv):
ec2 = boto3.resource('ec2')
instances = ec2.instances.all()
elb = boto3.client('elb')
autoscaling = boto3.client('autoscaling')
auto_scaling_groups = autoscaling.describe_auto_scaling_groups()['AutoScalingGroups']
@vvalorous
vvalorous / Shutdown Script
Created June 13, 2018 19:11 — forked from nicam/ Shutdown Script
This Script can be used to start / stop instances on amazon EC2
<?php
require_once 'sdk/sdk.class.php';
$hosts = array(
'linux' => array('id' => 'i-123ee456', 'ip' => '1.2.3.4'),
'windows' => array('id' => 'i-123ee457', 'ip' => '1.2.3.5'),
);
@vvalorous
vvalorous / lambda.py
Created June 13, 2018 19:08 — forked from reedobrien/lambda.py
AWS Lambda job to backup RDS instances
import boto3
import datetime
def lambda_handler(event, context):
print("Connecting to RDS")
client = boto3.client('rds')
print("RDS snapshot backups stated at %s...\n" % datetime.datetime.now())
client.create_db_snapshot(
DBInstanceIdentifier='web-platform-slave',
#Nicked from http://blog.ranman.org/cleaning-up-aws-with-boto3/
import boto3
from datetime import datetime, timedelta
region = "eu-west-1"
cloudwatch = boto3.client("cloudwatch", region_name=region)
today = datetime.now() + timedelta(days=1) # today + 1 because we want all of today
two_weeks = timedelta(days=14)
start_date = today - two_weeks
import json
import urllib, urllib2
SLACK_URL = 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX'
ICON = {
"cloudwatch": {
"OK": ":cloudwatch:",
"ALARM": ":alarm:",
},
console.log('[Amazon CloudWatch Notification]');
/*
configuration for each condition.
add any conditions here
http://docs.aws.amazon.com/macie/latest/userguide/macie-alerts.html
*/
var ALARM_CONFIG = [
{
condition: "INFORMATIONAL",
@vvalorous
vvalorous / monitor_queue.py
Created June 8, 2018 21:28 — forked from kjoconnor/monitor_queue.py
Monitor your SQS queues with boto
from boto.ec2.cloudwatch import CloudWatchConnection
from boto.sqs.connection import SQSConnection
import boto
import sys
from datetime import datetime, timedelta
import locale
from time import sleep
if(len(sys.argv) > 1):
queue_name = sys.argv[1]
@vvalorous
vvalorous / cw_exp.js
Created June 8, 2018 21:25 — forked from fbrnc/cw_exp.js
AWS Lambda function that collects relevant metrics from CloudWatch and pushes them to ElasticSearch
var AWS = require('aws-sdk');
var cloudwatch = new AWS.CloudWatch({ region: 'us-east-1'});
exports.handler = function (event, context) {
var ElasticSearchHost = 'elasticsearch.example:9200';
var Environment = 'int';
var EndTime = new Date;
var StartTime = new Date(EndTime - 15*60*1000);
var Metrics = {