#!/bin/bash set -e STACK_NAME="StaticSiteSiteStack" REGION="ap-southeast-2" PROFILE="dev" echo "Fetching stack outputs..." OUTPUTS=$(aws cloudformation describe-stacks \ --stack-name "$STACK_NAME" \ --region "$REGION" \ --profile "$PROFILE" \ --query 'Stacks[0].Outputs' \ --output json) # Extract values from outputs BUCKET_NAME=$(echo "$OUTPUTS" | jq -r '.[] | select(.OutputKey=="BucketName") | .OutputValue') DISTRIBUTION_ID=$(echo "$OUTPUTS" | jq -r '.[] | select(.OutputKey=="CloudFrontDistributionId") | .OutputValue') if [ -z "$BUCKET_NAME" ] || [ -z "$DISTRIBUTION_ID" ]; then echo "Error: Could not retrieve stack outputs" echo "BucketName: $BUCKET_NAME" echo "DistributionId: $DISTRIBUTION_ID" exit 1 fi echo "Bucket: $BUCKET_NAME" echo "Distribution ID: $DISTRIBUTION_ID" # Get the .dist directory relative to this script DIST_DIR="$(dirname "$0")/../.dist" if [ ! -d "$DIST_DIR" ]; then echo "Error: .dist directory not found at $DIST_DIR" exit 1 fi echo "Syncing .dist to S3..." aws s3 sync "$DIST_DIR" "s3://$BUCKET_NAME" \ --profile "$PROFILE" \ --delete echo "Invalidating CloudFront cache..." aws cloudfront create-invalidation \ --distribution-id "$DISTRIBUTION_ID" \ --paths "/*" \ --region "$REGION" \ --profile "$PROFILE" echo "Done! Site updated and cache invalidated."