Skip to content

deeheber/weather-site

Repository files navigation

🌦️ Weather Site

πŸ“– Description

Inspired by isitsnowinginpdx.com ❄️
See blog post for more details πŸ“

A serverless weather reporting website that answers a single question: "Is it [condition] in [location]?" with a simple YES/NO response 🎯

This automated workflow:

  1. πŸ“ Gets the current website status for a specified location
  2. 🌀️ Hits the OpenWeatherMap API to get current weather conditions
  3. πŸ”„ If the status has changed β†’ updates the website with new weather conditions
  4. ⏰ Runs automatically on a schedule via EventBridge Scheduler

My deployment of this site is here πŸš€

πŸ”΄ When the weather is happening (YES!):

Screenshot 2023-03-24 at 8 59 11 AM

🟒 When the weather is NOT happening (Nope!):

Screenshot 2023-03-24 at 8 58 11 AM

πŸ—οΈ Architecture

🎯 Core Stack (Always Required)

  • πŸͺ£ S3 - Static website hosting
  • 🌐 CloudFront - Global CDN distribution
  • ⚑ Lambda - HTML generation and site updates (ARM64)
  • πŸ”„ Step Functions - Orchestrates weather checks and updates
  • ⏰ EventBridge Scheduler - Triggers checks every 10 minutes
  • πŸ“Š Systems Manager Parameter Store - Stores current site status
  • πŸ” Secrets Manager - Stores OpenWeatherMap API key

🌍 Optional Custom Domain Stack

  • 🌐 Route53 - DNS hosted zone management
  • πŸ”’ Certificate Manager - SSL certificates for HTTPS
  • ↩️ CloudFront Function - www β†’ non-www redirects

πŸ“ˆ Optional Monitoring Stack

  • πŸ‘€ CloudWatch - Alarms for Step Function failures
  • πŸ“§ SNS - Email notifications

πŸ› οΈ Technologies

πŸ”„ Step Function State Machine

Screenshot 2025-07-01 at 09 24 30

πŸš€ Deployment Options

🎯 Basic Deployment (CloudFront Default Domain)

Works out of the box with a CloudFront-generated domain (e.g., d123456789.cloudfront.net) ✨

🌍 Custom Domain Deployment

Requires additional domain stack deployed to us-east-1 region for SSL certificates πŸ”’

πŸ“‹ Setup Instructions

βœ… Prerequisites

  1. 🟒 Install Node.js (see .nvmrc for required version)
  2. ☁️ Install AWS CLI and configure credentials
  3. πŸ”‘ Get an API key from OpenWeatherMap

πŸ› οΈ Basic Setup

  1. πŸ“₯ Clone the repository

  2. πŸ” Create a Secret in AWS Secrets Manager:

    • Name: weather-site-api-key
    • Value: Your OpenWeatherMap API key (plaintext)
  3. βš™οΈ Copy .env.example to .env and configure:

    cp .env.example .env
    • Set required variables: WEATHER_LOCATION_LAT, WEATHER_LOCATION_LON, LOCATION_NAME, etc.
    • Optionally set ALERT_EMAIL for failure notifications πŸ“§
    • Leave DOMAIN_NAME empty for basic deployment
  4. πŸ“¦ Install dependencies:

    npm install
  5. πŸ‘€ Set AWS profile (optional):

    export AWS_PROFILE=<your_aws_profile>

πŸš€ Deployment Commands

🎯 Basic Deployment (No Custom Domain)

npm run deploy

The CloudFront URL will be output to the console πŸ“‹

🌍 Custom Domain Deployment

⚠️ Important: Domain stack must be deployed to us-east-1 region first!

  1. πŸ“ Set DOMAIN_NAME in your .env file
  2. 🌐 Deploy domain stack to us-east-1:
    npm run deploy -- --region us-east-1 --exclusively "*-domain"
  3. ☁️ Deploy weather stack to your preferred region:
    npm run deploy -- --region us-west-2 --exclusively "*-weather"
  4. πŸ“Š Optionally deploy alert stack:
    npm run deploy -- --region us-west-2 --exclusively "*-alert"

🌍 Custom Domain Setup

🌐 DNS Requirements

  • If your domain is not hosted in Route53, point your nameservers to Route53 (instructions) πŸ”„
  • For non-Route53 domains: Update nameservers quickly after domain stack deployment starts to prevent certificate validation failures ⚑

πŸ—ΊοΈ Regional Requirements

  • 🌐 Domain Stack: Must deploy to us-east-1 (CloudFront SSL certificate requirement) πŸ”’
  • ☁️ Weather Stack: Can deploy to any AWS region 🌎
  • πŸ“Š Alert Stack: Deploy to same region as weather stack πŸ“

🎁 What Gets Created

  • 🌐 Route53 hosted zone for your domain
  • πŸ”’ SSL certificates for both example.com and www.example.com
  • ☁️ CloudFront distribution with custom domain
  • ↩️ Automatic www β†’ non-www redirect
  • πŸ“ DNS A records pointing to CloudFront

⏱️ Certificate Validation

  • πŸ• DNS validation can take up to 30 minutes
  • πŸ‘€ Monitor AWS Console for certificate status
  • ⚑ Ensure nameservers are updated promptly for external domains

🌎 Multi-Region Deployment Pattern

# Step 1: 🌐 Deploy domain resources (us-east-1 required)
npm run deploy -- --region us-east-1 --exclusively "myStack-domain"

# Step 2: ☁️ Deploy main application (any region)
npm run deploy -- --region us-west-2 --exclusively "myStack-weather"

# Step 3: πŸ“Š Optional monitoring (same region as weather)
npm run deploy -- --region us-west-2 --exclusively "myStack-alert"

πŸ‘¨β€πŸ’» Development

πŸ› οΈ Available Commands

npm run build          # πŸ”¨ Compile TypeScript
npm run test           # πŸ§ͺ Run Jest tests
npm run format         # ✨ Format code with Prettier
npm run lint           # πŸ” Lint code with ESLint
npm run synth          # πŸ“„ Generate CloudFormation templates
npm run diff           # πŸ‘€ Preview infrastructure changes
npm run deploy         # πŸš€ Interactive deployment
npm run deploy:ci      # πŸ€– CI/CD deployment (no prompts)
npm run destroy        # πŸ’₯ Delete all stacks

βš™οΈ Environment Variables

Configure in .env file:

  • πŸ“ WEATHER_LOCATION_LAT / WEATHER_LOCATION_LON - Coordinates for weather checks
  • 🏷️ LOCATION_NAME - Display name for the location
  • 🌦️ WEATHER_TYPE - Condition to check (snow, rain, etc.)
  • ⏰ SCHEDULES - Cron expressions for check frequency
  • 🏷️ STACK_PREFIX - Prefix for all AWS resources
  • 🌐 DOMAIN_NAME - Optional custom domain
  • πŸ“§ ALERT_EMAIL - Optional email for failure notifications

πŸ§ͺ Testing

Basic CDK snapshot tests are in the test/ folder:

npm run test

🧹 Cleanup

To delete all resources:

npm run destroy

πŸ—‘οΈ Manually delete the weather-site-api-key secret from AWS Secrets Manager.

🀝 Contributing

See CONTRIBUTING.md for more info on our guidelines.