Skip to content

Instantly share code, notes, and snippets.

View filipeandre's full-sized avatar

Filipe Ferreira filipeandre

View GitHub Profile
@filipeandre
filipeandre / test_assume_role_tag_session.py
Created January 21, 2025 16:08
Script used to validate tag session permission
import boto3
from botocore.exceptions import BotoCoreError, ClientError
def assume_role_with_tags(aws_access_key, aws_secret_key, role_arn, session_name, tags):
"""
Assumes an AWS IAM Role with the specified tags.
:param aws_access_key: AWS access key ID
:param aws_secret_key: AWS secret access key
:param role_arn: ARN of the role to assume
@filipeandre
filipeandre / whitelist-role.yaml
Last active January 20, 2025 16:06
Create a role that allows to whitelist an ipset
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
AccountId:
Type: String
Description: The AWS Account ID that can assume this role.
RoleName:
Type: String
Description: The policy name that allows add or remove ips from ipsets
Resources:
@filipeandre
filipeandre / fix-at-least-one-invalid-signature-was-encountered.md
Created January 16, 2025 18:45
At least one invalid signature was encountered docker error

Fix "At least one invalid signature was encountered"

When trying to build a Debian container, I encountered a bunch of errors like this upon running apt update:

W: GPG error: http://deb.debian.org/debian buster InRelease: At least one invalid signature was encountered.
E: The repository 'http://deb.debian.org/debian buster InRelease' is not signed.

The issue seems to be a lack of disk space. This StackOverflow answer was indeed correct: running docker image prune -f and docker container prune -f fixed the problem.

@filipeandre
filipeandre / delete_ecr_matching_a_prefix.sh
Last active January 7, 2025 10:00
For all ECR repositories, delete all images except the 2 newest.
python3 - <<EOF
import boto3
ecr = boto3.client('ecr')
repo_prefix = "dev-"
# Paginate through repositories
paginator = ecr.get_paginator('describe_repositories')
for page in paginator.paginate():
for repo in page['repositories']:
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"