Voting App on AWS
Public demo repo for customer labs and POV workshops.
Deploy a 3-tier voting application on AWS with Terraform in about 5 minutes. The stack is designed for segmentation and security demos (e.g., Cisco Secure Workload east-west policy testing) — web, app, and database tiers on separate subnets with distinct security groups.
|
|
| Repository |
https://github.com/chandrapati/voting-app-aws |
| Deploy time |
~5 min (Terraform) + ~8–12 min (app bootstrap) |
| Teardown time |
~2–3 min |
| Default region |
us-east-1 |
| Estimated cost |
~$0.05/hr on-demand (~$1.25/day if left running) |
What you get
A working “What’s For Lunch?” voting UI backed by a .NET API and SQL Server database:
Internet
|
┌──────┴──────┐
│ voting-web │ HTTP/HTTPS :80/:443
│ t3.micro │ 192.168.1.0/24 (public)
└──────┬──────┘
│ ec2.internal DNS
┌──────┴──────┐
│ voting-app │ HTTP :80
│ t3.micro │ 192.168.101.0/24 (public)
└──────┬──────┘
│ SQL :1433
┌──────┴──────┐
│ voting-db │ SQL Server 2019 (Docker)
│ t3.small │ 192.168.201.0/24 (private)
└─────────────┘
┌─────────────────┐
│ voting-client │ cron: HTTP+HTTPS → web, HTTP → app (east-west)
│ t3.micro │ 192.168.102.0/24 (private)
└─────────────────┘
| Tier |
Hostname |
Access |
Instance |
| Web (UI) |
voting-web01 |
Public IP |
t3.micro |
| App (API) |
voting-app01 |
Public IP |
t3.micro |
| DB (SQL) |
voting-db01 |
Private IP only |
t3.small |
| Client |
voting-client01 |
Private IP only |
t3.micro |
VPC Flow Logs (enabled by default) capture all accepted/rejected traffic for the VPC and deliver hourly partitioned plain-text logs to an encrypted, private S3 bucket with a 30-day lifecycle expiration.
Traffic generator (enabled by default, like Siwapp) — a voting-client01 EC2 in 192.168.102.0/24 runs a cron job every minute that:
- Hits the web tier over HTTP and HTTPS (
GET /, GET/PUT api/Votes)
- Hits the app tier API directly over HTTP (east-west: client → app → db)
This produces continuous flows for CSW ADM, segmentation policy demos, and VPC flow logs in S3.
Application binaries are pulled at boot from wajihalsaid/Voting_app.
Prerequisites
Install and verify before you start:
| Tool |
Check |
| AWS CLI v2 |
aws sts get-caller-identity |
| Terraform ≥ 1.3 |
terraform version |
| SSH client |
ssh -V |
| curl (for smoke test) |
curl --version |
You need an AWS account with permissions to create VPC, EC2, Route53, and security groups. No pre-existing infrastructure is required.
Bring up the app
Step 1 — Clone the repository
git clone https://github.com/chandrapati/voting-app-aws.git
cd voting-app-aws/terraform
Step 2 — Generate an SSH key (first time only)
ssh-keygen -t rsa -b 4096 -f voting-app-key -N "" -C "voting-app-deploy"
The private key voting-app-key stays on your machine (gitignored). Only the public key is registered in AWS.
Defaults work for most labs. To customize region or instance sizes:
cp terraform.tfvars.example terraform.tfvars
Edit terraform.tfvars if needed:
vpc_region = "us-east-1" # change region if required
instance_type = "t3.micro" # web + app tiers
db_instance_type = "t3.small" # SQL Server Docker needs 2 GiB RAM
If you use a named AWS CLI profile, set aws_credentials_profile = "your-profile".
Step 4 — Deploy
terraform init
terraform apply
Type yes when prompted (or use terraform apply -auto-approve in automation).
Timeline:
| Phase |
Duration |
What happens |
| Terraform apply |
~3–5 min |
VPC, 3 EC2 instances, security groups, private DNS |
| User-data bootstrap |
~8–12 min |
Docker SQL Server, .NET apps, Apache |
| Ready to use |
~15 min total |
UI responds on port 80 |
Your public IP is auto-detected and added to security groups for SSH and HTTP access.
Step 5 — Get the app URL
terraform output voting_web_url_http
Example: http://44.201.139.245
Open that URL in a browser. You should see “What’s For Lunch?” — add lunch options and vote.
Traffic generation starts automatically within ~5 minutes of the client EC2 boot (after the web tier is healthy). Monitor it:
terraform output monitor_traffic_log
# copy-paste the ssh ... tail -f command
Step 6 — Run the smoke test (recommended)
From the repo root:
./scripts/test-voting-app.sh
This polls the web tier for up to 15 minutes and reports success or troubleshooting hints.
Useful outputs after deploy
terraform output # all outputs
terraform output -raw voting_web_url_http
terraform output -raw voting_app_public_ip
terraform output -raw sql_password # SQL Server sa password (sensitive)
terraform output ssh_web # copy-paste SSH command
Verify the app works
- Browse to
terraform output -raw voting_web_url_http
- Add a lunch suggestion and vote
- Refresh the page — vote counts should update
- (Optional) HTTPS:
terraform output -raw voting_web_url_https — browser will warn about self-signed cert; proceed for lab use only
Tear down the app
Always destroy when the lab is finished to avoid ongoing charges.
cd voting-app-aws/terraform
terraform destroy
Type yes when prompted. All resources are removed in ~2–3 minutes.
Confirm nothing is left behind
# Should return empty or no voting-app resources
aws ec2 describe-instances \
--filters "Name=tag:Project,Values=voting-app" \
--query 'Reservations[].Instances[].State.Name'
aws ec2 describe-vpcs \
--filters "Name=tag:Project,Values=voting-app" \
--query 'Vpcs[].VpcId'
If terraform destroy fails partway, run it again — it is safe to retry.
Cost to run
Pricing below is approximate for us-east-1 on-demand (June 2026). Actual charges depend on your AWS account, region, and usage.
Compute (main cost)
| Resource |
Qty |
~$/hour |
~$/day (24h) |
~$/month (730h) |
t3.micro (web) |
1 |
$0.0104 |
$0.25 |
$7.59 |
t3.micro (app) |
1 |
$0.0104 |
$0.25 |
$7.59 |
t3.small (db) |
1 |
$0.0208 |
$0.50 |
$15.18 |
t3.micro (client) |
1 |
$0.0104 |
$0.25 |
$7.59 |
| EC2 subtotal |
|
~$0.052/hr |
~$1.25/day |
~$38/month |
Other charges (usually small)
| Item |
Estimate |
| EBS volumes (default ~8 GB × 3) |
~$2/month if instances run 24/7 |
| Route53 private hosted zone |
$0.50/month per zone |
| VPC Flow Logs → S3 |
~$0.50/GB ingested + ~$0.023/GB-month storage (low for demo traffic) |
| Data transfer (inbound) |
Free |
| Data transfer (outbound) |
First 100 GB/month free, then per-GB rates |
Cost-saving tips for customer demos
- Run
terraform destroy immediately after the workshop — a 4-hour lab costs ~$0.17 in EC2 alone.
- Do not leave the stack running overnight — ~$1/day adds up across multiple demos.
- Use the same AWS account/region for repeat workshops; no need to keep instances running between sessions.
- Spot instances — set
use_spot_instances = true in terraform.tfvars for ~60–70% EC2 savings (instances can be interrupted; acceptable for short demos).
Example workshop scenarios
| Scenario |
Duration |
Approx. EC2 cost |
| Single 2-hour POV session |
2 hr |
~$0.08 |
| Full day lab (8 hr) |
8 hr |
~$0.34 |
| Forgot to destroy (1 week) |
168 hr |
~$7.00 |
| Left running 30 days |
730 hr |
~$30.00 |
Note: This stack is not covered entirely by AWS Free Tier because the database tier uses t3.small (SQL Server in Docker requires 2 GiB RAM).
Troubleshooting
1. App URL times out or connection refused
Cause: Bootstrap still running (normal for 8–12 min after terraform apply).
Fix:
./scripts/test-voting-app.sh
Wait until you see OK: HTTP 200.
| Symptom |
Likely cause |
Fix |
ExpiredToken / auth error |
AWS credentials expired |
aws sso login or refresh keys, then retry |
UnauthorizedOperation |
IAM permissions missing |
Ensure EC2, VPC, Route53 create permissions |
| Stuck >15 min on one resource |
Transient AWS API delay |
Ctrl+C, then terraform apply again |
Error acquiring the state lock |
Previous run interrupted |
Delete .terraform.tfstate.lock.info if no other apply is running |
3. Can’t SSH or browse the app (but it worked earlier)
Cause: Your public IP changed; security groups only allow your IP at apply time.
Fix:
cd terraform
terraform apply # re-detects IP and updates security groups
4. Web tier issues
ssh -i voting-app-key ubuntu@$(terraform output -raw voting_web_public_ip)
sudo tail -100 /var/log/cloud-init-output.log
sudo systemctl status votingweb apache2
curl -s localhost:5000 | head -20
Look for voting-web bootstrap complete in /var/log/voting-web-bootstrap.log.
5. API tier issues (500, 503, api/Votes failures)
Full reference: docs/API-ERRORS.md — symptom table, bootstrap failure modes, and recovery steps.
Quick check from your laptop:
./scripts/diagnose-voting-app.sh
On the app host:
ssh -i voting-app-key ubuntu@$(terraform output -raw voting_app_public_ip)
sudo tail -100 /var/log/cloud-init-output.log
sudo systemctl status votingdata apache2
grep -i Catalog /var/www/votingdata/appsettings.json # expect votingapp
sudo journalctl -u votingdata -n 30 --no-pager
Common causes: SQL Server not running on db tier (Docker install failed on first boot), or wrong Initial Catalog. The app tier waits up to 15 minutes for voting-db01.ec2.internal:1433. Recreate db + app after pulling latest install scripts:
terraform taint 'aws_instance.voting["voting-db"]'
terraform taint 'aws_instance.voting["voting-app"]'
terraform apply
6. Database tier issues
The DB host has no public IP. Jump through the app host:
APP_IP=$(terraform output -raw voting_app_public_ip)
ssh -i voting-app-key -J ubuntu@${APP_IP} [email protected]
sudo docker ps
sudo docker logs sqlserver --tail 50
cat /var/log/voting-db-bootstrap.log
SQL Server is ready when docker logs show: SQL Server is now ready for client connections.
7. Votes don’t persist / database errors
# From app host — test SQL port
nc -zv voting-db01.ec2.internal 1433
# Get SA password from your laptop
terraform output -raw sql_password
Check security group allows TCP 1433 from app subnet 192.168.101.0/24.
8. .NET or package install failures
User-data installs legacy .NET Core 2.2 on Ubuntu 22.04. If apt/wget fails (mirror timeout):
sudo tail -200 /var/log/cloud-init-output.log
Recreate the affected instance:
terraform taint 'aws_instance.voting["voting-web"]'
terraform apply
9. Recreate everything from scratch
terraform destroy -auto-approve
terraform apply -auto-approve
./scripts/test-voting-app.sh
10. VPC Flow Logs / S3 (CSW-compatible)
Flow logs are on by default, published to S3 as plain text with a
CSW-required field set (including pkt-srcaddr / pkt-dstaddr for NAT
visibility). traffic_type = ALL captures both ACCEPT and REJECT.
After deploy:
terraform output vpc_flow_logs_s3_bucket
terraform output vpc_flow_logs_s3_prefix
List recent flow log objects (allow a few minutes after traffic starts):
BUCKET=$(terraform output -raw vpc_flow_logs_s3_bucket)
aws s3 ls "s3://${BUCKET}/AWSLogs/" --recursive | tail -20
Verify the CSW field header in a log file:
KEY=$(aws s3 ls "s3://${BUCKET}/AWSLogs/" --recursive | tail -1 | awk '{print $4}')
aws s3 cp "s3://${BUCKET}/${KEY}" - | gunzip -c | head -1
# Expect header containing: version srcaddr dstaddr ... pkt-srcaddr pkt-dstaddr flow-direction log-status
Point the CSW AWS connector at this bucket for flow ingestion (S3 only, not CloudWatch).
Disable flow logs in terraform.tfvars:
enable_vpc_flow_logs = false
Adjust retention (default 7 days):
flow_logs_retention_days = 7
Verify delivery and CSW-ready format:
bash scripts/verify-flow-logs.sh
terraform output -raw csw_flow_log_bucket_name
11. Traffic generator
The client (192.168.102.40) has no public IP. SSH via web jump host:
terraform output ssh_client_via_web
Monitor probe log:
terraform output monitor_traffic_log
Manual test on the client:
sudo /usr/local/bin/voting_traffic_probe.sh voting-web01.ec2.internal voting-app01.ec2.internal
Disable the traffic generator:
enable_traffic_generator = false
Typical log lines:
[2026-06-29 12:00:01] [http/web] PUT api/Votes/Pizza-1719667201 -> 200
[2026-06-29 12:00:02] [https/web] GET api/Votes -> 200
[2026-06-29 12:00:03] [http/app] PUT api/Votes/Sushi-1719667203 -> 200
If probes show 000 or 502, the app stack is still bootstrapping — wait 8–12 min after terraform apply.
Security notes for customer demos
- HTTP is open to your IP (auto-detected) plus RFC1918 ranges for tier-to-tier traffic.
- The database tier is not internet-facing.
- SQL
sa password is randomly generated and stored in Terraform state — treat state files as sensitive.
- This is a lab/demo stack, not production-hardened. Do not store real customer data.
- Destroy the environment when finished.
Repository layout
voting-app-aws/
├── README.md # This file
├── scripts/
│ └── test-voting-app.sh # Post-deploy smoke test
└── terraform/
├── main.tf
├── network.tf
├── security_groups.tf
├── ec2.tf
├── dns.tf
├── secrets.tf
├── flow_logs.tf # VPC Flow Logs → S3
├── traffic_client.tf # Traffic generator EC2
├── variables.tf
├── outputs.tf
├── terraform.tfvars.example
└── scripts/
├── install-voting-db.sh
├── install-voting-app.sh
├── install-voting-web.sh
├── install-voting-client.sh
└── voting_client_generate_traffic.sh
Sharing with customers
Send them:
- Repo link: https://github.com/chandrapati/voting-app-aws
- Prerequisites: AWS account, CLI, Terraform (table above)
- Bring-up: Steps in Bring up the app
- Teardown:
terraform destroy when done
- Cost: ~$0.04/hr — destroy after the session
License
Terraform and documentation in this repository may be used freely for demos and workshops. Application binaries are sourced from the upstream Voting_app project — refer to that repository for application licensing.
评论