Skip to content

End-to-end CI/CD pipeline for Java web applications using AWS CloudFormation, CodeArtifact, CodeBuild, CodeDeploy, CodePipeline, S3, EC2, and IAM. Features infrastructure as code, automated build and deployment, and comprehensive monitoring.

License

Notifications You must be signed in to change notification settings

Heeyaichen/aws-web-app-devOps

Repository files navigation

AWS Web Application DevOps Pipeline

A complete CI/CD pipeline for Java web applications using AWS DevOps services.

Overview

This project demonstrates a complete DevOps pipeline for a Java web application using AWS services. It includes infrastructure as code (CloudFormation), build and deployment automation, and a sample Java web application.

This project was inspired by NextWork's 7-Day DevOps Challenge. While following a similar architectural approach, this implementation includes additional automation through shell scripts, enhanced CloudFormation templates, and a customized web application.

Image

Table of Contents

Architecture

The architecture consists of three main components:

  1. Build Infrastructure - Core resources for building applications
  2. CI/CD Pipeline - Complete CI/CD pipeline configuration
  3. Deployment Environment - Target environment for application deployment

AWS Services Used

Service Purpose Documentation
AWS IAM Identity and access management IAM Documentation
AWS CloudFormation Infrastructure as code CloudFormation Documentation
AWS CodeArtifact Artifact repository CodeArtifact Documentation
AWS CodeBuild Continuous integration CodeBuild Documentation
AWS CodeDeploy Automated deployment CodeDeploy Documentation
AWS CodePipeline CI/CD orchestration CodePipeline Documentation
Amazon S3 Storage for artifacts S3 Documentation
Amazon EC2 Compute for deployment EC2 Documentation
AWS CodeStar Connections GitHub integration Connections Documentation

Prerequisites

  • AWS Account with administrative access
  • AWS CLI installed and configured
  • Git installed
  • Java 8+ installed
  • Maven installed
  • jq installed (for cleanup script)

Project Structure

aws-web-app-devOps/
├── cloudformation-templates/       # CloudFormation templates
│   ├── build-infra-stack.yaml      # Build infrastructure resources
│   ├── cicd-pipeline-stack.yaml    # CI/CD pipeline configuration
│   ├── deployment-server-stack.yaml # Deployment environment
│   └── README.md                   # CloudFormation documentation
├── scripts/                        # Deployment scripts
│   ├── install_dependencies.sh     # Install Apache and configure proxy
│   ├── start_server.sh            # Start application services
│   ├── stop_server.sh             # Stop application services
│   ├── validate_service.sh        # Validate deployment
│   └── README.md                   # Scripts documentation
├── src/                            # Java web application source code
├── appspec.yml                     # AWS CodeDeploy specification
├── bootstrap.sh                    # Automated deployment script
├── buildspec.yml                   # AWS CodeBuild specification
├── delete_stacks.sh               # Cleanup script
├── local_dev.sh                   # Local development script
├── pom.xml                        # Maven project configuration
└── settings.xml                   # Maven settings for CodeArtifact

Getting Started

AWS Account Setup

  1. Create an IAM User with Admin Access:

    • Go to IAM Console
    • Create a new user with programmatic access
    • Attach the AdministratorAccess policy
    • Save the access key and secret key
  2. Configure AWS CLI:

    aws configure

Local Development

  1. Clone the repository:

    git clone https://github.com/yourusername/aws-web-app-devOps.git
    cd aws-web-app-devOps
  2. Run the application locally:

    ./local_dev.sh
  3. Access the application: Open your browser and navigate to http://localhost:8090/nextwork-web-project/

Deployment

The entire deployment process is automated using the bootstrap.sh script:

./bootstrap.sh

This script will:

  1. Deploy the deployment server stack
  2. Create or use an existing GitHub connection
  3. Deploy the build infrastructure stack
  4. Deploy the CI/CD pipeline stack
  5. Start the pipeline execution

During the process, you'll need to authorize the GitHub connection when prompted.

CI/CD Pipeline

The CI/CD pipeline consists of three stages:

  1. Source: Fetches code from GitHub repository
  2. Build: Builds the application using CodeBuild
    • Uses Maven with CodeArtifact integration
    • Packages the application as a WAR file
  3. Deploy: Deploys to EC2 instance using CodeDeploy
    • Installs dependencies
    • Deploys the WAR file to Tomcat
    • Configures Apache as a proxy
    • Validates the deployment

Monitoring and Troubleshooting

Checking Pipeline Status

  1. Go to AWS CodePipeline Console
  2. Select the nextwork-devops-cicd pipeline
  3. View the current status and history

Accessing the Application

After successful deployment, access the application using the EC2 instance's public DNS:

  1. Go to AWS EC2 Console
  2. Find the instance with the tag role: webserver
  3. Use the Public DNS or IP address in your browser

Common Issues

  • GitHub Connection: Ensure the GitHub connection is authorized
  • Build Failures: Check CodeBuild logs for Maven errors
  • Deployment Failures: Check CodeDeploy logs and EC2 instance logs
  • Application Not Accessible: Verify security group settings and service status

Cleanup

To delete all resources created by this project:

./delete_stacks.sh

This script will:

  1. Empty & delete all S3 buckets
  2. Delete the CI/CD pipeline stack
  3. Delete the build infrastructure stack
  4. Delete the deployment server stack

Future Enhancements

Security Improvements

  • Network Security:
    • Replace open security group rules (0.0.0.0/0) with restricted CIDR blocks
    • Implement AWS WAF with CloudFront for edge protection
    • Configure TLS termination at load balancer level
    • Migrate from HTTP to HTTPS with proper certificates
  • Monitoring & Detection:
    • Set up CloudWatch alarms for unusual traffic patterns
    • Enable AWS GuardDuty for threat detection
    • Implement AWS Config for compliance monitoring

Application Enhancements

  • Architecture Upgrade:
    • Migrate to Spring Boot framework with layered architecture
    • Implement RESTful API endpoints
    • Add database connectivity with Amazon RDS
    • Implement user authentication with Amazon Cognito

Infrastructure Improvements

  • High Availability:
    • Deploy across multiple Availability Zones
    • Implement Auto Scaling for EC2 instances
    • Add Elastic Load Balancing for traffic distribution
  • Containerization:
    • Migrate to container-based deployment with Amazon ECS/EKS
    • Implement Docker for consistent environments
    • Add container security scanning

CI/CD Enhancements

  • Testing:
    • Add automated unit and integration testing
    • Implement code quality gates with SonarQube
    • Add security scanning with OWASP dependency checks
  • Deployment Strategy:
    • Implement blue/green deployment strategy
    • Add canary releases for gradual rollout
    • Configure automated rollbacks based on health checks

About

End-to-end CI/CD pipeline for Java web applications using AWS CloudFormation, CodeArtifact, CodeBuild, CodeDeploy, CodePipeline, S3, EC2, and IAM. Features infrastructure as code, automated build and deployment, and comprehensive monitoring.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published