Eugene.Devhello@eugene.dev
All articles

AWS, Terraform, CI/CD, DevSecOps, Serverless, Load testing

HealthConnect Ghana: DevSecOps for a Community Health Platform on AWS

The cloud and DevOps side of a telemedicine and community-health platform for Ghana. One pipeline that tests, scans and deploys every change, an event layer that never sends a reminder twice, and a load test that found the real bottleneck.

Eugene Sewor

20 November 2026, 10 min read

Community health volunteers in Ghana visit patients in places where the nearest clinic is far away and the phone signal is unreliable. HealthConnect Ghana, our second Cloud Computing project at Ashesi, gives them an app that works offline: record a patient's permission and vital signs with no signal, sync later, book a video visit with a clinician, raise a referral or an emergency.

It's one installable web app with eight roles: volunteers, patients, clinicians, pharmacists, traditional healers, Ghana Health Service officials, facility admins and platform admins. All patient data is synthetic.

Three HealthConnect phone screens: asking a patient's permission to record readings, recording blood pressure, temperature, weight and height offline, and a patient record that flags a high blood pressure reading for a clinician to check.
A volunteer's visit: ask permission first, record vitals offline, and the record flags a reading for a clinician to check.

As on our first project, AgroConnect, I was the Cloud and DevOps lead. I owned the Terraform, the AWS account, the pipeline and the hosting. This article covers what I built and what it taught me.

The team

Member Role
Joseph Etse Project manager and API
Eugene Sewor (me) Cloud and DevOps: infra/ and .github/
Elise Kennedy-Angbo Data: the FHIR-shaped PostgreSQL schema
Perfect Avugla Frontend: the offline-first app and the video call page

The architecture

HealthConnect AWS architecture in af-south-1: the PWA on S3 behind CloudFront; a two-zone VPC with a load balancer, a NAT instance, an Auto Scaling group of 2 to 4 API servers, a dedicated WebRTC call server and RDS PostgreSQL in data subnets; an SNS topic fanning out to two SQS queues and Lambda functions with a DynamoDB table; and supporting services including Secrets Manager, ECR, S3 media, CloudWatch, Systems Manager, IAM with GitHub OIDC and AWS Budgets.
HealthConnect as deployed in af-south-1. I drew this with AWS's official icons to match the running system. Click to open it full size.

We reused the patterns that worked on AgroConnect and fixed the ones that didn't. Everything runs in AWS af-south-1 (Cape Town), the region our latency tests showed was fastest from Ghana, in a separate network that doesn't overlap AgroConnect's.

  • Public subnets hold only the load balancer and a fck-nat instance, which costs about $3 a month instead of about $32 for a managed NAT Gateway.
  • Private subnets hold two to four API servers in an Auto Scaling group, plus the video call server. Nothing in them has a public IP.
  • Data subnets hold PostgreSQL 16 on RDS, encrypted, with seven days of backups and no route to the internet.
  • The app itself is static files in a private S3 bucket behind CloudFront.

All of it is Terraform, in 12 modules, with its state in S3 kept separate from AgroConnect's.

Least privilege, for real

Every server has its own IAM role that names exactly the resources it may touch. The API servers may pull only their own container image, read their own secrets and write their own logs. The NAT instance got its own role too, instead of sharing one. There's no SSH: servers are reached through Systems Manager.

A few things that sound small but matter:

  • TLS everywhere. HTTPS on the load balancer and CloudFront, TLS required by the database, and both S3 buckets refuse any request that isn't over HTTPS. I tested that: the same signed request works over HTTPS and gets "explicit deny" over HTTP.
  • No secrets in code. The database password, the token-signing key and the payment provider's key live in Secrets Manager. Servers read them at start-up through their role.
  • Every patient-record read and write is logged in an append-only audit table.

Hosting the app for about $0

The app builds to plain files, so it needs no servers. It's served from a private S3 bucket that only CloudFront can read, with a certificate from ACM, TLS 1.2 or newer, AWS's managed security headers, and a tiny CloudFront Function that sends app routes like /login to index.html.

