Skip to content

Instantly share code, notes, and snippets.

View filipeandre's full-sized avatar

Filipe Ferreira filipeandre

  • 14:16 (UTC +01:00)
View GitHub Profile
@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 / update-cdn.sh
Created April 24, 2023 09:46 — forked from rojenzaman/update-cdn.sh
firewalld rules for cloudflare cdn IPs (Red Hat, CentOS, Fedora)
#!/bin/bash
curl https://www.cloudflare.com/ips-v4 > .ips-v4
curl https://www.cloudflare.com/ips-v6 > .ips-v6
firewall-cmd --new-zone=cloudflare --permanent
firewall-cmd --reload
for i in `<.ips-v4`; do firewall-cmd --zone=cloudflare --add-source=$i; done
for i in `<.ips-v6`; do firewall-cmd --zone=cloudflare --add-source=$i; done
@filipeandre
filipeandre / certificate.yml
Last active July 30, 2024 10:46 — forked from techthoughts2/route53.yml
Creates an Amazon Route 53 hosted zone and a certificate *.hz that is automaticaly validated
AWSTemplateFormatVersion: '2010-09-09'
Description: >
This CloudFormation template validates ACM certificate using AWS Route53 DNS
service.
Parameters:
HostedZoneName:
Type: String
Description: The DNS name of an Amazon Route 53 hosted zone e.g. enterprise.filipeandre.com
AllowedPattern: (?!-)[a-zA-Z0-9-.]{1,63}(?<!-)
@filipeandre
filipeandre / Cfn-Stack.yml
Created March 15, 2023 22:06 — forked from atheiman/Cfn-Stack.yml
Run command across accounts and regions with SSM
AWSTemplateFormatVersion: '2010-09-09'
Description: >
SSM Automation Document run a custom SSM Command Document
against a fleet of target instances.
Parameters:
AutomationDocumentName:
Type: String
Description: Name of created SSM Automation Document
Default: MyAutomation
@filipeandre
filipeandre / aws-cli-commands.sh
Created March 15, 2023 20:15 — forked from abiydv/aws-cli-commands.sh
Useful aws cli commands (and errors)
# List all AWS Org accounts' Id, Name, and Email in a csv format
aws organizations list-accounts --query 'Accounts[].[Id,Name,Email,Status]' | jq -r '["id","name","email","status"], (.[]) | @csv'
# Find all EKS clusters in AWS Org
aws configservice list-aggregate-discovered-resources --resource-type "AWS::EKS::Cluster" --configuration-aggregator-name "aws-config-aggregator-name" --no-paginate --output text
# Find all EKS cluster AWS Org with name like name_pattern
# and only display the source account id, the cluster name, and the cluster region
aws configservice list-aggregate-discovered-resources --resource-type "AWS::EKS::Cluster" --configuration-aggregator-name "aws-config-aggregator-name" --no-paginate --query 'ResourceIdentifiers[?contains(ResourceName,`name_pattern`)].[SourceAccountId,ResourceName,SourceRegion]' --output text
@filipeandre
filipeandre / cdk-package.ts
Created January 20, 2023 18:10 — forked from ottokruse/cdk-package.ts
Script to publish CDK assets (e.g. Lambda function code) to S3 and generate parameter files, so you can combine cdk synth with CloudFormation deployments. This is essentially the equivalent of 'sam package' but then for CDK. Tested to work for Lambda and S3-deployments
#!/usr/bin/env ts-node
// This script uploads your assets to the CDK staging bucket in S3 (just as cdk deploy would)
// and writes out two files:
// - parameters.ini to use in CLI deployments (see instructions below)
// - parameters.json to use in AWS CodePipeline for CloudFormation deployments
//
// Installation instructions:
// - Save this script cdk-package.ts to the root of your CDK repo (i.e. next to cdk.json) and make it executable
// - Install script dependencies: npm install jsonpath aws-sdk adm-zip @types/jsonpath @types/adm-zip
@filipeandre
filipeandre / s3_utils.py
Created January 7, 2023 14:26 — forked from nackjicholson/s3_utils.py
s3 list paginator tricks.
import boto3
s3_client = boto3.client('s3')
def list_dirs(bucket, prefix):
""" Yield direct child folders of the given prefix.
"""
@filipeandre
filipeandre / net_interfaces_cleanup.py
Created October 12, 2022 09:18 — forked from revolutionisme/net_interfaces_cleanup.py
Remove Network interfaces created by AWS Lambda while undeploying stack
import boto3
from botocore.exceptions import ClientError
from time import sleep
# Fix this wherever your custom resource handler code is
from common import cfn_custom_resources as csr
import sys
MAX_RETRIES = 3
client = boto3.client('ec2')
@filipeandre
filipeandre / get-ec2.yaml
Created October 11, 2022 18:08 — forked from JAMSUPREME/get-ec2.yaml
SSM Automation
description: |-
### EC2 stopper by tag
Stop EC2 instances by tag
schemaVersion: '0.3'
mainSteps:
- name: getInstancesByTag
action: 'aws:executeAwsApi'
outputs:
- Name: InstanceIds
import boto3
ecs = boto3.client('ecs')
ssm = boto3.client('ssm')
cluster_name = “sample-cluster”
service_name = “sample-service”
# To stop the tasks
response = ecs.describe_services(
cluster=cluster_name,