Skip to content

Instantly share code, notes, and snippets.

@csereno
csereno / Recover-EC2-CW-Alarm.yaml
Created April 19, 2021 18:25
Cloudformation Templates
# CW Alarm Template
#
# Author: Chris Sereno
# Description: This template creates or adds CW alarms to EC2 Instances and will restart and recover instances.
# There are requirements to instance recovery. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-recover.html
# This is a personal test template and is NOT a vetted or approved template. Use at your own risk.
#
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'CloudWatch Alarms to recover EC2 Template'
@csereno
csereno / FileSearch.ps1
Last active May 29, 2021 22:58
Use Powershell to find a file in a directory from a list of files
$SearchDir = "C:\Source\Dir\"
$Filenames = Get-Content C:\filelist.txt
$Pics = Get-ChildItem -Path $SearchDir -File -Recurse
foreach ($File in $Filenames) {
$File = ($File.split('\')[-1]) #Gets just the file name
if(Get-Childitem -Path $SearchDir -Include $File -File -Recurse -ErrorAction SilentlyContinue) {
echo File Found: $File
}else{
echo Not Found: $File >> C:\NotFoundLog.txt
@csereno
csereno / AWSSubnetCIDR.yaml
Created June 17, 2020 04:01
Specifying the CIDR for an AWS subnet with an allowed pattern
SubnetCIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.0.0/20
Description: CIDR block for subnet
Type: String
@csereno
csereno / rclone.conf
Last active January 25, 2022 15:27
~/.config/rclone/rclone.conf file demonstrating configurations for Wasabi, Google, and AWS S3
# For more details see https://rclone.org/s3/
[wasabi]
type = s3
provider = Wasabi
access_key_id = xxxxx
secret_access_key = xxx
region = us-east-1
endpoint = s3.wasabisys.com
@csereno
csereno / rclone-unifi.service
Created November 3, 2019 22:18
SystemCtl Service file using RClone to S3 for Unifi Video
# /etc/systemd/system/rclone-unifi.service
[Unit]
Description=Unifi S3 Sync (rclone)
Wants=network-online.target
After=network-online.target
[Service]
Type=notify
User=unifi-video
Group=unifi-video
@csereno
csereno / secure-headers.js
Last active October 23, 2019 14:20
Add secure headers to static page through CloudFront
# Source: https://aws.amazon.com/blogs/networking-and-content-delivery/adding-http-security-headers-using-lambdaedge-and-amazon-cloudfront/
'use strict';
exports.handler = async (event, context, callback) => {
const response = event.Records[0].cf.response;
const headers = response.headers;
//Set new headers
headers['strict-transport-security'] = [{key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubdomains; preload'}];
headers['content-security-policy'] = [{key: 'Content-Security-Policy', value: "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'"}];
@csereno
csereno / keybase.md
Created September 20, 2019 03:11
proving keybase identity

Keybase proof

I hereby claim: * I am csereno on github. * I am csereno (https://keybase.io/csereno) on keybase. * I have a public key ASDM--9IKfrC1z0VN8aIh2vvEtrCMq-SfJm1EyzlinIxbQo To claim this, I am signing this object:

{   "body": {     "key": {       "eldest_kid": "0120ccfbef4829fac2d73d1537c688876bef12dac232af927c99b5132ce58a72316d0a",       "host": "keybase.io",       "kid": "0120ccfbef4829fac2d73d1537c688876bef12dac232af927c99b5132ce58a72316d0a",       "uid": "e618dbcce09215c6f5fa8c5104f44e19",       "username": "csereno"     },     "merkle_root": {       "ctime": 1568948993,       "hash": "6bd244737d6b82979cd5adc287be5b623fa90beda43d1c5555ead9eb177d73134fcf88fb743c6262de6b4bb04cf50f01aefd64998806cf6f774c2c4069a01f5e",       "hash_meta": "983886bef1e821df6c66edd4fbadefd7eccbe10a9017642452d809a02a78cf2c",       "seqno": 7626147     },     "service": {       "entropy": "NilApc9vJQeeUjBxjHAwO9kY",       "name": "github",       "username": "csereno"     },     "type": "web_service_bi
@csereno
csereno / Clear_CloudFlare_Cache.py
Last active September 18, 2019 18:02
Clear CloudFlare Cache with Lambda
###############
# Purges all cache in CloudFlare from AWS Lambda
# I use this script when GitHub pushes new content to my S3 bucket
# Requirements:
# * CloudFlare API Global Key saved in the Parameter Store as 'CloudFlare'
# * Environment variables:
# ** 'email' as your CloudFlare email to use
# ** 'cf_api' as your CloudFlare API URL
# ** 'topic' as your SNS topic to send notifications
# CloudFlare Doc: https://api.cloudflare.com/#zone-purge-all-files
@csereno
csereno / CW_Log_Metric_Filter_VPC_Flowlogs.md
Created February 1, 2019 22:50
CloudWatch Parse for VPC Flow Logs

metric filter syntax

[version, account, eni, source, destination, srcport, destport="22", protocol="6", packets, bytes, windowstart, windowend, action="REJECT", flowlogstatus]
@csereno
csereno / CloudWatch_Alarms_CLI_Commands
Last active July 30, 2023 19:44
AWS CloudWatch EC2 Alarms
Reference: https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/put-metric-alarm.html
===HIGH CPU===
aws cloudwatch put-metric-alarm --alarm-name "High CPU Util on INSTANCE" --alarm-description "Alarm when CPU exceeds 90 percent" --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 300 --threshold 90 --comparison-operator GreaterThanThreshold --dimensions "Name=InstanceId,Value=INSTANCE" --evaluation-periods 2 --alarm-actions "arn:aws:sns:REGION:ACCOUNT:SNSTOPIC" --unit Percent
===HIGH MEM===
aws cloudwatch put-metric-alarm --alarm-name "High Memory Util on INSTANCE" --alarm-description "Alarm when Memory exceeds 90 percent" --metric-name mem_used_percent --namespace AWS/EC2 --statistic Average --period 300 --threshold 90 --comparison-operator GreaterThanThreshold --dimensions "Name=InstanceId,Value=INSTANCEID" --evaluation-periods 2 --alarm-actions "arn:aws:sns:REGION:ACCOUNT:SNSTOPIC" --unit Percent
===StatusCheckFailed===
aws cloudwatch put-metric-alarm --alarm-name "EC