Technical insights, code snippets, and quick tips

Reducing Blog Image Load from 20MB to 1.5MB with WebP

Our blog homepage was loading 18-20 MB of images—11 PNG files at 1.4-2.0 MB each. On mobile connections, pages took 60-90 seconds to load.
// Before: Single large PNG for all devices
${post.imageUrl ? `<img src="${escapeHtml(post.imageUrl)}" 
     alt="${escapeHtml(post.title)}" 
     class="post-image">` : ''}

// After: Responsive WebP with PNG fallback
${post.imageUrl ? `<picture>
    <source 
        srcset="${escapeHtml(post.imageUrl.replace('.png', '-800.webp'))} 800w,
                ${escapeHtml(post.imageUrl.replace('.png', '-1200.webp'))} 1200w"
        type="image/webp"
        sizes="(max-width: 768px) 100vw, 600px">
// ...
Read More

Fixing HTTP to HTTPS Redirects in CloudFront

Google Search Console flagged our site with "HTTPS not evaluated" despite using HTTPS everywhere. The issue: HTTP requests weren't redirecting to HTTPS—they served content directly, creating duplicate content and hurting SEO.
# HTTPS works fine
curl -I https://example.com/page.html
# Returns: HTTP/2 200 ✅

# HTTP doesn't redirect (PROBLEM)
curl -I http://example.com/page.html
# Returns: HTTP/1.1 200 ❌
# Should return: HTTP/1.1 301 Moved Permanently
Read More

AWS SAM: Simplified Serverless Deployment

Deploying serverless applications requires coordinating Lambda functions, API Gateway, IAM roles, and environment variables. Manual CloudFormation is verbose and error-prone.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Parameters:
  ToEmail:
    Type: String
    Default: contact@example.com
  RecaptchaSecretKey:
    Type: String
    NoEcho: true

Resources:
// ...
Read More

Lambda + SES: Serverless Contact Form

Contact forms need backend infrastructure to send emails, but managing servers is overkill for occasional submissions. The challenge: build a secure, cost-effective contact form that handles spam and rate limiting.
const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses");
const ses = new SESClient({ region: "us-east-1" });

exports.handler = async (event) => {
  const body = JSON.parse(event.body);
  const { name, email, subject, message, honeypot } = body;
  
  // Honeypot check - bots fill this hidden field
  if (honeypot) {
    return { statusCode: 200, body: JSON.stringify({ message: 'Success' }) };
  }
  
// ...
Read More

Bedrock Image Generation: Custom Blog Images

Blog posts need hero images, but manually creating them is time-consuming and stock photos feel generic. The challenge: generate custom AI images on-demand.
def generate_image(prompt, output_key, local_path=None):
    """Generate image with Bedrock and upload to S3"""
    
    bedrock = boto3.client('bedrock-runtime', region_name='us-east-1')
    
    body = json.dumps({
        "taskType": "TEXT_IMAGE",
        "textToImageParams": {
            "text": prompt
        },
        "imageGenerationConfig": {
            "numberOfImages": 1,
// ...
Read More

S3 Deep Archive: 96% Cost Reduction with Lifecycle Policies

A backup bucket was consuming 44% of monthly AWS costs despite being accessed less than once per year. All 630+ GB sat in S3 Standard storage with no lifecycle policies configured.
{
  "Rules": [
    {
      "ID": "TransitionToDeepArchive",
      "Status": "Enabled",
      "Filter": {},
      "Transitions": [
        {
          "Days": 30,
          "StorageClass": "DEEP_ARCHIVE"
        }
      ]
// ...
Read More

Google Cloud Speech-to-Text: Simpler Than AWS Transcribe

We needed accurate speech transcription for a Flutter mobile app where users record voice memories. The transcription had to be fast, accurate, and cost-effective at scale.
// Load service account credentials
final credentialsJson = await rootBundle.loadString('assets/google-credentials.json');
final credentials = ServiceAccountCredentials.fromJson(json.decode(credentialsJson));
final client = await clientViaServiceAccount(
  credentials, 
  ['https://www.googleapis.com/auth/cloud-platform']
);

// Read and encode audio
final audioBytes = await File(audioFilePath).readAsBytes();
final audioBase64 = base64Encode(audioBytes);

// ...
Read More

AI Story Generation with Google Gemini: 10x Cheaper Than AWS

We needed AI to transform voice transcriptions into narrative stories for a memory preservation app. The challenge: keep costs low while maintaining high-quality storytelling that preserves the user's authentic voice.
final requestBody = {
  'contents': [{
    'role': 'user',
    'parts': [{
      'text': '''You are a compassionate storyteller helping someone preserve their memories.

The user was asked: "$prompt"
They responded: "$transcription"

Transform their response into a beautiful, narrative story in first person. Keep their voice and emotions, but enhance it with vivid details and reflective insights. Make it 2-3 paragraphs.'''
    }]
  }],
// ...
Read More

Optimizing AWS DynamoDB Performance: From Table Scans to GSI Queries

While building a blog API that needed to retrieve the 5 most recent posts, we encountered a classic database performance problem: the inefficient table scan. What started as a simple requirement—"get the last 5 blog posts"—became a practical lesson in understanding data access patterns and the impact of proper database design on both performance and cost.
# BEFORE: Inefficient table scan
response = table.scan(
    FilterExpression=Attr('status').eq('published')
)

posts = []
for item in response['Items']:
    posts.append({
        'id': item['postId'],
        'title': item['title'],
        'content': item['content'],
        'date': item['publishDate']
// ...
Read More