Deploying to the Cloud

Options

OptionGood forYou manage
Linux VM (AWS EC2, GCP Compute Engine)learning, small apps, full controlOS, Java, Nginx, TLS, restarts
Render / Railwaystudent projects, demosalmost nothing (connect GitHub)
AWS Elastic Beanstalk / App Runner, Google Cloud Runproduction without Kubernetescontainer image, config
Kubernetes (EKS, GKE)many services, big teamscluster, manifests (see Microservices)

On a Linux VM with systemd

Example

/etc/systemd/system/shopease.service

[Unit]
Description=ShopEase API
After=network.target

[Service]
User=shopease
WorkingDirectory=/opt/shopease
EnvironmentFile=/etc/shopease/shopease.env
ExecStart=/usr/bin/java -XX:MaxRAMPercentage=75 -jar /opt/shopease/shopease.jar
SuccessExitStatus=143
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Example

scp target/shopease-1.0.0.jar deploy@shopease-vm:/opt/shopease/shopease.jar
ssh deploy@shopease-vm "sudo systemctl daemon-reload && sudo systemctl restart shopease && systemctl is-active shopease"
curl -s https://api.shopease.in/actuator/health

Example output

active
{"status":"UP"}

Tip: Put Nginx (or Caddy) in front for HTTPS with a free Let's Encrypt certificate and proxy to localhost:8080. Set server.forward-headers-strategy=framework so Spring sees the real client IP and https scheme.

On Render (Free Tier Demo)

  1. Push the project with the Dockerfile to GitHub.
  2. Render → New → Web Service → pick the repo; it detects the Dockerfile.
  3. Add environment variables: SPRING_PROFILES_ACTIVE=prod, SPRING_DATASOURCE_URL, user, password (use a managed PostgreSQL or MySQL).
  4. Render passes PORT: set server.port=${PORT:8080}.
  5. Each push to main redeploys automatically.

On AWS

Example

A common simple setup: image in ECR, run on App Runner, database on RDS:

aws ecr create-repository --repository-name shopease
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.ap-south-1.amazonaws.com
docker tag shopease:1.0.0 123456789012.dkr.ecr.ap-south-1.amazonaws.com/shopease:1.0.0
docker push 123456789012.dkr.ecr.ap-south-1.amazonaws.com/shopease:1.0.0

Example output

Login Succeeded
1.0.0: digest: sha256:4f7a...c21e size: 2412

Note: Store the database password in AWS Secrets Manager (or GCP Secret Manager) and inject it as an environment variable. Never commit it to Git.