mirror of
https://github.com/Sea-Haven-Industries/engineering-handbook.git
synced 2026-10-04 11:22:08 +00:00
Add post-deploy health check template
Template script for project-specific health checks. Copy to scripts/health-check.sh — CD workflows run it automatically.
This commit is contained in:
parent
3aa634c260
commit
1e3c3d1e1a
1 changed files with 50 additions and 0 deletions
50
scripts/health-check-template.sh
Executable file
50
scripts/health-check-template.sh
Executable file
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Post-deploy health check template.
|
||||||
|
# Copy to your project as scripts/health-check.sh and customize.
|
||||||
|
# Called automatically by CD workflows after deploy.
|
||||||
|
# Args: $1 = stack name, $2 = AWS region
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
STACK_NAME="${1:?Stack name required}"
|
||||||
|
REGION="${2:-us-east-1}"
|
||||||
|
|
||||||
|
echo "Running health checks for ${STACK_NAME}..."
|
||||||
|
|
||||||
|
# Example: verify a Lambda function is invocable
|
||||||
|
# FUNCTION_NAME="${STACK_NAME}-process-order"
|
||||||
|
# aws lambda invoke \
|
||||||
|
# --function-name "$FUNCTION_NAME" \
|
||||||
|
# --payload '{"healthCheck": true}' \
|
||||||
|
# --region "$REGION" \
|
||||||
|
# /tmp/health-check-response.json
|
||||||
|
# cat /tmp/health-check-response.json
|
||||||
|
|
||||||
|
# Example: verify an EC2 instance is running
|
||||||
|
# INSTANCE_ID=$(aws cloudformation describe-stacks \
|
||||||
|
# --stack-name "$STACK_NAME" \
|
||||||
|
# --query 'Stacks[0].Outputs[?OutputKey==`InstanceId`].OutputValue' \
|
||||||
|
# --output text --region "$REGION")
|
||||||
|
# STATE=$(aws ec2 describe-instances \
|
||||||
|
# --instance-ids "$INSTANCE_ID" \
|
||||||
|
# --query 'Reservations[0].Instances[0].State.Name' \
|
||||||
|
# --output text --region "$REGION")
|
||||||
|
# if [[ "$STATE" != "running" ]]; then
|
||||||
|
# echo "ERROR: Instance $INSTANCE_ID is $STATE, expected running"
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
# echo "Instance $INSTANCE_ID is running."
|
||||||
|
|
||||||
|
# Example: verify an API Gateway endpoint responds
|
||||||
|
# API_URL=$(aws cloudformation describe-stacks \
|
||||||
|
# --stack-name "$STACK_NAME" \
|
||||||
|
# --query 'Stacks[0].Outputs[?OutputKey==`ApiUrl`].OutputValue' \
|
||||||
|
# --output text --region "$REGION")
|
||||||
|
# HTTP_CODE=$(curl -sf -o /dev/null -w '%{http_code}' "$API_URL/health")
|
||||||
|
# if [[ "$HTTP_CODE" != "200" ]]; then
|
||||||
|
# echo "ERROR: API health endpoint returned $HTTP_CODE"
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
# echo "API endpoint healthy."
|
||||||
|
|
||||||
|
echo "All health checks passed."
|
||||||
Loading…
Add table
Reference in a new issue