Skip to content

Hi, I have a Spring Boot backend and PostgreSQL database running locally using Docker Compose. The setup includes: - Spring Boot backend (Java 17) - PostgreSQL 15 - Dockerfile for backend

0
  1. Which AWS service is best for this setup (EC2, ECS, Elastic Beanstalk)?
  2. How can I deploy Docker Compose on AWS step by step?
  3. Are there any Free Tier limitations I should be careful about?
  4. How can I expose my backend securely (port, security group, HTTPS)?

Any guidance or best practices would be very helpful.

Thank you.

1 Answer
0

Deploying Spring Boot and PostgreSQL with Docker Compose on AWS

1. Best AWS Service for Your Setup

Elastic Beanstalk is likely the best option for your Spring Boot and PostgreSQL Docker Compose setup. It provides a managed platform that handles infrastructure provisioning, capacity management, load balancing, and automatic scaling while allowing you to focus on your application code. Elastic Beanstalk has built-in support for Docker Compose applications, making it ideal for your use case.

Alternatives:

  • EC2: Gives you full control but requires manual configuration and management
  • ECS: Good for container orchestration but has a steeper learning curve than Elastic Beanstalk

2. Deploying Docker Compose on AWS Step by Step

  1. Install the Elastic Beanstalk CLI on your local machine

  2. Prepare your application:

  • Ensure your docker-compose.yml file is in the root directory of your project
  • Make sure your Dockerfile for the Spring Boot application is properly configured
  1. Initialize your EB CLI repository:
eb init -p docker your-application-name --region your-region
  1. Configure SSH access (optional):
eb init

Follow the prompts to set up SSH for your instances

  1. Create an environment and deploy:
eb create your-environment-name

Elastic Beanstalk will detect your docker-compose.yml file and deploy your multi-container application

  1. Monitor deployment:
eb status your-environment-name
  1. Open your application (if it's a web application):
eb open your-environment-name

3. Free Tier Limitations

Be careful about:

  • EC2 instances: Free tier typically includes 750 hours per month of t2.micro or t3.micro instances
  • RDS for PostgreSQL: Consider using RDS instead of containerized PostgreSQL for production. Free tier includes 750 hours of db.t2.micro or db.t3.micro
  • S3 storage: Used by Elastic Beanstalk for application versions (5GB free)
  • Data transfer: Monitor outbound data transfer as it can incur costs
  • Elastic Load Balancer: Not included in free tier and will incur charges

For development, consider turning off non-production resources when not in use to maximize free tier usage.

4. Exposing Your Backend Securely

  1. Port Configuration:
  • Configure your Spring Boot application to run on port 8080 inside the container
  • Map this to port 80 or 443 in your docker-compose.yml
  1. Security Groups:
  • Restrict inbound traffic to only necessary ports (80/443 for HTTP/HTTPS)
  • For the database, only allow access from your application's security group
  1. HTTPS Implementation:
  • Use AWS Certificate Manager (ACM) to provision a free SSL certificate
  • Configure your load balancer to terminate SSL and forward traffic to your application
  • Set up a listener on port 443 with your SSL certificate
  1. Additional Security Measures:
  • Implement proper authentication and authorization in your Spring Boot application
  • Use environment variables for sensitive information like database credentials
  • Consider using AWS Secrets Manager for managing secrets

For a production environment, consider using an Application Load Balancer in front of your Elastic Beanstalk environment to handle HTTPS termination and routing.
Sources
Cost-Effective Deployment of Angular + Spring Boot + PostgreSQL Application on AWS | AWS re:Post
Migrating to Elastic Beanstalk Docker running on Amazon Linux 2 from Multi-container Docker running on Amazon Linux - AWS Elastic Beanstalk
QuickStart: Deploy a Docker Compose application to Elastic Beanstalk - AWS Elastic Beanstalk

answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Relevant content