Skip to content

Instantly share code, notes, and snippets.

View filipeandre's full-sized avatar

Filipe Ferreira filipeandre

View GitHub Profile
@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 / install_jupiter_lab.sh
Last active March 10, 2025 20:31
Install Jupiter lab using PIPx
# install pipx
python -m pip install --user pipx
python -m pipx ensurepath
sudo pipx ensurepath --global
# install jupyterlab
pipx install jupyterlab --include-deps
pipx ensurepath
# add common dependencies
@filipeandre
filipeandre / cloudformation-language-extensions-fn-foreach.yaml
Last active March 7, 2025 15:41
Working Alarm template with cloudformation Fn::ForEach
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::LanguageExtensions
Parameters:
AlarmLambdaPairs:
Type: CommaDelimitedList
Description: |
Comma-separated "prefix:lambdaName" pairs. Example: "PrefixA:MyLambdaA,PrefixB:MyLambdaB"
Default: PrefixA:MyLambdaA,PrefixB:MyLambdaB
@filipeandre
filipeandre / sources.md
Last active February 27, 2025 12:13
Prototype of XKS proxy in Node.js that leverages the official Azure SDKs to interact with Azure Key Vault

Sources

AWS KMS Custom Key Store (XKS) Documentation:

The design and endpoint concepts are inspired by AWS’s documentation for creating an external key store. AWS XKS Documentation

Azure Key Vault Keys Documentation:

Details about managing keys and using cryptographic operations with Azure Key Vault Azure Key Vault Keys Overview.

Azure SDK for JavaScript:

@filipeandre
filipeandre / delete_deprecated_lambdas.py
Last active February 19, 2025 11:32
Delete all deprecated lambdas
import boto3
def delete_old_nodejs_lambdas():
client = boto3.client("lambda")
deprecated_runtimes = {"nodejs12.x", "nodejs14.x", "nodejs16.x"}
# Paginate through all Lambda functions
paginator = client.get_paginator("list_functions")
page_iterator = paginator.paginate()
@filipeandre
filipeandre / devops-vpn-tunnel-monitor.yaml
Created February 6, 2025 17:14
Simple cloudformation template no monitor site to site vpn tunnels
AWSTemplateFormatVersion: 2010-09-09
Description: Setup-Monitoring-On-AWS-Site-to-Site-VPN
Parameters:
UniqueName:
Type: String
Description: An unique qualifier
AllowedPattern: ^[\\.\\-_/#A-Za-z0-9]{1,512}
SnsTopicARN:
Type: String
Description: (Required) ARN of your SNS topic
@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']: