Skip to content

Instantly share code, notes, and snippets.

@aphexlog
aphexlog / generate_image.py
Created June 12, 2025 23:20
A lightweight Python script that uses AWS Bedrock to generate images from text prompts.
#!/usr/bin/env python3
"""
Simple image generator using AWS Bedrock
"""
import argparse
import base64
import io
import json
import os
import boto3
import cv2
import os
import sys
from datetime import datetime
# Get the directory where the script is located
script_dir = os.path.dirname(os.path.abspath(__file__))
# Create data directory if it doesn't exist
@aphexlog
aphexlog / terminal_chat.py
Last active September 19, 2024 19:00
GenAi chatbot (terminal based) that has an audible voice
import json
import boto3
import logging
import pyaudio
from botocore.exceptions import ClientError
from mypy_boto3_bedrock_runtime.client import BedrockRuntimeClient as BedrockClient
from typing import cast
from pydub import AudioSegment
from io import BytesIO
@aphexlog
aphexlog / xls_to_csv.py
Created August 24, 2023 15:21
Convert an Excel file to CSV.
import openpyxl
import csv
workbook = openpyxl.load_workbook("workbook.xlsx")
sheet = workbook.active
with open("workbook.csv", "w", newline="") as csv_file:
csv_writer = csv.writer(csv_file, delimiter=",")
for row in sheet.iter_rows():
csv_writer.writerow([cell.value for cell in row])
@aphexlog
aphexlog / s3_delete_all_objects.py
Created July 16, 2023 21:23
Deletes all objects in an s3 bucket
import boto3
def delete_all_objects(bucket_name):
s3 = boto3.resource('s3')
bucket = s3.Bucket(bucket_name)
bucket.objects.all().delete()
if __name__ == "__main__":
import sys
bucket_name = sys.argv[1] # pass the bucket name as an argument to the script
"""
Purpose: Get instance types for a given region and availability zone
Usage:
- python3 get_instance_types.py --region us-east-1 --availability_zone us-east-1a --instance_type t2.micro
- python3 get_instance_types.py --region us-east-1 --availability_zone us-east-1a --instance_type "t2.*"
- python3 get_instance_types.py --region us-east-1 --availability_zone "*" --instance_type g3.4xlarge
"""
import argparse
import boto3
@aphexlog
aphexlog / extend-ebs.sh
Created August 30, 2021 21:27
Modifies EBS volumes
#!/bin/bash
# Specify the desired volume size in GiB as a command line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}
# Get the ID of the environment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
# Get the ID of the Amazon EBS volume associated with the instance.
VOLUMEID=$(aws ec2 describe-instances \
@aphexlog
aphexlog / buildspec.yml
Created November 9, 2020 18:46
Buildspec template for CloudFormation targets
version: 0.2
env:
variables:
CACHE_CONTROL: "86400"
S3_BUCKET: {-INSERT BUCKET NAME FOR STATIC WEBSITE HERE-}
BUILD_FOLDER: {-INSERT THE NAME OF THE BUILD FOLDER HERE-}
BUILD_ENV: "prod"
phases:
install:
@aphexlog
aphexlog / buildspec.yml
Created November 9, 2020 18:46
buildspec template for npm application
version: 0.1
phases:
install:
commands:
- printenv
- npm install
build:
commands:
- npm run build

Amazon Linux 2, RHEL7, and CentOS 7 (64 bit)

#!/bin/bash
cd /tmp
sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
sudo systemctl enable amazon-ssm-agent
sudo systemctl start amazon-ssm-agent

Amazon Linux, CentOS 6 (64 bit)