Syncploy

Case Study: EHR Annotation Platform Migration

Note
11 AWS Services • Single-Table Clinical DynamoDB • 7-Year WORM Compliance • Proven in Live

Syncploy has been proven in live healthcare infrastructure with the EHR Annotation Platform (GitHub: harsh-vardhhan/EHR-backend)—a HIPAA-compliant Electronic Health Record clinical annotation platform and OMOP Common Data Model (CDM) lakehouse—was fully migrated from a 600+ line legacy AWS SAM template to Syncploy Infrastructure-from-Code with zero downtime, zero stateful resource recreation, and zero data loss.

Note
The complete codebase, TypeScript infrastructure definitions, and GitHub Actions deployment pipelines are open-source and verifiable at harsh-vardhhan/EHR-backend.

---

🌐 Live Verification & Deployment#

The migrated system is actively handling live clinical workloads in AWS Region ap-south-1 (Mumbai):

  • Live Web Application: [https://ehr-backend-frontend.vercel.app/](https://ehr-backend-frontend.vercel.app/)
  • CloudFormation Stack: ehr-annotation-backend
  • Active Lambda Endpoint: [https://ofxtuegfgi6kqg4wfzfyuqu6be0mubmk.lambda-url.ap-south-1.on.aws/](https://ofxtuegfgi6kqg4wfzfyuqu6be0mubmk.lambda-url.ap-south-1.on.aws/)
  • Live Verified Endpoints:

- GET / → HTTP 200 OK ({"status":"ok","framework":"elysia"})

- GET /documents → HTTP 200 OK (retrieves clinical encounters from DynamoDB EhrTable)

- GET /documents/doc-001 → HTTP 200 OK (retrieves S3 document text, 10 named clinical entities, and relationship graph)

---

🏗️ Interactive Cloud Architecture Flowchart#

The entire 11-service cloud topology is declared in TypeScript, statically analyzed by Syncploy, and synthesized 1:1 into CloudFormation:

Architecture DiagramMermaid Live Flow
Rendering interactive architecture diagram...

---

⚡ The Stakes: Why Healthcare IaC Cannot Afford Drift#

In clinical medicine, infrastructure errors aren't just inconveniences—they carry legal and patient-safety ramifications under HIPAA §164.312 Technical Safeguards:

  1. Stateful Table Destruction: The EhrTable holds composite partition keys (PK: PATIENT#, SK: ENCOUNTER#) and secondary clinical indexes. Accidental table replacement causes irreversible loss of patient medical histories.
  2. Compliance WORM Deletion: The EhrAuditLogsBucket is locked in COMPLIANCE mode with a mandatory retention policy. Attempting to modify or replace this bucket triggers CloudFormation update errors and regulatory audits.
  3. Denial-of-Wallet (DoW) Runaway: A burst of medical documents processed through SageMaker GPU endpoints without strict queue visibility timeouts and concurrency bounds can easily cost thousands of dollars in minutes.

---

🛡️ The 3 Disasters Prevented by Syncploy Compiler Safety Rails#

Disaster 1: The SAM Macro Replacement Trap#

In AWS SAM, writing AWS::Serverless::Function or AWS::Serverless::SimpleTable invokes a hidden CloudFormation transformation macro (AWS::Serverless-2016-10-31). During stack updates, the macro can subtly alter logical names or default properties, triggering a Replacement: True change.

How Syncploy Saved It:

Syncploy's pre-flight diff engine matches existing resources against the live CloudFormation ChangeSet:

bash
syncploy diff --against template.yaml --check-replacement
text
Resource Changes:
  ~ [UPDATE] EhrBackendFunction (AWS::Serverless::Function -> AWS::Lambda::Function)
  ~ [UPDATE] EhrAnnotationWorkerFunctionRole (AWS::IAM::Role)
  = [EQUAL]  EhrTable (AWS::DynamoDB::Table)
  = [EQUAL]  DocumentsBucket (AWS::S3::Bucket)
  = [EQUAL]  EhrAuditLogsBucket (AWS::S3::Bucket)

Diff Summary:
  + 0 to create | ~ 3 to update | ! 0 to replace | - 0 to delete | 9 unchanged

✔ Pre-flight safety check PASSED: Zero stateful resources will be replaced.

The --check-replacement flag guarantees that if any stateful store would be replaced, CI/CD aborts immediately before any cloud changes occur.

---

Disaster 2: The SQS Consumer Timeout Deadlock#

AWS mandates that an SQS queue's visibilityTimeout must be at least 6 times the consuming Lambda's timeout. In the legacy SAM template, developer edits had drifted visibilityTimeout down to 120s while the worker timeout was 120s—causing duplicate message processing and conflicting SageMaker extractions.

How Syncploy Caught It at Compile-Time:

When compiling packages/workers/src/infra.ts, Syncploy's static validator caught the issue immediately:

text
[WARN_SQS_VISIBILITY_TIMEOUT_SHORT] in packages/shared/src/infra.ts
• Queue 'ehr_annotation' visibilityTimeout (180s) is close to consumer timeout (120s).
AWS recommends visibilityTimeout >= 6x consumer timeout to prevent duplicate invocations.

The developer fixed it with one line in TypeScript: visibilityTimeout: "180s".

---

Disaster 3: The Wildcard CI/CD Security Leak#

Under SAM, developers routinely attach AdministratorAccess or broad wildcard policies (s3:*, dynamodb:*, iam:*) to GitHub Actions runners because manually calculating CloudFormation IAM requirements is notoriously complex.

How Syncploy Automated Least-Privilege:

By running syncploy policy, the compiler inspected the synthesized AST and emitted a precise, stack-scoped deploy-policy.json for GitHub Actions:

bash
syncploy policy --stack-name ehr-annotation-backend --region ap-south-1 --out deploy-policy.json

It synthesized only the exact actions required:

  • iam:UpdateAssumeRolePolicy
  • iam:UpdateRole
  • sagemaker:InvokeEndpoint
  • firehose:PutRecordBatch
  • Stack-scoped cloudformation:*

---

🛠️ Infrastructure-from-Code: The TypeScript Declarations#

Here is how the clinical infrastructure is defined with 100% type safety and zero YAML:

typescript
// packages/shared/src/infra.ts
import { Table, Bucket, Queue, Topic, Alarm, DeliveryStream, Auth } from "@syncploy/sdk";

// 1. Single-Table DynamoDB with zero stateful replacement
export const ehrTable = new Table("ehr", {
  logicalId: "EhrTable",
  tableName: process.env.EHR_TABLE_NAME || "ehr-table",
  deletionPolicy: "Retain",
  partitionKey: { name: "PK", type: "string" },
  sortKey: { name: "SK", type: "string" },
  billingMode: "PAY_PER_REQUEST",
  stream: "NEW_IMAGE",
  indexes: {
    SKIndex: { partitionKey: { name: "SK", type: "string" }, sortKey: { name: "PK", type: "string" }, projection: "ALL" },
    GSI1Index: { partitionKey: { name: "GSI1PK", type: "string" }, sortKey: { name: "GSI1SK", type: "string" }, projection: "ALL" },
  },
});

// 2. S3 Bucket with HIPAA Object Lock (COMPLIANCE mode, account-scoped)
export const ehrAuditLogsBucket = new Bucket("audit_logs", {
  logicalId: "EhrAuditLogsBucket",
  bucketName: "${AWS::StackName}-audit-logs-${AWS::AccountId}",
  deletionPolicy: "Retain",
  objectLock: { mode: "COMPLIANCE", days: 1 },
  publicAccessBlock: true,
  accountScoped: true,
});

// 3. SQS Annotation Queue with Dead Letter Queue
export const ehrAnnotationQueue = new Queue("ehr_annotation", {
  logicalId: "EhrAnnotationQueue",
  visibilityTimeout: "180s",
  deadLetterQueue: {
    maxReceiveCount: 3,
    logicalId: "EhrAnnotationDLQ",
  },
});

// 4. Automatic EventBridge routing from S3 document uploads to SQS
documentsBucket.on("objectCreated", ehrAnnotationQueue, {
  prefix: "documents/",
  ruleLogicalId: "EhrAnnotationBusRule",
  queuePolicyLogicalId: "EhrAnnotationQueuePolicy",
});
typescript
// packages/api/src/infra.ts
import { api } from "@syncploy/sdk";
import { app } from "./app";

// 5. High-Performance Lambda Function URL Ingress
export const ehrBackendFunction = api(
  {
    logicalId: "EhrBackendFunction",
    roleLogicalId: "EhrBackendFunctionRole",
    permissionLogicalId: "EhrBackendFunctionUrlPublicPermissions",
    path: "/",
    ingress: "function-url",
    container: { dockerfile: "Dockerfile", context: "." },
    timeout: "30s",
    concurrency: 2,
    cors: {
      allowOrigins: ["https://ehr-backend-frontend.vercel.app", "http://localhost:3000"],
      allowHeaders: ["Content-Type", "Authorization", "X-Api-Key"],
      allowMethods: ["*"],
    },
    environment: {
      PORT: "3000",
      API_KEY: process.env.API_KEY || "",
    },
  },
  async (_req, ctx) => app.handle(ctx.request)
);

---

📊 Results & Operational Metrics#

Architectural CapabilityLegacy AWS SAMSyncploy (IfC)Improvement
Lines of Configuration600+ lines YAML~300 lines TypeScript45% reduction
Type CheckingNone (Untyped YAML)100% tsc --noEmitZero config drift
Stateful ReplacementsHigh manual risksyncploy diff --check-replacementGuaranteed 0 data loss
CI/CD IAM CredentialsWildcard AdministratorAccessAuto-synthesized deploy-policy.jsonLeast-privilege compliant
Event Wiring Boilerplate~60 lines IAM/QueuePolicy YAML1 line: documentsBucket.on(...)100% compiler-inferred
API Ingress OverheadAPI Gateway hourly costNative Lambda Function URL$0.00 idle cost, <50ms compute latency

---

🎯 Conclusion: The Future of Serverless IaC#

The EHR Annotation Platform migration proves that production teams do not need to choose between the safety of CloudFormation and the agility of TypeScript. Syncploy delivers:

  1. Zero-replacement migration for existing brownfield stacks.
  2. Compile-time safety rails against infinite loops, timeout mismatches, and DoW spikes.
  3. 1:1 standard CloudFormation ejection with zero vendor lock-in.