AWS Builder Center

A 2018 bookstore showcase on AWS

A 2018 bookstore showcase on AWS

The showcase is  RepakaRamateja/CloudNative-BookStore-MicroServices-GO , a student's write-up of Packt's Getting Started with Cloud Native Go course. Its README promises a "Micro Service based Http Book Store Rest API" on Go, Docker and Kubernetes, and walks a ten-rung ladder: an HTTP server on the standard library, JSON marshalling of a  Book , a REST API, a Dockerfile, an Alpine variant, a compose file with nginx in front, then Pods, Namespaces, Deployments and Services, and finally  kubectl scale  and a rolling update.
That ladder is the one this repository's  app/  service climbed: one Go file, a multi-stage build onto distroless, three replicas on EKS behind an ALB provisioned from an Ingress, the image in ECR, identity from IRSA. So the useful question is not "could this run on AWS" but which rung of the showcase becomes which AWS service, and which rung the showcase is missing. Read from the source rather than the title, the repository is:
what the title says
what the source says
microservices
one service: five handlers on the default mux, no gRPC, no queue, no auth
a bookstore
a package-level  map[string]Book  seeded with two titles; each replica has its own copy and a restart empties it
Kubernetes manifests
 extensions/v1beta1  for both the Deployment and the Ingress, an API group removed in Kubernetes 1.16;  --record  in the rollout commands, since removed from  kubectl 
containerised
a binary built on the host, copied into  alpine:3.5 , a base that stopped receiving patches in 2018
good bones
requests and limits, a  RollingUpdate  strategy with  maxSurge  and  maxUnavailable ,  minReadySeconds , readiness and liveness probes, unit tests with testify
The last row is why the showcase is worth mapping at all. It teaches the right habits on primitives that have aged, and the habits are the part that transfers.


First, a cluster that will accept the manifests

Nothing below works until two files change, and neither change is about AWS. The Deployment needs  apps/v1 , which requires the  spec.selector  that  extensions/v1beta1  defaulted from the template labels. The Ingress needs  networking.k8s.io/v1 , whose  defaultBackend  replaced  backend  and whose  service.name  and  service.port.number  replaced  serviceName  and  servicePort :
apiVersion: apps/v1
kind: Deployment
spec:
selector:
matchLabels:
app: cloud-native-go
# everything else in the original is still valid apps/v1
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cloud-native-go
spec:
defaultBackend:
service:
name: cloud-native-go
port:
number: 8080
On EKS specifically, the minimum supported Kubernetes version is years past 1.16, so the unedited manifests are rejected at  apply . That is the fastest possible way to learn this, and it is the first thing the showcase's reader will hit. The README's  kubectl  sequence itself,  create ,  scale ,  set image ,  rollout history ,  rollout undo , is current once  --record  is dropped; rollout history now reads the  kubernetes.io/change-cause  annotation instead.

The ladder, one AWS piece per rung


the README's rung
what it does today
the AWS piece
state here
 go build ,  docker build ,  docker push 
builds on the host, copies the binary into  alpine:3.5 , pushes to Docker Hub
CodeBuild running a two-stage Dockerfile (a  golang  builder, a distroless or  scratch  final stage), pushing to ECR with immutable tags and scan on push; a Graviton fleet or  buildx  for the  linux/arm64  image the  t4g  nodes want
built:  app/Dockerfile  is that two-stage build, and the ECR repository is Terraform
 docker-compose  with  nginx:1.11.9  in front
a reverse proxy on 8080 to the service on 9090, via a  links:  block
the Application Load Balancer is the reverse proxy, and the nginx container disappears; App Runner is the one-call equivalent of  docker-compose up -d  if there is no cluster
built: the ALB, from the Ingress
Pod, Namespace, Deployment
 kubectl create -f , labels,  describe 
unchanged on EKS after the  apps/v1  bump; a  pod-security.kubernetes.io/enforce=restricted  label on the namespace makes Pod Security Admission reject the spec until it gains a  securityContext , which the Go binary does not need to be without
built:  k8s/base  carries the Deployment, Namespace and ServiceAccount
NodePort Service, bare Ingress
 type: NodePort  "to access a port on each node"; an Ingress with no class and no host
on EKS the nodes are in private subnets and nothing reaches a NodePort; the Ingress, with  ingressClassName: alb  and  target-type: ip , is turned into an ALB by the Load Balancer Controller, and an ACM certificate ARN in an annotation adds TLS
built: the same Ingress shape, the same controller
the in-memory map (the rung the README lacks)
 map[string]Book , one copy per replica
