Cloud Engineer Runbook: Updating Production Applications on Auto-Scaled AWS EC2 & Google Cloud Run Fleets

When an application runs behind an AWS Auto Scaling Group (ASG) or a multi-region Google Cloud Run service, manually SSH-ing into individual servers to run `git pull` is a dangerous anti-pattern: the next scale-out event will launch a stale machine image and reintroduce old bugs. As a Senior Cloud Engineer and GCP Engineer, I automate fleet updates using Boto3 / Terraform pipelines and Cloud Build triggers.

1. Automated AWS AMI & Launch Template Promotion with Python (`boto3`)

Below is the production Python pattern for creating a timestamped AMI from a staging/primary builder instance, registering a new Launch Template version, and updating the Auto Scaling Group to use `$Latest` before triggering a blue/green instance refresh:

import uuid
import boto3

ec2 = boto3.client("ec2", region_name="us-east-1")
autoscaling = boto3.client("autoscaling", region_name="us-east-1")

def promote_fleet_release(source_instance_id: str, launch_template_id: str, asg_name: str) -> str:
    image_name = f"prod-app-{uuid.uuid4().hex[:12]}"
    ami_resp = ec2.create_image(
        InstanceId=source_instance_id,
        Name=image_name,
        NoReboot=True,
    )
    image_id = ami_resp["ImageId"]
    waiter = ec2.get_waiter("image_available")
    waiter.wait(ImageIds=[image_id])

    lt_ver = ec2.create_launch_template_version(
        LaunchTemplateId=launch_template_id,
        SourceVersion="$Latest",
        LaunchTemplateData={"ImageId": image_id},
    )
    new_ver = str(lt_ver["LaunchTemplateVersion"]["VersionNumber"])
    ec2.modify_launch_template(
        LaunchTemplateId=launch_template_id,
        DefaultVersion=new_ver,
    )
    autoscaling.update_auto_scaling_group(
        AutoScalingGroupName=asg_name,
        LaunchTemplate={"LaunchTemplateId": launch_template_id, "Version": "$Latest"},
    )
    return image_id

2. Backward-Compatible Schema Migrations Across Rolling Updates

Because old and new instances serve traffic simultaneously during the 150-second target group warmup window, a Senior Backend Engineer and Cloud Engineer never drops or renames a database column in the same release that removes references from application code. Always use the two-step Expand & Contract migration pattern.

3. Related Cloud Engineering Guides


⚡ Hire Aldian Fazrihady — Senior Cloud, GCP, Backend, AI Application & Full Stack Engineer

Need production cloud architecture, GCP/AWS infrastructure, high-throughput backend systems, AI agents, or full stack web engineering? Book a 1-Day Programming Sprint for $100 USD (International Card / Apple Pay) or Rp 1,000,000 (Indonesian QRIS / Bank Virtual Account), or hire directly on Upwork:

Book $100 / Rp 1M 1-Day Sprint → Hire on Upwork (100% Job Success) →


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 25+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs