Skip to content

Instantly share code, notes, and snippets.

@tobywf
tobywf / boto3-gzip.py
Last active October 18, 2023 17:32
GZIP compressing files for S3 uploads with boto3
from io import BytesIO
import gzip
import shutil
def upload_gzipped(bucket, key, fp, compressed_fp=None, content_type='text/plain'):
"""Compress and upload the contents from fp to S3.
If compressed_fp is None, the compression is performed in memory.
"""
@lavie
lavie / replace-asg-instances.sh
Last active August 27, 2018 07:35
Bash script to replace all ASG instances (by flagging them as Unhealthy, ASG does the rest)
#!/bin/bash
# Usage `./replace-asg-instances.sh my-asg-name`
# Will set all instances to Unhealthy, so they are replaced by the ASG.
# Notice this is meant to work with EC2 health-check ASG, not ELB health-checks.
if [[ $1 == "" ]]; then
echo Usage "./replace-asg-instances.sh my-asg-name"
exit 1
fi
@vancluever
vancluever / amifind.sh
Created January 26, 2016 08:05
Find the most recent Ubuntu AMI using aws-cli (or any other AMI for that matter)
#!/bin/sh
# Use AWS CLI to get the most recent version of an AMI that
# matches certain criteria. Has obvious uses. Made possible via
# --query, --output text, and the fact that RFC3339 datetime
# fields are easily sortable.
export AWS_DEFAULT_REGION=us-east-1
aws ec2 describe-images \
@mitchwongho
mitchwongho / Docker
Last active November 29, 2023 06:36
Docker 'run' command to start an interactive BaSH session
# Assuming an Ubuntu Docker image
$ docker run -it <image> /bin/bash