At our traffic, CloudFront's free tier covers it, so the hosting costs close to nothing. CloudFront's edge in Lagos is also closer to Ghana than our servers in Cape Town.

Deploys are careful about phones running the old version: hashed asset files go up first and are cached for a year and never deleted, then index.html and the service worker go up with no-cache. A phone halfway through an update can still load everything it needs.

One pipeline that tests, scans and deploys

On AgroConnect, deploys went through one laptop. It broke when that laptop's disk filled up, and a teammate's change sat unreleased because nobody redeployed. For HealthConnect I built one GitHub Actions pipeline that runs on every pull request and every merge to main.

GitHub Actions run: terraform, backend, database schema, Lambda, frontend and call page tests, a secrets, dependency and infrastructure scan, a "what changed" step, then deploy API and deploy PWA jobs, all passing in 22 minutes.
A passing run on main. Tests and scans first; then only the parts that changed are deployed.

On every pull request:

  • Terraform format and validation, API tests against a real PostgreSQL with every migration applied, schema tests, Lambda tests, and the frontend and call page builds.
  • Security scans: gitleaks for secrets across the whole git history, Trivy for vulnerable packages in every lockfile, and Trivy for misconfigured Terraform and Dockerfiles. CodeQL scans the code; Dependabot opens weekly update PRs.

On a merge to main:

  • The pipeline works out what changed since the last green run and deploys only that.
  • The API image is built, scanned by Trivy before it's pushed (a hard gate), tagged with the commit SHA, pinned in Systems Manager, and rolled out by replacing servers, followed by /health and /ready checks.
  • A release waits for one teammate's approval through a GitHub production environment before any deploy job starts.
  • GitHub holds no AWS keys. It signs in with OIDC, and the deploy role trusts only a run on this repository's main branch.

terraform apply stays manual, after a person reads the plan, so the deploy role can't change the infrastructure itself.

Proving the gates work

For the lab, we tested the gates on purpose. A teammate pushed a made-up AWS key on a throwaway branch:

GitHub Actions run titled "DO NOT MERGE: Lab 9 Part B, fake key for the secret scan", failed. All tests pass but the secrets, dependency and infrastructure scan fails, and every deploy job is skipped.
The secret scan catches a planted fake key. Every test passes, but nothing deploys.

Every test passed, the secret scan failed, and nothing deployed. It also taught us something: gitleaks scans every branch, so while that branch existed, it failed unrelated pull requests too. We deleted the branch after capturing the evidence.

Events that never fire twice

When someone books an appointment, two things should happen independently: the patient gets a reminder, and the specialist gets notified. Two functions reading one queue would compete, so each message would reach only one of them.

So the API publishes appointment.created to one SNS topic, which delivers a copy to two SQS queues, each triggering its own Lambda function and each with its own dead-letter queue after three failed attempts. Adding a third consumer later is one more queue.

AWS console showing the reminders dead-letter queue holding one message with body {"type":"appointment.created","appointmentId":"not-a-uuid"}, received 6 times, in a table of the messages waiting in the queue.
Testing the dead-letter queue: a malformed event fails three times and is parked here instead of being retried forever.

Then we found a real bug: one test booking produced two reminders. Nothing was broken. The API and SQS both deliver "at least once", and offline phones retry, so duplicates are expected. The consumer has to handle them.

We added a DynamoDB table that the reminder function claims each appointment in. I created the table and the permission that lets only the reminder function write to it, and Joseph updated the function. The claim is one conditional write: "only if this ID isn't there yet." If it's already claimed, the function logs duplicate_skipped and sends nothing. If sending fails, it releases the claim so SQS can retry. Entries expire after 30 days.

We chose this over a table in PostgreSQL, which would have pulled the function into the private network with database credentials, and over SQS FIFO deduplication, which only remembers for five minutes while a phone can retry hours later. The trade-off is written down: if the function dies after claiming but before sending, that one reminder is lost. At most one beat sometimes two.

