Skip to content

Instantly share code, notes, and snippets.

View filipeandre's full-sized avatar

Filipe Ferreira filipeandre

  • 14:33 (UTC +01:00)
View GitHub Profile
@filipeandre
filipeandre / SKILL.md
Created March 16, 2026 10:12
Git Master Skills / Agent
name git-master
description MUST USE for ANY git operations. Atomic commits, rebase/squash, history search (blame, bisect, log -S). Triggers: 'commit', 'rebase', 'squash', 'who wrote', 'when was X added', 'find the commit that'.

Git Master Agent

You are a Git expert combining three specializations:

  1. Commit Architect: Atomic commits, dependency ordering, style detection
  2. Rebase Surgeon: History rewriting, conflict resolution, branch cleanup
@filipeandre
filipeandre / concurrency.py
Last active December 15, 2025 18:00
Force aws limit increase lambda
#!/usr/bin/env python3
import asyncio
import io
import json
import os
import time
import zipfile
import boto3
from botocore.config import Config
@filipeandre
filipeandre / revet_secret.sh
Created March 13, 2025 14:44
Revert aws secret to previous version
#!/bin/bash
set -euo pipefail
# Check for required commands: aws and jq.
command -v aws >/dev/null 2>&1 || { echo "aws CLI is required but not installed. Exiting." >&2; exit 1; }
command -v jq >/dev/null 2>&1 || { echo "jq is required but not installed. Exiting." >&2; exit 1; }
usage() {
cat <<EOF
Usage: $0 [secret_name]
@filipeandre
filipeandre / s3_reencrypt.py
Last active October 16, 2025 14:19
S3 encryption migration tool (SSE-S3 -> SSE-KMS or ensure SSE-KMS)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
S3 encryption migration tool (SSE-S3 -> SSE-KMS or ensure SSE-KMS).
- Generates manifest of current objects with SSE/KMS info + drift status
- Ensures bucket default encryption (optional)
- Re-encrypts objects in place to a target KMS key (idempotent, resumable)
Usage:
@filipeandre
filipeandre / rds_rekey_instance.py
Last active October 14, 2025 15:53
Re-encrypt an Amazon RDS *instance* by snapshot→copy(with KMS)→restore.
#!/usr/bin/env python3
"""
Re-encrypt an Amazon RDS *instance* by snapshot → copy(with KMS) → restore.
Usage:
python rds_rekey_instance.py \
--db-identifier my-db \
--target-kms-key-id arn:aws:kms:us-east-1:123456789012:key/abcd-... \
--region us-east-1 \
[--source-snapshot-id my-existing-snapshot] \
@filipeandre
filipeandre / import_resources.py
Last active October 14, 2025 15:51
Import resources into existing stack
#!/usr/bin/env python3
"""
Create an IMPORT change set while preserving all existing parameters,
with inline resource specs and optional parameter overrides.
Usage examples:
# Single DynamoDB import, keep all parameters as-is
python import_changeset.py \
--stack-name TargetStack \
@filipeandre
filipeandre / aws-waf-add-block-all-rule.py
Last active October 14, 2025 15:40
This script acts as lock down switch for all regional aws waf for current region
#!/usr/bin/env python3
"""
Add a top-priority "block-all" rule to every AWS WAFv2 Web ACL in the current Region (REGIONAL scope),
without removing existing rules. The change is fully reversible via a local backup file.
Features
- Enumerates all REGIONAL Web ACLs in the configured AWS region
- Creates (or reuses) IP sets that match all IPv4 and IPv6 addresses (0.0.0.0/0 and ::/0)
- Inserts a new rule at priority 0 that blocks all traffic, shifting existing rule priorities down
- Stores a per-WebACL backup (original rules + metadata) under ./waf_backups/<region>/<web_acl_id>.json
@filipeandre
filipeandre / extract.js
Last active September 17, 2025 11:01
Extract env variables from ecs task definition
(() => {
// Find the env vars table body via CSS attribute selectors
const tbody = document.querySelector(
'[id^="awsui-tabs-"][id$="-envVariables-panel"] table tbody'
);
if (!tbody) return "";
const rows = Array.from(tbody.querySelectorAll("tr"));
@filipeandre
filipeandre / rollback_s3.sh
Created August 22, 2025 19:36
Restore s3 bucket to previous version before today
#!/usr/bin/env bash
set -euo pipefail
# Restore S3 objects updated today to their most recent version before today (Europe/Lisbon).
# Usage:
# ./restore.sh [--bucket BUCKET] [--yes] [--dry-run]
BUCKET=""
ASSUME_YES="false"
DRY_RUN="false"
@filipeandre
filipeandre / lb_trafic_report.py
Created August 22, 2025 15:17
Trafic report for load balancers
#!/usr/bin/env python3
"""
lb_traffic_report.py (human-friendly)
Enumerate all ALBs, NLBs, and CLBs in the current AWS account & region and fetch key
CloudWatch metrics for a given time window. Outputs a summary table (stdout) and
optionally writes a CSV.
Human-friendly improvements:
- Byte values shown using dynamic units (B/KB/MB/GB/TB) with 2 decimal places.