Agu Richard Chiwetalu

Two workloads on AWS: IaaS versus managed services

I run two things on AWS. One is plain IaaS and the other is built from managed services. They differ in who does the work and in how the bill is worked out.

The link shortener: IaaS on EC2

A Flask app on a single EC2 instance. It takes a long URL, generates a short code, stores the mapping in MySQL on RDS and redirects when someone requests the short link.

This is IaaS in the textbook sense. AWS rents me an instance with a set amount of CPU, memory, disk and network, and everything I put on it is my job. Under AWS's shared responsibility model they look after the hardware, the network and the hypervisor. I look after the operating system, its patches, the Python runtime and keeping the Flask process up. Unless I add a process manager or health checks, a crash means downtime until I notice. The database is the exception: RDS is managed, so AWS runs the database server and I only deal with the schema and the data.

IaaS is normally priced per instance for the time it runs, and providers either bill partial hours as full hours (non-prorated) or charge only for the part used (prorated). EC2 bills Linux instances per second with a 60-second minimum, so short-lived instances aren't rounded up to an hour. That matters for burst work where you start a lot of instances for a few minutes. For something like the shortener that runs all the time, it doesn't help much. An idle instance costs the same as a busy one.

Scaling out would need an Auto Scaling group with a load balancer in front. The app is in reasonable shape for that because it keeps no state of its own. Every short code lives in RDS, so any instance could serve any request, and the database would hit its limit before the web tier did.

The portfolio: managed services

This site is static HTML in a private S3 bucket. CloudFront serves it over HTTPS on agurichard.com with an ACM certificate, and reads from the bucket through origin access control, so the bucket is never public. There's no operating system anywhere in this that I'm responsible for.

Deployment is a GitHub Actions workflow that runs on every push to main. The job assumes an IAM role through GitHub's OIDC provider, so no AWS access keys are stored as repository secrets. The two commands that do the work:

aws s3 sync ./site s3://<bucket> --delete

aws cloudfront create-invalidation \
  --distribution-id <distribution-id> \
  --paths "/*"

--delete removes anything from the bucket that's no longer in the repo, which matters when pages get renamed or moved. The invalidation clears CloudFront's cached copies so changes show up straight away. A wildcard path counts as one invalidation path, and the first 1,000 paths each month are free, so invalidating /* on every deploy costs nothing at this size.

The billing is usage-based all the way through. S3 charges per gigabyte stored and per request, and CloudFront charges for data transferred and requests served. A quiet month costs almost nothing.

Moving the shortener towards PaaS

The next step is to get the shortener off a hand-managed VM and onto something closer to PaaS, where the provider runs the platform and I only ship the app. PaaS is usually priced by usage, which suits a small app with uneven traffic.

The usual downside of PaaS is lock-in. If the app is written against one provider's own APIs, moving it later means rewriting parts of it. Packaging it as a Docker image first is my way round that. The same image can run on ECS with Fargate, on App Runner, or on another provider's container service, and the database settings will come in as environment variables instead of living on the instance. I'll get it running locally against RDS before choosing where to host it.

← All posts