Skip to content

Instantly share code, notes, and snippets.

View filipeandre's full-sized avatar

Filipe Ferreira filipeandre

View GitHub Profile
@filipeandre
filipeandre / trigger_update_stack.py
Last active May 9, 2024 12:41
Trigger a stack update changing a single parameters without waiting
#!/usr/bin/env python
import argparse
import boto3
def main():
parser = argparse.ArgumentParser(description='Update AWS CloudFormation stack while overriding a specific parameter.')
parser.add_argument('--region', '-r', required=True, help='AWS region where the stack is located')
parser.add_argument('--stack-name', '-s', required=True, help='Name of the CloudFormation stack')
parser.add_argument('--parameter-key', '-k', default=None, help='Parameter key to override')
parser.add_argument('--parameter-value', '-v', default=None, help='New value for the parameter to override')
@filipeandre
filipeandre / scheduled_suspend_resume_execute.yaml
Last active May 9, 2024 11:35
Deploy Python Lambda that executes a shell command with CloudWatch Event and SNS Notification
AWSTemplateFormatVersion: '2010-09-09'
Description: Deploy Python Lambda with CloudWatch Event and SNS Notification
Parameters:
# Suspend
SuspendCommand:
Type: String
Description: The shell command to run
@filipeandre
filipeandre / .env
Created May 8, 2024 16:50
Test env replacement on docker command
TEST_ENV=1
@filipeandre
filipeandre / pyenv_poetry_nvm.bashrc.sh
Last active May 3, 2024 12:12
After installing nvm, and poetry this code auto loads poetry similarly to the auto load nvm on dir change.
# Ubuntu NVM and Poetry shell integration
export PATH=$HOME/.local/bin:$PATH
cd_poetry() {
poetry_path="$(nvm_find_up pyproject.toml | command tr -d '\n')"
if [[ ! -z "$poetry_path" ]]; then
if ! poetry env info --path &>/dev/null; then
@filipeandre
filipeandre / batch-convert-heic.rb
Created April 13, 2024 10:45 — forked from rietta/batch-convert-heic.rb
Shell script to batch convert HEIC files to jpeg, leaving the original and its converted side by side. Requires Mac OS or Linux, the find command line tool, and ImageMagick
#!/usr/bin/env ruby
require 'shellwords'
files = `find . -iname '*.heic'`.split("\n")
files.each do |original_file|
output_file = original_file.gsub(/\.heic\z/i, ' Converted.jpg')
if File.exist?(output_file)
STDERR.puts "Skipping output #{output_file} exists."
else
@filipeandre
filipeandre / compile_yaml.py
Last active April 12, 2024 09:35
This script updates the yaml files with the python code
#!/usr/bin/env python
"""
This script updates the yaml files with the python code
"""
import os
import re
ZIP_FILE_INDENT_SPACES = 10
@filipeandre
filipeandre / api_gwv2_github_authorizer.py
Last active April 12, 2024 09:17
Api Gateway V2 Github Ip Authorizer
"""
This Lambda function is designed authorize only hooks from GitHub's IP addresses to access the API Gateway endpoint.
"""
import traceback
import urllib.request
import json
from json import JSONDecodeError
from urllib.error import URLError
import ipaddress
# Fetch the IP addresses of GitHub's hooks
@filipeandre
filipeandre / whitelist_waf_v2.py
Last active March 21, 2024 13:58
Simple request to whitelist waf
try:
import requests
import boto3
except ImportError:
import subprocess
subprocess.run(['pip3', 'install', 'boto3', 'requests'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
finally:
import json
import requests
import boto3
@filipeandre
filipeandre / docker-compose.yaml
Last active April 26, 2024 12:06
Proxy to remote ec2
name: pip-remote
# this data volume contains the proxy config
volumes:
data:
node_modules:
pgdata:
services:
@filipeandre
filipeandre / eks-with-docker.yaml
Created December 12, 2023 11:02
Ec2 profile that installs docker on EKS nodes
AWSTemplateFormatVersion: '2010-09-09'
Resources:
EksWithDockerLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateName: EksWithDocker
VersionDescription: Initial version
LaunchTemplateData:
# MetadataOptions: