Skip to content

Instantly share code, notes, and snippets.

View toabctl's full-sized avatar

Thomas Bechtold toabctl

  • Canonical
  • Berlin/Germany
View GitHub Profile
@toabctl
toabctl / ssm-images.sh
Created November 22, 2022 10:57
Images from SSM for different regions
#!/bin/bash -eu
# this is 2P Ubuntu Pro Xenial
SSM_ID=prod-f6ogoaqs7lwre/ubuntu-pro-16.04-lts
# get a AMI via SSM from us-east-1
US_EAST_1_AMI=$(aws --region us-east-1 ssm get-parameters --names "/aws/service/marketplace/${SSM_ID}" --query 'Parameters[0].Value' --output text)
echo $US_EAST_1_AMI
# get the AMI name via describe-images
@toabctl
toabctl / aws-snapshots-size.py
Last active December 1, 2022 10:56
Get the total amount of snapshots in GiB
#!/usr/bin/python3
"""
Get the total amount of GiB snapshots use and calculate the average snapshot size
Use eg. with:
AWS_DEFAULT_REGION=sa-east-1 AWS_PROFILE=my-profile ./aws-snapshots-size.py
"""
import boto3
#!/usr/bin/python3
import boto3
ec2res = boto3.resource('ec2')
ec2client = boto3.client('ec2')
region_name = ec2client.meta.region_name
snapshots = ec2res.snapshots.filter(OwnerIds=['self'])
@toabctl
toabctl / aws-marketplace.py
Created February 27, 2023 05:42
AWS Marketplace interactions
#!/usr/bin/env python
import click
import boto3
import json
import prettytable
client = boto3.client('marketplace-catalog', region_name='us-east-1')
@toabctl
toabctl / aws-snapshots-delete.py
Created December 12, 2024 17:57
Delete snapshots in region and account
#!/usr/bin/python3
"""
Delete all snapshots
!!!!!!!!!!!!!!!! BE CAREFUL !!!!!!!!!!!!!!!!!!!!!!!!!
AWS_DEFAULT_REGION=sa-east-1 AWS_PROFILE=my-profile ./aws-snapshots-delete.py
"""
@toabctl
toabctl / aws-images-delete.py
Last active December 12, 2024 17:58
delete images and snapshots
#!/usr/bin/env python3
"""
Delete all snapshots
!!!!!!!!!!!!!!!! BE CAREFUL !!!!!!!!!!!!!!!!!!!!!!!!!
AWS_DEFAULT_REGION=sa-east-1 AWS_PROFILE=my-profile ./aws-snapshots-delete.py
Or to iterate over all regions:
#!/usr/bin/env python3
"""
Helper using awspub to register an image on a single region.
Copyright (C) <2025> <Thomas Bechtold>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as