Skip to content

Instantly share code, notes, and snippets.

@confickerP
confickerP / gpu_allocation.py
Created July 24, 2021 13:02 — forked from nqbao/gpu_allocation.py
gpu_allocation.py
import os
import logging
import gpustat
logger = logging.getLogger(__name__)
def get_free_gpu_indices():
stats = gpustat.GPUStatCollection.new_query()
used_gpus = set()
@confickerP
confickerP / copy-snapshot.sh
Created July 24, 2021 13:02 — forked from nqbao/copy-snapshot.sh
Copy AMI across accounts
#!/bin/bash
raw=$1
ami_id=$(echo "$raw" | cut -d"," -f1)
image_name=$(echo "$raw" | cut -d"," -f2)
echo "Copying $image_name ($ami_id)"
aws ec2 modify-image-attribute --image-id $ami_id --launch-permission "{\"Add\":[{\"UserId\":\"$TO_ACCOUNT\"}]}" --profile $FROM_PROFILE
aws ec2 copy-image --name "$image_name" --source-image-id $ami_id --source-region $SOURCE_REGION --profile $TO_PROFILE
@confickerP
confickerP / delete_ami.py
Created July 24, 2021 13:01 — forked from nqbao/delete_ami.py
A small python script to wipe out all AMI. Be extremely careful when you run this.
import boto3
ec2 = boto3.client('ec2')
images = ec2.describe_images(Owners=['self'])
for image in images['Images']:
if image['State'] == 'available':
snapshots = image['BlockDeviceMappings']
@confickerP
confickerP / ssm_parameter_store.py
Created July 24, 2021 13:01 — forked from nqbao/ssm_parameter_store.py
Python class to provide a dictionary-like interface to access AWS SSM Parameter Store easily
# Copyright (c) 2018 Bao Nguyen <b@nqbao.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
#!/usr/bin/env python
# grab the first unformatted disk and format it, then label it and update to fstab
# this must be ran as root
import subprocess
import time
import os
import datetime
import sys
@confickerP
confickerP / lambda_s3_event.py
Created July 24, 2021 13:00 — forked from nqbao/lambda_s3_event.py
Snippet to handle s3 events
import boto3
import json
import urllib.parse
import uuid
import os
def lambda_handler(event, context):
sfn = boto3.client('stepfunctions')