Skip to content

Instantly share code, notes, and snippets.

@mlapida
mlapida / ParticleWebook.json
Created February 26, 2016 18:00
A webhook to be used with a Particle Photon
{
"event": "sendSleep",
"url": "https://[yourendpoint].execute-api.us-east-1.amazonaws.com/prod/ParticleSleepV1",
"requestType": "Post",
"headers": {
"x-api-key" : "[yourapikey]"
},
"json": {
"name": "{{SPARK_EVENT_NAME}}",
"data": "{{SPARK_EVENT_VALUE}}",
@mlapida
mlapida / FlowLogs-to-S3-Lambda.py
Last active April 15, 2021 05:39
A Lambda Function for streaming and translating flow logs on the fly. This example was used for HP ArcSight. A full writeup can be found on my site http://mlapida.com/thoughts/exporting-cloudwatch-logs-to-s3-lambda
import boto3
import logging
import json
import gzip
import urllib
import time
from StringIO import StringIO
logger = logging.getLogger()
logger.setLevel(logging.INFO)
@mlapida
mlapida / EBS-Orphaned-Report-Lambda.py
Last active April 29, 2022 08:10
Generate a report of orphaned EBS volumes and send an SNS. A full writeup can be found on my site http://mlapida.com/thoughts/lambda-tracking-orphaned-ebs-volumes
import boto3
import logging
from datetime import *
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.WARNING)
#define the connection
ec2 = boto3.resource('ec2', region_name="us-west-2")
@mlapida
mlapida / EC2-Snapshot-Lambda.py
Last active April 29, 2022 08:10
A lambda function for taking a snapshot of all EC2 instances in a region and cleaning the snapshots up after a set number of days. This ones now works best in conjunction with Asset Tagging https://gist.github.com/mlapida/931c03cce1e9e43f147b A full write up can be found on my site https://empty.coffee/tagging-and-snapshotting-with-lambda/
import boto3
import logging
import datetime
import re
import time
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.ERROR)
@mlapida
mlapida / tootstats.py
Created January 10, 2023 05:35
A small python script that will publish some basic local stats to Mastodon (or GoToSocial). Can be put on a cron to do so regularly.
import requests
import psutil
import time
# A small function to calculate updtime.
def seconds_elapsed():
return time.time() - psutil.boot_time()
requests.post(
@mlapida
mlapida / EC2-Stopped-Tagged-Lambda.py
Last active January 30, 2023 15:09
Using a lambda function, stop all instances that are tagged appropriately.
import boto3
import logging
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.INFO)
#define the connection
ec2 = boto3.resource('ec2')
@mlapida
mlapida / EC2-Tag-Assets-Lambda.py
Last active January 17, 2024 08:10
A lambda function that will copy EC2 tags to all related Volumes and Network Interfaces. A full writeup can be found on my site https://empty.coffee/tagging-and-snapshotting-with-lambda/ - Thank you to the community for keeping this updated!
from __future__ import print_function
import json
import boto3
import logging
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.ERROR)