Skip to main content

Polo Legacy — Deploy & Test Strategy

Development

Local Dev Server

python run.py # or: inv run
  • Flask app on port 2200 with LiveReload
  • Watches src/* for changes, auto-restarts on crash (5s backoff)
  • Sets ENV=dev, USE_LOCAL_DATA=true
  • Uses LocalDataService (reads local_data.json instead of DynamoDB)
  • Converts Lambda event/context into Flask request objects

Tailwind CSS

inv tailwind # one-shot compile
inv tailwind --watch # watch mode

Output: src/static/dist/main.css

Syncing Local Data

inv sync # all resources, all profiles
inv sync -r instances # single resource type
inv sync -p prod,staging # specific AWS profiles

Requires AWS CLI profile "polo" configured. Writes per-type JSON files, then combine() merges into local_data.json for the dev server.

Build

Lambda Package

inv zip # creates lambda_deployment.zip with deps
inv build # SAM build
inv build -p polo # with specific AWS profile

SAM Template (template.yaml)

  • Runtime: Python 3.12
  • Memory: 256 MB
  • Timeout: 30 seconds
  • Layers: AWS Lambda Powertools v2
  • Functions:
    • PoloFunctionlambda_function.lambda_handler (API routes)
    • StaticFunctionlambda_static.lambda_handler (/static files)
  • API Events:
    • /{proxy+} ANY → PoloFunction
    • / ANY → PoloFunction

Deploy

CDK Deployment

inv bootstrap -p polo # CDK bootstrap (first time)
inv deploy -p polo -e prod # deploy to production
inv deploy -p polo -e prod -s PoloStack # specific stack
inv deploy -p polo -e prod --exclusively # only named stack
inv destroy -p polo -e prod # tear down
inv destroy -p polo -e prod --force # skip confirmation

CDK apps defined in:

  • infra/app.py — main application stack
  • infra/ci.py — CI/CD pipeline
  • infra/destination.py — cross-account destination

Environment Variables (Production Lambda)

Required:

VariableValue
ENVprod
AWS_REGIONus-east-1
DYNAMODB_TABLE_NAMEprod-ResourceTable
DYNAMODB_REPORT_TABLE_NAMEprod-ReportTable
POWERTOOLS_SERVICE_NAMEpolo
POWERTOOLS_METRICS_NAMESPACEPolo
LOGOUT_URL/auth/logout

Optional:

VariablePurpose
USE_LOCAL_DATAtrue for dev mode
SLACK_WEBHOOK_URLCloud Cop Slack notifications
DATA_BUCKET_NAMES3 bucket for sync data
CORE_ACCOUNT_IDCross-account cost data
CORE_ROLE_ARNCross-account role assumption

Testing

Configuration

pytest.ini / conftest.py:

  • Auto-mocks os.environ (function scope) with:
    • LOGOUT_URL=/auth/logout
    • DATA_BUCKET_NAME=test-data
    • USE_LOCAL_DATA=1

Test Commands

inv test # all tests
inv test --local # local tests only (no AWS)
inv test --integration # integration tests (requires AWS)
inv test --watch # watch mode (pytest-watch)
inv test --coverage # with coverage report
inv test --report # HTML coverage report
inv test --fail-under 80 # minimum coverage threshold

Test Stack

ToolPurpose
pytestTest runner
motoAWS service mocking (DynamoDB, S3, EC2, etc.)
freezegunTime freezing for date-dependent tests
pytest-coverageCoverage measurement
pytest-watchFile-watching test re-runner

Test Files

src/lambda_function_test.py — API handler tests
src/lambda_cop_test.py — Cloud Cop tests
src/routes/common_test.py — Route utility tests
src/services/dynamo_data_service_test.py — DynamoDB service tests
src/services/local_data_service_test.py — Local data service tests
src/services/cost_breakdown_service_test.py — Cost calculation tests
src/services/models/instance_test.py — Instance model tests
src/services/models/marqoindex_test.py — Index model tests
src/services/models/all_test.py — Everything object tests
src/services/reports/*_test.py — Reporter tests

Test Strategy

  • Unit tests: Models, services, utilities — fast, no external deps
  • Mocked AWS tests: Using moto to simulate DynamoDB, S3, EC2 APIs
  • Time-dependent tests: Using freezegun for report generation, TTL logic
  • No E2E browser tests: Frontend is server-rendered, no Playwright/Selenium
  • No snapshot tests: HTML output not snapshot-tested

CI/CD

CDK-managed pipeline (infra/ci.py). Build steps:

  1. Tailwind CSS compilation
  2. Lambda zip creation
  3. SAM build
  4. CDK synth
  5. CDK deploy

Dependencies

Production (src/requirements.txt)

arrow — datetime utilities
boto3 — AWS SDK
htmxido — HTML generation DSL
humanize — human-readable numbers
pytz — timezone handling
requests — HTTP client

Development (requirements.dev.txt)

# Infrastructure
aws-cdk-lib, aws_cdk.aws_lambda_python_alpha, constructs

# AWS
aws_lambda_powertools[tracer], boto3-stubs[*]

# Testing
pytest, pytest-coverage, pytest-watch, pytest-freezegun, moto

# Code quality
ruff, mypy, mypy-extensions

# Dev server
flask, livereload, python-dotenv, invoke

# Utilities
coverage, freezegun, ujson, setuptools