# TBI-Websvc-Create-UpdateASG — SSM Automation Runbook

## Overview

SSM Automation document that creates an AMI from the Golden Image server, updates the `tbi-websvc-ext-int` launch template with the new AMI, and initiates a rolling instance refresh on the `tbi-websvc-internal` ASG.

- **Document Name**: `TBI-Websvc-Create-UpdateASG`
- **Version**: 2
- **Region**: ca-central-1
- **AWS Account**: 594765360358 (tbi-dev)

## Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| TargetASG | String | `tbi-websvc-internal` | ASG to update and refresh |

## Resources

| Resource | ID | Notes |
|----------|----|-------|
| Golden Image Instance | `i-03b93ff71964f685c` | Hardcoded source for AMI creation |
| Launch Template | `lt-0148e3a4f1f74192b` (`tbi-websvc-ext-int`) | New version created per run |
| Auto Scaling Group | `tbi-websvc-internal` | Rolling refresh target |

## Steps

### Step 1: CreateAMI
- Creates AMI from Golden Image instance `i-03b93ff71964f685c`
- Image name: `tbi-websvc-<timestamp>`
- `NoReboot: true` — source instance is not disrupted

### Step 2: UpdateLaunchTemplate
- Creates a new version of `tbi-websvc-ext-int` sourced from `$Latest`, overriding only the AMI ID
- Sets the new version as the default on the launch template

### Step 3: StartInstanceRefresh
- Triggers a rolling instance refresh on the target ASG
- **MinHealthyPercentage**: 100 (never drops below full capacity)
- **MaxHealthyPercentage**: 200 (surge — new instances launch before old ones terminate)
- **InstanceWarmup**: 300s (5 minutes before instance is considered healthy)

## How to Run

### CLI
```bash
aws ssm start-automation-execution \
  --document-name TBI-Websvc-Create-UpdateASG \
  --document-version 2 \
  --profile tbi-dev \
  --region ca-central-1
```

### With custom ASG
```bash
aws ssm start-automation-execution \
  --document-name TBI-Websvc-Create-UpdateASG \
  --document-version 2 \
  --parameters '{"TargetASG":["c60-tbi-websvc-qa-staging"]}' \
  --profile tbi-dev \
  --region ca-central-1
```

### Monitor execution
```bash
aws ssm describe-automation-executions \
  --filters Key=DocumentNamePrefix,Values=TBI-Websvc-Create-UpdateASG \
  --profile tbi-dev \
  --region ca-central-1
```

## Version History

| Version | Date | Changes |
|---------|------|---------|
| 1 | 2025-05-05 | Initial — created new launch templates per run, no rolling update |
| 2 | 2026-03-25 | Switched to launch template versioning, added instance refresh with rolling strategy |

---

**Last Updated**: 2026-03-25
