Module project: one API, three hosts
Deploy the Harbourline Accounts API to Elastic Beanstalk, to ECS on Fargate behind an ALB, and to Lambda behind an HTTP API, measure each with the same probe, price each one, and record your recommendation as an architecture decision record.
Assumes: .NET 10 LTS · Amazon.CDK.Lib 2.277.0 · Cdklabs.CdkNag 3.0.2 · Elastic Beanstalk .NET 10 on Amazon Linux 2023 · ECS Fargate (arm64) · Lambda dotnet10 (arm64) · AWS CLI v2 · Region us-east-1 · labs/m03-accounts-api. Verified against official sources on 2026-11-18.
What you are building
A decision, backed by evidence. You take one ASP.NET Core API, the Harbourline Accounts API with its tests, and run the same build on three AWS hosts:
- AWS Elastic Beanstalk: a single-instance environment, .NET 10 on Amazon Linux 2023.
- Amazon ECS on AWS Fargate: tasks in private subnets behind an Application Load Balancer.
- AWS Lambda (
dotnet10): behind an API Gateway HTTP API.
All three read the same DynamoDB table with the same least-privilege permissions and the same Parameter Store path, so any difference you measure comes from the host, not from the application. You then measure latency and cold starts with one probe, price each host with a stated model, and write a one-page comparison and an architecture decision record (ADR) that a colleague could challenge. No data is real; no deployment is left running.
Learning objectives
By the end of the project you can:
- Deploy one application to three different compute models and explain what each one made you configure (a platform zip, a container image, a function package).
- Show that the three hosts share an identity model: a role per host, with the same read-only grant, and no keys.
- Measure first-request and warm latency fairly: same client, same network, same path, with known caveats (TLS on first connection, cold starts).
- Build a cost model with stated assumptions, find the break-even request volume between a fixed-cost host and a per-request host, and say how fragile that number is.
- Write an ADR that states context, options, decision, consequences and a review trigger.
- Tear down all five stacks and prove nothing is billing.
Prerequisites
- Hosting options compared, Elastic Beanstalk for .NET, Deploying to ECS on Fargate and Lambda with C#
- Lab 3.2, Lab 3.3 and Lab 3.4: this project reuses their steps and commands; read them first so you meet each command once with its explanation
- Lab 3.5 is recommended: it explains the Parameter Store key every host needs
- Tools: Docker Desktop with buildx, .NET 10 SDK, AWS CLI v2 with
learn-sandboxsigned in, Node.js LTS and the CDK CLI, an account bootstrapped for CDK in us-east-1
Cost label
| Part | Label | Notes |
|---|---|---|
Tests, local run, cdk synth, cost model, ADR | 🟢 free | Everything except the three deployments |
| Lambda + HTTP API | 🟢 free | Within the Lambda free allowance for lab traffic |
| Beanstalk single instance | 🟡 credits | About one cent per hour for a t3.micro plus its public IPv4 address ⚠ VERIFY |
| Fargate + ALB + NAT gateway | 🟡 credits | The expensive part: roughly USD 0.10 per hour while running |
| Total | 🟡 credits | About USD 0.10 to 0.30 if everything is up for one to three hours and destroyed the same day |
Free alternative: do Parts 1, 5, 6 and 7 without deploying. Run the probe against http://localhost:5080 for the baseline, run cdk synth for all three stacks to read the generated CloudFormation and the cdk-nag results, and complete the cost model and ADR using published prices and the formulas below instead of measured latency. You lose the real cold-start data, so say so in the ADR.
Architecture
| Beanstalk | Fargate | Lambda | |
|---|---|---|---|
| Unit you deploy | Zip of dotnet publish output | Container image in ECR (arm64) | Zip of dotnet publish -r linux-arm64 |
| Front door | nginx on the instance (public IP) | ALB in public subnets, HTTP 80 | HTTP API, HTTPS |
| Where the code runs | EC2 t3.micro, Amazon Linux 2023 | Tasks, 0.25 vCPU / 0.5 GB, private subnets | Execution environment, 1024 MB, arm64 |
| App identity | Instance profile role | Task role | Execution role |
| Port or event | PORT=5000 | 8080 | API Gateway payload 2.0 |
| Health | Beanstalk enhanced health on /health/ready | ALB target group on /health/ready | None (invocation errors) |
| Scaling | None (single instance) | Target tracking, 1 to 3 tasks | Automatic, per request |
| Logs | Beanstalk log streaming, 7 days | /hl-m03/accounts-api/ecs, 7 days | /hl-m03/accounts-api/lambda, 7 days |
| Stack | HlM03-Beanstalk | HlM03-Registry, HlM03-Fargate | HlM03-Lambda |
Security boundary view. Each host has its own identity (instance profile, task role, execution role) and each role gets the same two statements from one helper, AccountsApiPermissions.GrantReadOnly: read one table and its indexes, read one Parameter Store path. None of them can write the table, reach other tables, read other parameters or call other services. Authentication on the API is disabled with an explicit override in all three stacks (see the shortcut below). The unprotected parts of each host are different: Beanstalk exposes the instance on port 80 in the default VPC, the ALB listens on HTTP 80 in public subnets, the HTTP API has a public HTTPS endpoint with a throttle.
Microsoft / Azure comparison
| You know (Microsoft/Azure) | AWS host in this project | What's different |
|---|---|---|
| App Service (Windows or Linux plan) | Elastic Beanstalk | Beanstalk creates real EC2, security group and (in other modes) ALB and Auto Scaling resources in your account |
| Container Apps, or App Service for Containers | ECS on Fargate + ALB | You describe the network (VPC, subnets, security groups) yourself |
| Functions with ASP.NET Core integration, Consumption plan | Lambda + HTTP API | Cold starts are visible in REPORT lines; the platform bills per request and duration |
| Azure Pricing Calculator comparison of plans | A model you write yourself | The point of Part 6: make the assumptions visible |
| Architecture Decision Records in a wiki | ADR in the repository | Same idea; keep it next to the code and review it in a pull request |
Part 1: prepare (free)
All commands run from labs/m03-accounts-api in Git Bash.
Run the tests
dotnet test --solution AccountsApi.slnxExpected: 71 passed, 1 skipped (the optional real-AWS smoke test). Do not deploy anything that fails its tests: a deployment proves the host works, not that the code does.
Run it locally and take the baseline
dotnet run --project src/Harbourline.Accounts.Api --launch-profile http
# in a second window:
dotnet run tools/latency-probe.cs -- http://localhost:5080 200This is the zero-network baseline (in-memory repository, no TLS). Write down p50, p95 and p99. Everything you measure later minus this is what the host, the network and DynamoDB add.
Deploy the shared table, seed it, create the key parameter
export AWS_PROFILE=learn-sandbox AWS_REGION=us-east-1
OWNER=<your-name>
cd infra/cdk && cdk deploy HlM03-Shared -c owner=$OWNER && cd ../..
for f in seed/batch-*.json; do aws dynamodb batch-write-item --request-items "file://$f"; done
aws ssm put-parameter --name /hl-m03/accounts-api/Pseudonymisation/Key --type SecureString \
--value "$(openssl rand -hex 32)" \
--tags Key=Project,Value=cea-lab Key=Lab,Value=m03-accounts-api Key=Environment,Value=learn Key=Owner,Value=$OWNEREach batch-write-item must report "UnprocessedItems": {}; if not, run that file again.
Read the stacks before you deploy them
cd infra/cdk
cdk synth HlM03-Fargate -c owner=$OWNER > /dev/null # cdk-nag runs here; a finding fails the synth
cd ../..Skim BeanstalkStack.cs, FargateStack.cs and LambdaStack.cs. Notice what is shared (AccountsApiPermissions, the table name, the parameter path, the tags) and what is host-specific. Count the resources each stack creates, then write your prediction: which host will have the lowest warm p50, the highest first-request latency and the lowest hourly cost? You will compare it with the evidence.
Part 2: Host 1, Elastic Beanstalk
Publish and zip the contents
dotnet publish src/Harbourline.Accounts.Api -c Release -o publish/beanstalk
# Zip the CONTENTS (files at the archive root) with Windows' built-in bsdtar: it writes forward slashes.
(cd publish/beanstalk && /c/Windows/System32/tar.exe -a -c -f ../beanstalk.zip *)Beanstalk starts the app from <name>.runtimeconfig.json, so the output stays framework-dependent. A zip with a top-level folder, or with backslashes in entry names (PowerShell 5.1's Compress-Archive), leads to a 502 from nginx.
Find the exact platform name and deploy
aws elasticbeanstalk list-available-solution-stacks \
--query "SolutionStacks[?contains(@, 'Amazon Linux 2023') && contains(@, '.NET 10')]"
cd infra/cdk
cdk deploy HlM03-Beanstalk -c owner=$OWNER -c ebSolutionStack="<exact name from the query>"
cd ../..The platform name changes with every platform release, so look it up each time. Creation takes about 5 to 10 minutes. The ApiUrl output is the environment URL (HTTP).
Check it
EB=$(aws cloudformation describe-stacks --stack-name HlM03-Beanstalk \
--query "Stacks[0].Outputs[?OutputKey=='ApiUrl'].OutputValue" --output text)
curl -i $EB/health/ready
curl -s $EB/v1/accounts/ACC-0000000001Note what you had to do yourself on this host: choose a platform branch, zip the output, and set PORT (the stack does it). Note what Beanstalk did for you: instance profile wiring, health reporting, log streaming, managed platform updates.
Part 3: Host 2, ECS on Fargate
Create the registry and push an arm64 image
cd infra/cdk && cdk deploy HlM03-Registry -c owner=$OWNER && cd ../..
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
REGISTRY=$ACCOUNT.dkr.ecr.us-east-1.amazonaws.com
aws ecr get-login-password | docker login --username AWS --password-stdin $REGISTRY
docker buildx build --platform linux/arm64 -t $REGISTRY/hl-m03-accounts-api:v1 --push .
aws ecr wait image-scan-complete --repository-name hl-m03-accounts-api --image-id imageTag=v1
aws ecr describe-image-scan-findings --repository-name hl-m03-accounts-api --image-id imageTag=v1 \
--query "imageScanFindings.findingSeverityCounts"Tags are immutable: a changed image needs a new tag (v2). The details and the rationale are in Lab 3.3.
Deploy
cd infra/cdk && cdk deploy HlM03-Fargate -c owner=$OWNER -c imageTag=v1 && cd ../..
FG=$(aws cloudformation describe-stacks --stack-name HlM03-Fargate \
--query "Stacks[0].Outputs[?OutputKey=='ApiUrl'].OutputValue" --output text)
curl -i $FG/health/readyThis takes about 5 to 8 minutes. From now on the meter is running at roughly USD 0.10 per hour: do not leave this stack up while you write.
Part 4: Host 3, Lambda + HTTP API
Publish for arm64 and deploy
dotnet publish src/Harbourline.Accounts.Api -c Release -r linux-arm64 --self-contained false -o publish/lambda
cd infra/cdk && cdk deploy HlM03-Lambda -c owner=$OWNER && cd ../..
LM=$(aws cloudformation describe-stacks --stack-name HlM03-Lambda \
--query "Stacks[0].Outputs[?OutputKey=='ApiUrl'].OutputValue" --output text)
curl -i $LM/health/readyReplay the sample event too (aws lambda invoke --function-name hl-m03-accounts-api --payload fileb://events/get-account-v2.json out.json). The step-by-step explanation, the cold-start experiments and the Terraform variant are in Lab 3.4.
Part 5: measure
Method matters more than the numbers. Follow it exactly so your table is defensible.
Fix the conditions
- Same machine, same network, same time window. Close other heavy network use. Do all runs in one sitting.
- Same request. The default path
/v1/accounts/ACC-0000000001goes through routing, validation, a DynamoDBGetItemand JSON serialisation. - Sequential requests. The probe sends one at a time on purpose: it measures per-request latency, not throughput, and it cannot overload or bill your deployment.
- Know your caveats. Beanstalk and the ALB are HTTP; the HTTP API is HTTPS. The first request to the HTTPS host pays a TLS handshake that the HTTP hosts do not. The probe reuses one connection afterwards, so the warm numbers are comparable; the first-request numbers are not strictly like with like, and you must say so. Tasks reach DynamoDB through a gateway endpoint; the other two use the public endpoint.
Run the probe three times per host
for H in "$EB" "$FG" "$LM"; do
echo "=== $H ==="
dotnet run tools/latency-probe.cs -- $H 200
doneRound 1 is straight after deployment (a cold Lambda, a warmed-up server). Do rounds 2 and 3 five minutes apart. For Lambda, also do one run after at least 15 minutes without traffic and read the Init Duration from the log:
aws logs tail /hl-m03/accounts-api/lambda --since 30m | grep REPORTRecord real numbers
Copy this table into your report and fill it with what you measured.
| Measure | Local baseline | Beanstalk | Fargate + ALB | Lambda + HTTP API |
|---|---|---|---|---|
| First request, right after idle (ms) | ||||
| Warm p50 (ms) | ||||
| Warm p95 (ms) | ||||
| Warm p99 (ms) | ||||
Lambda Init Duration (ms) | n/a | n/a | n/a | |
Time from cdk deploy start to first healthy response (min) | n/a | |||
| Failed requests of 200 |
Add one line below the table saying where you ran the probe and from which network, and one line on anything unusual (a slow first round, a 5xx, a throttle).
Part 6: price it
Measure latency, calculate cost. Prices change: check them on the pricing pages the day you do this, and write the date next to your figures.
The model
Assumptions to state in your report (change them if you disagree): one Region, 730 hours per month, requests average 60 ms of function time, 1024 MB Lambda memory on arm64, Fargate shape as deployed (one 0.25 vCPU / 0.5 GB arm64 task, one ALB, one NAT gateway, three public IPv4 addresses), Beanstalk as deployed (one t3.micro, one public IPv4 address). The data transfer and log charges are small at lab scale and are left out; say that.
| Component | Unit price used | Source / status |
|---|---|---|
| Fargate vCPU (Linux arm64) | USD 0.03238 per vCPU-hour | AWS Fargate pricing page, checked 2026-11-18 |
| Fargate memory (Linux arm64) | USD 0.00356 per GB-hour | same page |
| Lambda requests | USD 0.20 per million | Lambda pricing page, checked 2026-11-18 |
| Lambda duration, x86 | USD 0.0000166667 per GB-second | same page; arm64 is cheaper, see next line |
| Lambda duration, arm64 | about USD 0.0000133334 per GB-second | ⚠ VERIFY on the Arm tab of the pricing page |
| HTTP API | USD 1.00 per million requests (first tier) | API Gateway pricing page, checked 2026-11-18 |
| Application Load Balancer | about USD 0.0225 per hour plus capacity units | ⚠ VERIFY |
| NAT gateway | about USD 0.045 per hour plus data | ⚠ VERIFY |
| Public IPv4 address | about USD 0.005 per hour each | ⚠ VERIFY |
EC2 t3.micro Linux | about USD 0.0104 per hour | ⚠ VERIFY |
Worked example (illustrative, with the assumptions above)
| Host | Fixed per month | Variable | Result |
|---|---|---|---|
| Fargate (lab shape) | Task: 0.25 × 0.03238 × 730 = 5.91, plus 0.5 × 0.00356 × 730 = 1.30; ALB 0.0225 × 730 = 16.43; NAT 0.045 × 730 = 32.85; 3 IPv4 × 0.005 × 730 = 10.95 | Capacity units and data: small at this scale | about USD 67 per month |
| Beanstalk (lab shape) | Instance 0.0104 × 730 = 7.59; IPv4 0.005 × 730 = 3.65; small disk | none | about USD 12 per month |
| Lambda + HTTP API | none | Per million requests: 0.20 + 1.00 + compute (0.06 s × 1 GB × 0.0000133334 × 1,000,000 = 0.80) | about USD 2.00 per million requests |
Break-even between Fargate and Lambda for this shape: 67 divided by 2.00 is about 34 million requests per month (about 13 requests per second averaged over the month). Below it Lambda is cheaper; above it the always-on host is cheaper if one task can carry that traffic, which only your own load measurement can tell you.
Read the model critically
Most of the Fargate figure is the NAT gateway and load balancer, not compute. With VPC endpoints instead of a NAT gateway, or ECS Express Mode, the number changes a lot. And one Fargate task is not highly available: two tasks in two Availability Zones are the minimum for a bank, which adds about USD 7 per month for the second task but keeps the load balancer and NAT constant. Beanstalk single-instance has no redundancy at all. Lambda is multi-AZ by default. Put these differences in your report; a cost table without an availability row is misleading.
Part 7: the comparison and the ADR
The one-page comparison
Write one page (a table plus five or six sentences) covering these rows for the three hosts: warm latency, cold start or start-up behaviour, deployment effort (steps you ran, time to first healthy response), operational burden (what you patch, scale, monitor), availability, security surface (what is public, what identity it uses), cost model and monthly figure, and rollback. Use only evidence from this project.
The ADR
An ADR is a short record of one decision, written for the person who inherits it. Save it as docs/adr/0001-accounts-api-host.md in your portfolio repository.
# ADR 0001: Host for the Harbourline Accounts API
- **Status:** Proposed (date)
- **Deciders:** (names)
## Context
What the API does, its traffic shape (steady, spiky, overnight bursts), latency expectations,
availability target, who operates it, constraints (security, cost, team skills).
## Options considered
1. Elastic Beanstalk (single instance, or load balanced)
2. ECS on Fargate behind an ALB
3. Lambda behind an HTTP API
## Evidence
Your measured table, your cost model with its assumptions and date, and what you could not measure.
## Decision
We will run ... because ...
## Consequences
Good: ... Bad: ... Risks we accept: ... Follow-up work (HA, TLS, auth, WAF, alarms): ...
## Review trigger
We will revisit if requests exceed N per month, p99 exceeds N ms, or the team changes.Your decision may be any of the three, or a split ("Fargate for the customer API, Lambda for the overnight partner endpoint"). A good ADR says what would make you change your mind.
Security considerations
⚠ Learning shortcut — not for production
All three stacks run the API with authentication disabled through an explicit override, serve over plain HTTP (Beanstalk and the ALB), put a Beanstalk instance in the default VPC, use one NAT gateway, have no WAF and delete data on destroy. The data is fictional and the stacks live for hours. Production: Auth__Mode=Cognito with issuer and client IDs, TLS everywhere (ACM certificates on the ALB, a custom domain on the API), AWS WAF in front of the ALB and Regional APIs where supported, private subnets and VPC endpoints, one NAT gateway per AZ if you keep NAT, retained data with deletion protection, alarms on 5xx, latency and throttling, and a break-glass process for changing the production parameter path.
- Compare identities, not just URLs. Run
aws iam list-role-policiesandaws iam list-attached-role-policiesfor each host's role. The Beanstalk instance role and the Lambda execution role each carry an AWS managed policy for platform duties (AWSElasticBeanstalkWebTier;AWSLambdaBasicExecutionRole, which only writes logs) in addition to the app grant; the Fargate task role carries none, because the separate execution role pulls the image and writes logs. A role per host is the design; a shared role is how permissions creep. - One bucket of configuration, three delivery paths. Each host receives
ParameterStore__Pathas an environment variable and reads the key itself. No secret is baked into a zip, an image or a template. - Each host fails closed on a missing key. Delete the parameter and redeploy or restart one host to see the app refuse to start: that is the intended behaviour.
- Throttle the public Lambda endpoint, and protect the public Beanstalk one. The HTTP API stage allows ten requests per second. The Beanstalk instance and the ALB have no limits, which is one more reason to destroy them the same day.
- The probe sends a correlation header. Search for it in each host's logs; if you cannot find a request across the API, load balancer and application in a few minutes, tracing is not good enough for a bank.
- Never claim compliance. The pipeline here shows controls (least privilege, no keys, immutable image tags, scan on push). Whether a design meets PCI DSS or UK GDPR obligations is a decision for your security, risk and legal functions.
Common mistakes
- Deploying all three, measuring one. Then forgetting the other two are running. Use the destroy checklist and the tag query.
- Comparing numbers from different networks or times of day. You will measure your Wi-Fi, not the hosts.
- Reading one cold start as "the cold start". Cold starts vary; take several, and report a range.
- Putting the Fargate cost in the wrong place. The NAT gateway and ALB dominate; compute is a small part. Say so.
- Forgetting availability in the comparison. A single Beanstalk instance and a single Fargate task are cheap because they are not highly available.
- Writing an ADR after the fact to justify a choice you already made. Write the options and the evidence first, decide second.
- Skipping the tag check at the end. Destroyed stacks occasionally leave log groups, parameters or ENIs.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Tests fail locally | Wrong SDK, or a test depends on a variable you set | Use .NET 10 SDK; unset ParameterStore__Path and Pseudonymisation__SecretId |
cdk deploy HlM03-Beanstalk says the stack does not exist | publish/beanstalk.zip is missing, so the app skipped the stack | Run Part 2 step 1 |
cdk deploy HlM03-Lambda says it is skipping | publish/lambda is missing | Run Part 4 |
ebSolutionStack error | The context value was not passed or the platform name is outdated | Re-run the list-available-solution-stacks query and pass the exact name |
| Beanstalk health "Severe", nginx 502 | App not listening on PORT, or the zip has a top-level folder | Rebuild the zip from inside publish/beanstalk |
| Fargate tasks restart in a loop, targets unhealthy | /health/ready fails (table missing, key missing, wrong architecture image) | Task logs in /hl-m03/accounts-api/ecs; push an arm64 image |
CannotPullContainerError | Tag not pushed or no route to ECR | aws ecr list-images; the NAT gateway must exist |
Lambda returns {"message":"Internal Server Error"} | Exception at start-up | /hl-m03/accounts-api/lambda logs; usually the key parameter or IAM |
Runtime.InvalidEntrypoint | Lambda package built for the wrong architecture | Republish with -r linux-arm64 |
| All hosts return 5xx at once | The shared table or key is missing | Re-run Part 1 step 3 |
| Probe shows 429 from Lambda | Stage throttle (10 req/s) reached | Run only one probe at a time |
| Numbers are wildly different between runs | Network noise, laptop sleep, VPN | Repeat at a quieter time; drop outliers only with a stated rule |
AccessDeniedException ... ssm:GetParametersByPath | The configured path and the IAM resource differ | Both are /hl-m03/accounts-api/ |
Cost and cleanup
Destroy in the same sitting. Expect the Fargate stack's NAT gateway and ALB to be the largest part of the bill for the whole project, and the reason the destroy list below is one command.
cd infra/cdk
cdk destroy HlM03-Lambda HlM03-Fargate HlM03-Beanstalk HlM03-Registry HlM03-Shared -c owner=$OWNER --force
aws ssm delete-parameter --name /hl-m03/accounts-api/Pseudonymisation/Key
cd ../.. && rm -rf publish out.json
# Nothing tagged for this project should remain (some resources take minutes to disappear)
aws resourcegroupstaggingapi get-resources \
--tag-filters Key=Project,Values=cea-lab Key=Lab,Values=m03-accounts-api \
--query "ResourceTagMappingList[].ResourceARN"
# Belt and braces
aws ec2 describe-nat-gateways --filter Name=state,Values=available --query "NatGateways[].NatGatewayId"
aws elbv2 describe-load-balancers --query "LoadBalancers[].LoadBalancerName"
aws elasticbeanstalk describe-environments --query "Environments[?Status!='Terminated'].EnvironmentName"
aws lambda list-functions --query "Functions[?starts_with(FunctionName, 'hl-m03')].FunctionName"If you deleted publish/ before destroying, the Beanstalk and Lambda stacks are not part of what the CDK app synthesises: delete them with aws cloudformation delete-stack --stack-name HlM03-Beanstalk (and HlM03-Lambda). If you also used the Terraform in infra/terraform, run terraform destroy -var owner=$OWNER. The CDK bootstrap stack CDKToolkit stays; it costs cents per month. Check Billing → Cost Explorer the next day as a final proof (filter by the tag Project=cea-lab if you have activated it as a cost allocation tag; otherwise look at the daily total by service).
Exercises
- 🟢 Guided: Compare your prediction from Part 1 step 4 with the measured table. For each wrong prediction, write one sentence on why.
- 🟡 Challenge: Change the cost model's assumptions: 200 ms average duration, 512 MB Lambda memory, and a VPC-endpoint design for Fargate without NAT (you must price the endpoints yourself). Recompute both break-even points. How sensitive is the decision to each assumption?
- 🔴 Live problem: Harbourline's partner team says: "the Accounts API must be highly available across two Availability Zones, answer 99% of requests within 300 ms, and cost under USD 150 per month for 20 million requests." Recommend a host, say what extra design you would add (and price it), and say which of your measurements you would need to repeat under real load before signing off.
Assignment
Publish a repository (or folder in your portfolio) with: your measured table and the conditions you ran it under; the cost model as a small file you can re-run (a spreadsheet, or a script that takes request volume, duration and memory and prints monthly cost per host); the one-page comparison; and docs/adr/0001-accounts-api-host.md. Add a section "What would change in a real bank?" covering TLS and WAF, authentication, multi-AZ, accounts and environments, and who must approve the host choice.
Solutions
Expect these patterns, and check that they hold for your data: the local baseline is the lowest warm latency (no network, no database); Beanstalk and Fargate warm latencies are close to each other and dominated by your distance to us-east-1 and the DynamoDB call; Lambda's warm p50 is similar or slightly higher (API Gateway and the event translation add a little), with a visibly worse p99 and a first request that is several times slower after idle. Most people predict Lambda will be the cheapest and fastest; it is the cheapest at low volume and not the fastest. If your numbers differ, ask whether you were on a different network between rounds. A prediction that is wrong is the useful part: write down the model of the system that was wrong.
At 200 ms and 512 MB: compute per million requests is 0.2 s × 0.5 GB × 0.0000133334 × 1,000,000 = about USD 1.33, so Lambda is about 0.20 + 1.00 + 1.33 = USD 2.53 per million, and the break-even against the lab-shape Fargate (USD 67) rises to about 26 million requests per month. With VPC endpoints instead of NAT you remove USD 32.85 and one IPv4 address (USD 3.65) but add interface endpoints priced per endpoint-hour per AZ (about USD 0.01 per hour each ⚠ VERIFY; for ECR API, ECR DKR, CloudWatch Logs and SSM across two AZs that is eight endpoint-hours, about USD 58 per month, plus a free S3 gateway endpoint), so for a one-task service the NAT gateway can actually be cheaper: the saving only appears at larger scale or when NAT data charges are high. The lesson is that the decision is more sensitive to per-request duration and fixed networking cost than to the compute price per second.
Lambda meets high availability by default but risks the 300 ms target on cold starts and for 99% you can tolerate roughly one slow request in a hundred, so measure the cold-start share at the expected concurrency and traffic pattern; at 20 million requests per month (about 8 per second average) most requests are warm. Cost: Lambda about USD 2 per million gives about USD 40 per month, well under the limit; add provisioned concurrency or SnapStart if the cold-start share breaks the 99% target. Fargate: two tasks in two AZs plus an ALB and a NAT gateway or endpoints is roughly USD 75 to 130 per month depending on the networking choice, still under the limit, with more predictable latency. Beanstalk single-instance fails the availability requirement; load-balanced Beanstalk across two AZs would pass but costs more than Fargate for the same shape. Add: TLS, auth, WAF, alarms. Repeat under realistic load: p99 and error rate for each candidate, the cold-start share for Lambda, and the scale-out time for Fargate when traffic doubles. Recommend the cheaper host that passes the repeated measurement, state the risks you accept in the ADR, and set a review trigger.
Knowledge check
Answer: So the only variable in your comparison is the host. A different table, Region or permission set would change latency and risk and make the comparison meaningless. The shared helper also demonstrates least privilege: the same two statements, scoped to one table and one parameter path, apply to an instance role, a task role and an execution role.
Answer: It measures per-request latency, not throughput. Sequential requests also cannot accidentally load-test, and bill, a public lab deployment, and avoid queuing effects that would hide the host's own behaviour.
Answer: The HTTP API is HTTPS, so the first request pays a TLS handshake; the Beanstalk and ALB endpoints are HTTP. Lambda's first request may also include a cold start. State the protocols, and compare warm percentiles (one reused connection) as the like-with-like numbers.
Answer: The networking, not compute: the NAT gateway and the ALB (and their IPv4 addresses) cost several times more than the 0.25 vCPU task. This is why the stack is cheap per hour but not cheap per month if left running.
Answer: The conditions under which the decision should be revisited, stated as measurable thresholds (request volume, p99 latency, cost, team or compliance change). Without it, a decision made on lab-scale assumptions silently becomes permanent.
Interview questions
- You have an API with unpredictable traffic. How do you choose between Lambda and Fargate? Measure cold starts and warm latency, model cost against the expected request range with stated assumptions, check availability and operational burden, and write the decision down with a review trigger. Spiky and idle favours Lambda; steady and latency-sensitive favours Fargate; the break-even is specific to the workload.
- What does Elastic Beanstalk give you over raw EC2, and what does it hide? Provisioning, health reporting, log streaming, managed updates and a deployment mechanism for your zip. It hides real EC2, security group, load balancer and Auto Scaling resources that still exist in your account and still bill.
- How do you keep three environments' permissions consistent? One policy definition (a helper or module) applied to each environment's role, tested by listing the resulting policies, plus alarms or Config rules for drift.
Certification practice
A team compares running an API on a single always-on container task with a load balancer (fixed monthly cost) against AWS Lambda behind an HTTP API (cost per request). Traffic is currently low but is expected to grow tenfold. Which statement is correct? A. Lambda is always cheaper. B. The container option is always cheaper. C. There is a request volume above which the fixed-cost option becomes cheaper, so the team should compute that break-even using measured duration and memory. D. Cost does not depend on request volume. Answer: C. Per-request pricing scales with traffic; fixed-cost hosting does not. The crossover depends on duration, memory and the fixed resources (load balancer, NAT). A and B ignore it; D is false.
A developer must deploy the same ASP.NET Core application to Elastic Beanstalk, ECS on Fargate and Lambda. Which artefacts are required, respectively? A. A zip of the published output, a container image in a registry, and a zip of the published output built for the function's architecture. B. A container image for all three. C. A Git repository URL for all three. D. A compiled .exe for all three.
Answer: A. Beanstalk takes an application bundle, ECS runs an image from a registry, and a Lambda zip must match the function's runtime and architecture. B is wrong for the zip-based hosts (Lambda supports images, but this project uses the managed runtime), C and D are not deployment artefacts for these services.
An API runs as one Fargate task behind an ALB. The company requires availability across a single Availability Zone failure. What change meets the requirement at the lowest additional cost? A. Increase the task's CPU. B. Run at least two tasks in subnets in two Availability Zones. C. Move the ALB to a private subnet. D. Enable deletion protection on the ALB. Answer: B. Tasks spread across AZs keep serving if one AZ fails. A changes capacity not placement; C breaks internet access; D protects against deletion, not failure.
Completion checklist
- Tests pass (71 passed, 1 skipped) before I deployed anything
- All three hosts answered
/health/readyand the same account request - I measured with one probe, one network, three rounds, and recorded the conditions
- My cost model states every assumption and price date, with a break-even figure
- I wrote the one-page comparison and an ADR with a review trigger
- I destroyed all stacks, deleted the parameter, and the tag, NAT and load balancer checks returned nothing
Key takeaways
- A host is a bundle of trade-offs: packaging, networking, scaling, availability, cost shape and operational burden. The code is the same; everything around it differs.
- Measure with a controlled method and disclose its caveats; do not quote latency without saying how you got it.
- Cost has a fixed part and a variable part; the break-even between them is the number that matters, and it moves with your assumptions.
- Cheap and unavailable are different from cheap and available: always put availability in the comparison.
- An ADR is a record of the evidence and the conditions for changing your mind, not a justification.
Further reading
Independent learning resource — not affiliated with, endorsed or sponsored by Amazon Web Services. AWS and related marks are trademarks of Amazon.com, Inc. or its affiliates. All banking data in examples is fictional. Sample architectures are for learning and are not automatically compliant with GDPR, PCI DSS or any banking regulation.
Porting .NET Framework apps to AWS
Decide whether to rehost, replatform or port a legacy .NET Framework 4.8 banking application, use AWS Transform for .NET and Microsoft's upgrade tooling, fix the classic blockers (System.Web, WCF, configuration, Windows-only APIs), and know when Windows on EC2 or Beanstalk is the right answer.
Module 3 cheat sheet
One-page revision summary for .NET Application Development on AWS: services, Azure mapping, CLI commands, limits, decision rules, exam traps and cost traps.