DynamoDB, a single table with  isbn  as the partition key and on-demand capacity; the pod reaches it through IRSA or EKS Pod Identity with a role allowing five actions on one table, so no key lives in the image, the manifest or a Secret
target: the whereami service is stateless on purpose; the IRSA role exists
 scale --replicas=5 ,  set image ,  rollout undo 
five replicas that fit on the laptop; a rollout that discards every book created since the last one
Karpenter so that scaling past the node group provisions an instance and removes it after; a HorizontalPodAutoscaler so it is driven by load; the ALB pod readiness gate so a new pod is not ready until its target is healthy, which closes the brief 502 window; immutable ECR tags so  1.0.2  cannot be silently re-pushed
built:  k8s/base  has the HPA and PDB; Karpenter and the readiness gate are target

The one change that matters is the database

Every scaling and rollout demo in the README is correct only for a stateless service, and the bookstore is not one. It keeps its state where it cannot survive:  kubectl scale --replicas=5  produces five bookstores that disagree, and  kubectl set image  throws away every book created since the last revision. The showcase's own probes make this invisible, because both hit  /  and  /  always answers 200.
DynamoDB is the fit because the map is keyed by ISBN, the access pattern is get-by-key, put, update, delete and scan-all, and a  Book  is four strings. The change is confined to the six store functions in  api/book.go , using the AWS SDK for Go v2, and it is strictly better than the map on one point the showcase gets wrong even in memory:
operation
the map today
DynamoDB
create
look up the ISBN, then insert; two replicas can both succeed
 PutItem  with  ConditionExpression: attribute_not_exists(isbn) , atomic, returns the  409 Conflict  the handler already sends
update
look up, then overwrite
 UpdateItem  with  attribute_exists(isbn) , same shape
read
a map lookup
 GetItem , strongly consistent if the demo needs read-your-write
list
copy the map into a slice
 Scan  on a two-row table, which is the one call that would need a rethink at real volume
The credential side is the more important half. The showcase has never had an identity; with Pod Identity the service account is bound to a role that allows those five actions on that one table, and that is the entire secret story. This repository already has the pattern: two IRSA roles in  terraform/ , rendered into the manifests by  make deploy , and the  architecture page  on why. If the exercise must be relational, Aurora Serverless v2 with RDS Proxy and a connection string in Secrets Manager works; for four strings keyed by ISBN it is more machinery than the data deserves. The  NoSQL page  has the longer argument for choosing a store by the one question it answers.

What the showcase never had

Four things a course project omits that the AWS mapping fills for free, each one configuration rather than a project:
gap
the AWS piece
the change on the Go side
observability
Container Insights for CPU, memory and probe restarts; CloudWatch Logs through the Fluent Bit add-on; the ALB's access logs to S3
the handlers do not log; a structured logger is the whole change
authentication
the ALB's authenticate-cognito action puts Cognito in front of  POST ,  PUT  and  DELETE  by annotation
none
secrets
none needed after the database change, because Pod Identity replaces credentials; Secrets Manager with the Secrets Store CSI driver for the day a third-party key appears
none
the echo handler
WAF on the ALB can rate-limit  /api/echo 
 api/echo.go  indexes  r.URL.Query()["message"][0]  without a length check; a request with no  message  panics the handler,  net/http  recovers it and drops the connection, and the log fills with  http: panic serving . The bounds check is one line and belongs in the course
There is also a repository defect that comes before any of this. The source imports  github.com/PacktPublishing/Cloud-Native-Go/api , the upstream course path rather than the fork's, and there is no  go.mod , so the build only works inside a  GOPATH  laid out to match. Add the module file and fix the import first; nothing on AWS helps with that.

What the mapping says

The title oversells and the source is honest about it. One Go service, one in-memory map, and a README whose Approach section says exactly that. As a ladder from  go build  to  rollout undo  it is clean, with probes, limits and a rollout strategy that many production manifests lack. As a "MicroServices" bookstore there is nothing to map. This page mapped the ladder.
The first port is to Kubernetes 1.16, not to AWS. Both manifests use an API group gone since 2019 and the base image stopped receiving patches the same year. Every AWS piece above assumes the two-file edit at the top of this page has been done.
This repository is the showcase's target state, minus the database. ECR, EKS, the Ingress-provisioned ALB and IRSA are what  make infra push deploy  builds here, and the whereami service is the same shape as the bookstore without the map. The rung the showcase lacks, DynamoDB behind six functions and one role, is the rung this repository has also not climbed, and for the same reason: the demo service is stateless on purpose. The  target architecture  is where the data band gets argued.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article