Part 4 · A Second Platform Finds a Hidden Bug; Playwright, ElevenLabs and ffmpeg
Chapter 1
The Same Services on Amazon EKS with Helm and Pod Identity
What you will build
A one-day EKS cluster that runs the same image as ECS, with the same permissions, installed by a Helm chart, verified end to end, captured, and destroyed.
Owner's VM: terraform, helm, kubectl (port-forward to the API)
EKS 1.37 control plane (standard support, API endpoint open to the owner's IP only)
Managed node group: 1 x t3.large (public subnet, no NAT)
namespace novanutri (Helm release): api pod, mcp pod
Pod Identity Agent add-on -> IAM roles api-pod and mcp-pod (same rights as the ECS task roles)
Kept from earlier parts: ECR image, Bedrock models and Guardrail, Aurora, Knowledge Base
Prices and choices
| Decision | Price | Why |
|---|---|---|
| Kubernetes 1.37, upgrade policy STANDARD | $0.10 per cluster-hour; extended support would be $0.60 | Never pay for extended support by accident |
| One managed node, t3.large On-Demand | about $0.083 an hour; gp3 $0.08 per GB-month | Fargate on EKS needs private subnets and NAT; Auto Mode adds a per-instance fee |
| EKS Pod Identity, one role per service | no extra charge | Same rights as ECS; no keys in the cluster |
| kubectl port-forward, no load balancer | $0 | Only the owner needs to reach it for the capture |
| Separate Terraform stack, destroyed the same day | about $0.19 an hour in all | Other parts stay untouched |
Terraform for the cluster
resource "aws_eks_cluster" "this" {
version = "1.37"
access_config {
authentication_mode = "API"
bootstrap_cluster_creator_admin_permissions = true
}
upgrade_policy { support_type = "STANDARD" }
vpc_config {
endpoint_public_access = true
endpoint_private_access = true
public_access_cidrs = [var.owner_cidr]
subnet_ids = data.aws_subnets.public.ids
}
}
# Add-ons: vpc-cni, kube-proxy, coredns, eks-pod-identity-agent
# Node group: instance_types = ["t3.large"], AL2023, 30 GB, desired 1
Add one rule on the Aurora security group: port 5432 from the cluster security group only. It leaves with the stack.
Pod Identity: roles per service account
resource "aws_eks_pod_identity_association" "api" {
cluster_name = aws_eks_cluster.this.name
namespace = "novanutri"
service_account = "novanutri-api"
role_arn = aws_iam_role.api_pod.arn
}
# The role trusts pods.eks.amazonaws.com with sts:AssumeRole and sts:TagSession
The mcp service account gets its own role with the MCP rights (Retrieve, embeddings, read-only database user).
A hardened Helm chart
Two Deployments and two ClusterIP Services:
- api: one replica with
strategy: Recreate(meals are kept in memory), readiness and liveness probes on/api/health. - mcp: rolling update, reached in the cluster as
novanutri-mcp:8765. - Same hardening as ECS:
runAsNonRoot, user 10001,readOnlyRootFilesystem, all capabilities dropped,seccompProfile: RuntimeDefault, and anemptyDirmounted at/tmp.
Keep the account ID out of git: the image repository URL and the Aurora, Knowledge Base and Guardrail settings come from Terraform outputs, and an install script passes them to Helm without printing them:
S=$(terraform output -json helm_settings) # a sensitive output: never printed
v() { python3 -c "import json,sys; print(json.loads(sys.argv[1])[sys.argv[2]])" "$S" "$1"; }
helm upgrade --install novanutri deploy/helm/novanutri --namespace novanutri --create-namespace \
--set-string image.repository="$(v image_repository)" \
--set-string aws.auroraHost="$(v aurora_host)" \
--set-string aws.knowledgeBaseId="$(v knowledge_base_id)" \
--set-string aws.guardrailId="$(v guardrail_id)" \
--set-string aws.guardrailVersion="$(v guardrail_version)" \
--wait --timeout 10m 2>&1 | sed -E 's/[0-9]{12}/<account>/g' # mask any account ID in Helm's output
Check the chart before the cluster exists with helm lint and helm template.
The bug only EKS showed
Both pods ran on the first try, and health reported the database reachable, so the IAM token sign-in to Aurora through Pod Identity worked. But health also said Bedrock credentials were missing, and recommend returned 503.
Cause: the service decided whether it may call Bedrock by looking for an API key or the ECS credential variable (AWS_CONTAINER_CREDENTIALS_RELATIVE_URI). Pod Identity delivers credentials through a different variable (AWS_CONTAINER_CREDENTIALS_FULL_URI). The credentials worked; the check refused them. Fix:
# Role credentials a container receives: ECS task role, EKS Pod Identity, EKS IAM roles for service accounts.
ROLE_CREDENTIAL_ENV = ("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI", "AWS_CONTAINER_CREDENTIALS_FULL_URI",
"AWS_WEB_IDENTITY_TOKEN_FILE")
def bedrock_key_loaded() -> bool:
return bool(os.getenv("AWS_BEARER_TOKEN_BEDROCK") or any(os.getenv(name) for name in ROLE_CREDENTIAL_ENV))
Add a parametrized test for each variable, ship it the normal way (commit, CI builds and tests the image), then helm upgrade to the new tag. The upgrade took 52 seconds: the API pod stopped before its replacement started (Recreate), the MCP pod rolled.
General lesson: never detect credentials by one environment variable. Let the SDK's credential chain decide, or accept every documented container credential source.
End-to-end check through port-forward
| Check | Result |
|---|---|
| health | 200; database, vision model, tables, Bedrock credentials ok |
| analyze and confirm (snack photo) | 1.6 s |
| recommend | 18.4 s, $0.0167; both models answered |
| MCP tools | 8 calls in the mcp pod's log |
Teardown and leftover check
Uninstall the release, remove the kubeconfig entry, destroy the stack (20 resources), then check: no cluster, instance, network interface, security group, volume, launch template, log group, IAM role or Aurora rule left. The cluster ran about 1.5 hours, roughly $0.30.
Lessons
- Pin the support type to STANDARD to avoid extended support charges.
- Pod Identity gives each service its own role with no keys and no OIDC provider setup per cluster.
- Run the same image on a second platform; it finds assumptions the first platform hid.
Chapter 2
Making the Demo Video by Code
What you will build
A 2-minute 1080p demo video with narration, quiet background music and burned-in subtitles, produced by scripts you can rerun after any change. No video editor, no screen recorder, and no cloud resource running during production.
record_web.mjs Playwright: the public site, exact 30 fps frames, scripted scroll and a drawn cursor
slides.py PIL: title, architecture, screenshot scenes, end slide
tts.py ElevenLabs API: narration per scene, with character timings
timing.py scene length = lead-in + speech + tail
assemble.py ffmpeg: fit each scene to its voice, join, build the SRT subtitles
music.py ElevenLabs Music API: a calm instrumental bed
finalize.py ffmpeg: duck the music under the voice, normalize loudness, burn in subtitles
Plan the video before recording
Write a scene table: time, screen, source, narration. Decide what not to show: NovaNutri moved the cost and security cards, the disclaimer and trademark notices into an About text under the video, and used saved screenshots for the cloud consoles, so nothing had to be switched on for the video. A homepage demo can be about two minutes; a YouTube series can come later.
Legal checklist for a company video: name cloud services as plain facts (no vendor logos, no implied partnership), no health claims, credit data licenses, use music licensed for commercial use, and keep account IDs, ARNs and emails off screen.
Record the website frame by frame
Screen recorders drop frames and record whatever the machine does. Instead, set the page state for each frame and take a screenshot, then let ffmpeg assemble the frames at an exact 30 fps:
const page = await browser.newPage({ viewport: { width: 1440, height: 810 }, deviceScaleFactor: 4 / 3 }); // 1920 x 1080
async frame(duration = 1 / FPS) {
const file = `${String(this.n++).padStart(5, "0")}.png`;
await this.page.screenshot({ path: `${this.dir}/${file}` });
this.list.push(`file '${file}'\nduration ${duration.toFixed(4)}`); // ffmpeg concat list
}
async scrollTo(y, seconds) {
const from = await this.page.evaluate(() => window.scrollY);
for (let i = 1; i <= Math.round(seconds * FPS); i++) {
await this.page.evaluate((v) => window.scrollTo(0, v), from + (y - from) * ease(i / frames));
await this.frame();
}
}
// A hold is one frame with a long duration, so a 4-second pause costs one screenshot.
- Inject a small SVG cursor and a click ripple into the page and move them per frame.
- A 1440 x 810 viewport at a 4/3 device scale fills 1080p with readable text.
- Render with
ffmpeg -f concat -i list.txt -vf fps=30,scale=1920:1080,format=yuv420p -c:v libx264 -crf 16.
Narration with timings
Generate one MP3 per scene with the ElevenLabs text-to-speech endpoint that returns character timings (/v1/text-to-speech/{voice_id}/with-timestamps). Read the API key from a local .env file and never print it. Try three or four voices on the same sentence before generating the whole script; it costs only a few hundred characters.
The timings do two jobs:
- Scene length. Each scene lasts lead-in (0.5 s) + speech + tail (0.7 s). Holds in the web recording are set so the screen arrives where the sentence starts (for example, scroll to the nutrition cards as the voice says "Nutrition is calculated by code").
- Subtitles. Cut cues at sentence ends, then at commas when longer than about 84 characters, and wrap to two lines of about 42.
Two subtitle bugs worth avoiding:
- Do not split on every period: "U.S." and "novapunkai.com" became separate cues. Mask dots inside words before splitting.
- Never let a cue end after the next one starts: players stack overlapping cues and the text jumps up the screen.
Assemble scenes with ffmpeg
ffmpeg -i scene.mp4 -i scene_voice.mp3 -filter_complex \
"[0:v]tpad=stop_mode=clone:stop_duration=30,trim=duration=$LEN,setpts=PTS-STARTPTS,fps=30,format=yuv420p[v];
[1:a]aresample=48000,adelay=${LEAD_MS}:all=1,apad,atrim=duration=$LEN,asetpts=PTS-STARTPTS[a]" \
-map "[v]" -map "[a]" -c:v libx264 -crf 17 -c:a pcm_s16le scene.mov # PCM audio needs MOV, not MP4
Then join all scenes with the concat demuxer and encode the final AAC track.
Music under the voice
Generate a calm instrumental with the ElevenLabs Music API (POST /v1/music with a prompt, a length in milliseconds and force_instrumental). Paid plans allow broad commercial use; check the current terms for your use.
[0:a]volume=7dB,asplit=2[voice][key];
[1:a]volume=-14dB,afade=t=in:d=1.5,afade=t=out:st=$END:d=3[music];
[music][key]sidechaincompress=threshold=0.03:ratio=6:attack=30:release=600[ducked];
[voice][ducked]amix=inputs=2:duration=first:normalize=0,alimiter=limit=0.89[a]
The voice sits near -16 LUFS; the music about 17 dB under it between sentences and about 20 dB under it while the voice speaks. The whole mix measured about -15.5 LUFS, a good level for web and YouTube.
Subtitles burned in
Many visitors watch with the sound off, so burn the subtitles into the picture:
-vf "subtitles=demo.srt:force_style='FontName=Segoe UI Semibold,FontSize=15,PrimaryColour=&H003D8015,
OutlineColour=&H00FFFFFF,BorderStyle=1,Outline=3,Shadow=0'"
ASS colours are written &HAABBGGRR (blue, green, red), not RGB: #15803D green becomes &H003D8015. A shadow can look like an underline; a thick white outline alone reads well on both white pages and photos. Run ffmpeg inside the output folder so the subtitle path has no drive letter (the filter syntax treats : as a separator).
Put it on the website
Encode a light copy for autoplay (720p, about 7 MB) and a full copy for the case study (1080p, about 11 MB), both with -movflags +faststart. Autoplay must be muted; the burned-in subtitles carry the message. Load the full copy only on click (preload="metadata").
Lessons
- Script the video like code: one change, one rerun.
- Let the narration set the timing, and derive subtitles from the same timings.
- Keep music far below the voice and skip sound effects for a technical demo.
- Show only real screens; the video never needs the cloud running.
See it running
Live demo: novanutri.novapunkai.com
Case study and 2-minute video: novapunkai.com/projects/novanutri
Building a Real-World AI Agent on AWS · NovaNutri
| Part 1 | Project Design and a Data Pipeline from Airflow to Iceberg |
| Part 2 | Honest Model Evaluation and an Agent with MCP, Bedrock and a Guardrail |
| Part 3 | Deploying the Agent on ECS Fargate with CI/CD and a Public Web Demo |
| Part 4 | The Same Services on Amazon EKS, and a Demo Video Made by Code |
NovaNutri is a portfolio technology demo, not a commercial product. Nothing it produces is medical or nutrition advice. Data: Nutrition5k (Google Research, CC BY 4.0), USDA FoodData Central (CC0), Dietary Guidelines for Americans 2025-2030.
AWS, Amazon Bedrock and other product names are trademarks of their owners. This series is independent and not endorsed by Amazon Web Services.