Video calls that go directly between phones

Video visits use WebRTC, so the video travels directly between the two browsers and our server only introduces them. That signalling server keeps rooms in memory, so both people must reach the same process. Behind two load-balanced API servers they could land on different ones and never meet.

So the call page runs on one dedicated t3.micro, reached through the same load balancer by a host-name rule. The load balancer drops any connection that's silent for 60 seconds, and a patient waiting for the doctor is silent, so the server pings every socket every 25 seconds.

Call statistics: path direct (srflx to srflx), round-trip time 176 ms, video packet loss 0.00% (0 lost of 918 received), video jitter 52 ms, 23 frames per second.
One of our cross-network test calls, Ho to Oyibi, about 120 km apart on different networks: a direct connection with no packet loss.

I tested it from Ho against Joseph in Oyibi, about 120 km apart on different providers. Every call connected directly with no relay, at 138–192 ms round trip and near-zero packet loss. On a connection throttled to about 3G, video froze but the call never dropped, so in practice telemedicine here should be audio-first. Three calls don't prove every carrier allows direct connections, so production needs a TURN relay as a fallback; it's drawn on the diagram as not yet built.

Load testing: finding the real bottleneck

To see what the system could take, I ran k6 from a temporary server inside the network: 1,000 virtual users at once, each registering 10 patients with 5 records each, 50,000 records in total, all through the load balancer like real phones.

Requests 50,001 in about 290 s (172 per second)
Stored 34,457 (68.9%), about 119 records per second
Refused, database busy (503) 21.7%
Load balancer errors 0
Health check during the test 200 every time
Auto Scaling 2 → 4 servers about a minute in
Peak CPU API servers 26%, database 63%

The system never fell over, but it refused almost a third of the records. The cause wasn't CPU or the database itself; it was the connection pool. Each API server keeps at most 10 database connections and waits at most 5 seconds for one. With 1,000 users at once, requests queued longer than that and got a 503.

That's a good failure: nothing crashed, the service stayed up, and the phones' sync queue retries a 503 later, so in real use those records would arrive on the next attempt. The fix is known: a larger pool, a longer wait or RDS Proxy, and a bigger database class for sustained load. It's written up rather than rushed in before the demo.

The first run was a bug in my script, not the system: I sent readings without their consent link, and the API correctly refused all 30,000 of them. That's the database enforcing consent exactly as designed.

Backups you've actually restored

A backup you've never restored is a hope. I copied the latest automatic database snapshot under a new customer-managed encryption key, restored it as a separate database in the same private subnets, and checked it held exactly the migrations and records from the snapshot time.

Snapshot to a usable database took about 10.7 minutes. The live database wasn't touched, and the copy was deleted afterwards.

What it costs

For 1 to 9 November, the whole shared AWS account spent $35.11 before credits, of which $15.76 was tagged HealthConnect. Education credits covered it, so the actual bill was about $0. Our budget ceiling for the platform was $100 a month.

What I took away

  • Automate deploys before you need them. The laptop that broke on AgroConnect is why every change now goes through one pipeline.
  • Scan before you push, not after. A vulnerable image never reaches the registry.
  • Assume every message arrives twice. Idempotency belongs in the consumer, not in hope.
  • Load tests find the boring bottleneck. It was a connection pool setting, not the database or the servers.
  • Restore your backups. Ten minutes is a number you can put in a plan.
  • Write down the trade-offs. One NAT instance, one approver and no TURN relay are all known risks with known fixes.

The Terraform, the pipeline, every architecture decision and all the lab evidence are in the repository.

Read next

EchoForest: Listening for Chainsaws in Ghana's Forests

The full story of EchoForest, an acoustic machine-learning system that runs on Raspberry Pi sensor nodes and alerts rangers to illegal logging, from a 2021 hackathon win to my final-year project.