Skip to content

Instantly share code, notes, and snippets.

View filipeandre's full-sized avatar

Filipe Ferreira filipeandre

View GitHub Profile
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS EU West 1 VPN gateway with connections to Azure.
Parameters:
VpcId:
Type: AWS::EC2::VPC::Id
Description: ID of the existing VPC.
SubnetId:
Type: AWS::EC2::Subnet::Id
@filipeandre
filipeandre / handler.js
Created November 20, 2024 17:47
Lambda used to check connection
const https = require('https');
exports.handler = async (event) => {
const url = '';
const timeout = 4000; // 4 seconds
return new Promise((resolve) => {
const options = {
method: 'GET',
timeout: timeout,
@filipeandre
filipeandre / multiple_domain_redirect_template.yaml
Last active November 19, 2024 13:21
Deploys a solution that redirects multiple domains to a new domain using bucket redirect
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
RedirectDomain:
Type: String
Default: 'https://sapo.pt'
Description: 'The target domain for the redirect.'
DomainsToRedirect:
Type: CommaDelimitedList
@filipeandre
filipeandre / AutoScalingTestStack.ts
Last active November 21, 2024 21:22
Testing managed ec2 auto scaling based on ecs service desired count using CDK
import {DockerImageAsset} from 'aws-cdk-lib/aws-ecr-assets';
import {FoundationApp, FoundationStack, FoundationStackProps} from "@devops/cdk";
import * as cdk from 'aws-cdk-lib';
import * as autoscaling from 'aws-cdk-lib/aws-autoscaling';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
export class AutoScalingTestStack extends FoundationStack {
@filipeandre
filipeandre / search.py
Created November 8, 2024 21:57
Search for word recursively across all pages of a site
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin, urlparse
import re
import time
def is_valid_url(url, base_netloc):
"""
Check if the URL is valid and belongs to the same domain.
"""
@filipeandre
filipeandre / template.yml
Last active November 8, 2024 22:50 — forked from daaru00/template.yml
A SAM template that describe an Amazon CloudFront distribution that serve a static website from an S3 Bucket.
AWSTemplateFormatVersion: 2010-09-09
Description: "Personal Website"
Parameters:
DomainName:
Type: String
Description: "The domain name of website"
BucketName:
Type: String
Description: "The bucket name"
@filipeandre
filipeandre / record_private_ips_alb.py
Created November 7, 2024 10:57
It collects the ELB's private IPs from EC2 network interfaces within a specified VPC. It fetches the existing Route53 records to check for differences. If the IPs have changed, it updates the Route53 A record.
import boto3
import sys
# AWS Configuration
vpc_id = 'your-vpc-id'
elb_network_description = 'Your ELB network interface description (generated like "ELB your-elb-name")'
route53_internal_hosted_zone_id = 'Your Route53 Internal hosted zone ID'
route53_internal_record_name = 'your-route53-record.internal.' # Ending with dot
aws_access_key = 'Your IAM Key'
@filipeandre
filipeandre / migrate_git_submodule_https_ssh.sh
Created August 12, 2024 07:02
Migrate gitmodules from https to ssh
#!/usr/bin/env bash
set -e
git config -f .gitmodules --get-regexp 'submodule\..*\.path' | while read -r key submodule_path; do
http_url=$(git config --file .gitmodules --get submodule.$submodule_path.url)
ssh_url=${http_url/https:\/\/github.com\//[email protected]:}
git config -f .gitmodules submodule.$submodule_path.url $ssh_url
git config -f .gitmodules submodule.$submodule_path.shallow true
echo "Updated $submodule_name ($submodule_path) URL:"
@filipeandre
filipeandre / list_banned_ips.sh
Last active August 5, 2024 11:02
Fail2ban usefull Aliases
sudo zgrep 'Ban' /var/log/fail2ban.log*
@filipeandre
filipeandre / read_gzipped_from_s3.ts
Last active August 1, 2024 11:21
Get a gziped file from s3 to memory
import { createGunzip } from 'node:zlib';
import { text } from 'node:stream/consumers';
import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3';
async function readGzippedFromS3(s3Client: S3Client, bucket: string, objectKey: string): Promise<string> {
const command = new GetObjectCommand({
Bucket: bucket,
Key: objectKey,
});
const response = await s3Client.send(command);