DEV Community

Harshit Singh
Harshit Singh

Posted on

Mastering AWS: Step-by-Step Guide to Deploying a Full-Stack React + Java Spring Boot App

AWS can feel like a labyrinth, but don’t worry—we’ll navigate it together. This guide takes you step-by-step through deploying a modern React + TailwindCSS + TypeScript frontend and a Java Spring Boot backend with SQL and NoSQL databases . By the end, your app will be running live, scalable, and secure in the AWS cloud.


1. Setting Up AWS: Preparing for Deployment 1.1. Creating Your AWS Account

  1. Head to AWS Signup .

  2. Create an account with billing enabled.

  3. Opt for Free Tier , but note some services may incur costs (we’ll mention where).
    1.2. IAM: Who Gets What Access

  4. Why: To secure your AWS environment by controlling access.

  • How:
    1. Open the IAM Management Console .
  1. Create a new IAM user:
    • Name: DevUser.
- Assign **AdministratorAccess**  policy (for now).
Enter fullscreen mode Exit fullscreen mode
  1. Set up Multi-Factor Authentication (MFA) for added security.

2. Building the Frontend: Static Hosting Done Right 2.1. Hosting React Static Files on S3

  1. What to Do: Build your React app using Vite:
npm run build
Enter fullscreen mode Exit fullscreen mode

This creates a dist/ directory containing your static files.

  1. S3 Setup:
    • Go to S3 ConsoleCreate Bucket .
  • Bucket Name: my-react-app.

  • Enable public access for static hosting:

    • Under Permissions , uncheck "Block all public access."
    • Add a Bucket Policy :
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "PublicReadGetObject",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::my-react-app/*"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode
  • Enable Static Website Hosting in Properties :

    • Index document: index.html.
    • Error document: 404.html. 2.2. Configuring CloudFront
    • Why: To cache and serve your app globally with HTTPS.
  1. How:
    • Open the CloudFront ConsoleCreate Distribution .
  • Origin: Select your S3 bucket.

  • Enable SSL/TLS using AWS Certificate Manager .

  • Route traffic from https://www.myapp.com to this CloudFront distribution.


3. Backend Hosting: Spring Boot on AWS 3.1. EC2 Instance for Backend

  1. Launch EC2 Instance:
    • Go to EC2 ConsoleLaunch Instance .
  • Select Amazon Linux 2 AMI (or Ubuntu).

  • Instance Type: t2.micro (Free Tier eligible).

  • Key Pair: Create or use an existing one for SSH access.

  • Configure Security Group:

    • Allow inbound traffic on port 8080 (for backend APIs).
  • Launch the instance.

  1. Install Java and Deploy Spring Boot:
    • SSH into your instance:
ssh -i my-key.pem ec2-user@<ec2-instance-public-ip>
Enter fullscreen mode Exit fullscreen mode
  • Install Java:
sudo yum update -y
sudo amazon-linux-extras enable corretto8
sudo yum install java-1.8.0-amazon-corretto -y
Enter fullscreen mode Exit fullscreen mode
  • Deploy your app:
java -jar your-springboot-app.jar
Enter fullscreen mode Exit fullscreen mode

3.2. Load Balancing with ALB

  1. Why: To ensure availability and distribute traffic across multiple EC2 instances.

  2. How:

    • Go to EC2 ConsoleLoad BalancersCreate Application Load Balancer .
  • Configure:

    • Listener: HTTP (port 80).
    • Target Group: Add your EC2 instance(s).
  • Route traffic from the ALB DNS to your backend.


4. Database Configuration: RDS and DynamoDB 4.1. Relational Database with RDS

  1. Go to RDS ConsoleCreate Database .

  2. Select:

  • Database Type: PostgreSQL (or MySQL/OracleDB).

  • Instance Class: db.t2.micro (Free Tier eligible).

  • Multi-AZ Deployment: Optional for production.

  1. Note the endpoint, username, and password.

  2. Connect Spring Boot:
    Update application.properties:

spring.datasource.url=jdbc:postgresql://<rds-endpoint>:5432/yourdb
spring.datasource.username=<username>
spring.datasource.password=<password>
Enter fullscreen mode Exit fullscreen mode

4.2. NoSQL with DynamoDB

  1. Go to DynamoDB ConsoleCreate Table .
    • Table Name: UserDetails.
  • Partition Key: UserId.
  1. Use AWS SDK to interact with DynamoDB from your backend.

5. Logging and Monitoring 5.1. CloudWatch for Logs

  1. Install the CloudWatch Agent:
sudo yum install amazon-cloudwatch-agent
Enter fullscreen mode Exit fullscreen mode
  1. Configure CloudWatch in Spring Boot:
    • Add logback configuration :
<appender name="CLOUDWATCH" class="com.amazonaws.services.logs.logback.CloudWatchAppender">
  <logStreamName>SpringBootApp</logStreamName>
  <logGroup>BackendLogs</logGroup>
</appender>
Enter fullscreen mode Exit fullscreen mode

5.2. Alarms and Tracing

  • Set up CloudWatch Alarms for CPU usage, memory, etc.

  • Use X-Ray for distributed tracing across microservices.


6. Automating Deployments: CI/CD with AWS 6.1. CodePipeline + CodeBuild

  1. CodePipeline Setup:
    • Source: Connect to GitHub or CodeCommit.
  • Build: Add a CodeBuild project.

  • Deploy: Use S3 (frontend) and EC2 or Elastic Beanstalk (backend).

  1. CodeBuild Example Buildspec:
version: 0.2
phases:
  install:
    commands:
      - npm install
      - mvn clean install
  build:
    commands:
      - npm run build
      - mvn package
  post_build:
    commands:
      - aws s3 sync dist/ s3://my-react-app/
Enter fullscreen mode Exit fullscreen mode

7. DNS and Domain Management

  1. Route 53 for Custom Domain:
    • Register a domain (or use an existing one).
  • Create DNS records:

    • A Record: Point to CloudFront (frontend).
    • CNAME: Point to ALB (backend).

8. Testing and Scaling

  1. Use AWS Load Testing Tool for performance.

  2. Enable Auto Scaling Groups for EC2 instances.


AWS gives you superpowers , but with great power comes great responsibility. By following this guide, your project will be live, secure, and ready to scale at the speed of your users. Now, go forth and deploy like a cloud ninja!


Things To Keep In Mind: This Article is not a exact solution. You may face other difficulties along the way. What i tried to do is to create and enlighten the path of How AWS and its powers can be anchored to deploy your project over the clouds. Even after reading and gathering knowledge from this article, and still You Face any problem or you would like to discuss things further more DO WRITE A COMMENT or CONNECT WITH ME OVER OTHER SOCIAL PLATFORMS*. You can also **Email me*.

SOCIALS:

INSTAGRAM :: @___kunwar___ & @witted.tech
X || Twitter :: @harshitsinghHS

Top comments (1)

Collapse
 
plzbugmenot profile image
Jason Smith

Good.