Skip to content

Instantly share code, notes, and snippets.

View tdmalone's full-sized avatar

Tim Malone tdmalone

View GitHub Profile
@iann0036
iann0036 / gist:b473bbb3097c5f4c656ed3d07b4d2222
Last active February 28, 2024 19:39
List of expensive / long-term effect AWS IAM actions
route53domains:RegisterDomain
route53domains:RenewDomain
route53domains:TransferDomain
ec2:ModifyReservedInstances
ec2:PurchaseHostReservation
ec2:PurchaseReservedInstancesOffering
ec2:PurchaseScheduledInstances
rds:PurchaseReservedDBInstancesOffering
dynamodb:PurchaseReservedCapacityOfferings
s3:PutObjectRetention
@matthiasr
matthiasr / delete-s3.sh
Created December 14, 2020 09:18
Delete everything in an S3 bucket (in a hurry)
# I needed to delete ~300k objects from an S3 bucket in a hurry. The better and cheaper solution is to use a lifecycle rule, but those can take a day or two to take effect.
bucket="i-want-to-lose-all-my-data"
mkdir -p deletes
# 1. List all the objects in the bucket, transform them 1000 at a time into request objects for DeleteObjects, write each to a separate file
aws s3api list-objects-v2 --bucket "${bucket}" \
| jq -c '.Contents | _nwise(1000) | map({ Key: .Key }) | { Objects: ., Quiet: true }' \
| awk '{ f = "deletes/" NR ".json"; print $0 > f; close(f) }'
package main
import (
"errors"
"fmt"
"io/ioutil"
"log"
"net"
"os"
"os/exec"
@nemani
nemani / download_all_lambda_functions.sh
Last active March 27, 2024 12:10
Download All Lambda Functions
# Parallelly download all aws-lambda functions
# Assumes you have ran `aws configure` and have output-mode as "text"
# Works with "aws-cli/1.16.72 Python/3.6.7 Linux/4.15.0-42-generic botocore/1.12.62"
download_code () {
local OUTPUT=$1
aws lambda get-function --function-name $OUTPUT --query 'Code.Location' | xargs wget -O ./lambda_functions/$OUTPUT.zip
}
mkdir -p lambda_functions
@Deconstrained
Deconstrained / update_ec2_pd_webhook_ip_security_group.py
Last active January 20, 2022 00:20
Updates an EC2 security group with rules to permit connections from PagerDuty IP addresses
#!/usr/bin/env python
import argparse
import logging
import os
import requests
import subprocess
import sys
from boto.ec2 import get_region
kubectl exec --namespace=manadr-dev -it $(kubectl get pod -l "service=mysql" --namespace=manadr-dev -o jsonpath='{.items[0].metadata.name}') -- bash
@matthewpalmer
matthewpalmer / pod.yaml
Last active July 21, 2023 04:54
Example Kubernetes pod for the multi-container sidecar design pattern
# Example YAML configuration for the sidecar pattern.
# It defines a main application container which writes
# the current date to a log file every five seconds.
# The sidecar container is nginx serving that log file.
# (In practice, your sidecar is likely to be a log collection
# container that uploads to external storage.)
# To run:
@fjudith
fjudith / kubernetes_service_session_affinity.md
Last active August 8, 2023 12:43
Enable Session Affinity (a.k.a Sticky Session) to Kubernetes service
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active April 17, 2024 15:52
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@eduardcloud
eduardcloud / LambdaEfsBackup.py
Created September 19, 2017 10:14
Backup EFS file-system to S3 with lambda function
import boto3
import time
region = 'eu-west-1'
user_data_script = """#!/bin/bash
instanceid=$(curl http://169.254.169.254/latest/meta-data/instance-id)
cd /
mkdir moodledata
mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-xxxxxxxxxxc.efs.eu-west-1.amazonaws.com:/ moodledata
tar czf mooodledata-backup-$(date +%d-%m-%Y_%H-%M).tar.gz /moodledata
aws s3 mv mooodledata-backup-*.tar.gz s3://xxxxxxxxx/