Deploying an Web Application that uses MySQL Database on AWS
Deploying a JSP Application with MySQL to AWS
Deploying a JSP application with a MySQL backend to AWS involves coordinating three main components: the RDS database, MySQL Workbench for schema migration, and Elastic Beanstalk for application hosting.
Step 1: Create the AWS RDS MySQL Instance
Before deploying the code, the database must be provisioned and ready to accept connections.
- Launch RDS: Navigate to the RDS Dashboard in the AWS Console and click Create Database.
- Configuration:
- Engine: Select MySQL.
- Template: Select Free Tier (if applicable) or Dev/Test.
- Settings: Set a DB Instance Identifier, Master Username, and Master Password.
- Connectivity: Set Public Access to Yes. This is a temporary measure so your local MySQL Workbench can reach the instance from outside the VPC.
- Finish: Once the status is "Available," copy the Endpoint (e.g.,
mydb.cxyz.us-east-1.rds.amazonaws.com).
Step 2: Migrate Schema using MySQL Workbench
Use your local client to move your existing database structure to the cloud instance.
- Connect to RDS: Create a new connection in MySQL Workbench using the RDS Endpoint as the Hostname.
- Security Rule: If the connection fails, ensure the RDS Security Group has an Inbound Rule for Port 3306 with your "My IP" as the source.
- Migration: Use the Database > Migration Wizard to select your local MySQL as the Source and the RDS instance as the Target. Follow the steps to execute the schema creation.
Step 3: Prepare the JSP Application
Your application must be configured to read database connection details from Environment Variables rather than hardcoded strings.
Update yourDriverManager.getConnection()or Data Source configuration to useSystem.getenv("RDS_HOSTNAME").
Finally, package your project into a .war (Web Application Archive) file.
Step 4: Deploy to Elastic Beanstalk
- Create Environment: In the Elastic Beanstalk console, click Create Application and select Tomcat as the platform.
- Application Code: Upload the .war file you generated in Step 3.
- Configuration: Under Software Configuration, add the following Environment Properties:
RDS_HOSTNAME: Your RDS EndpointRDS_PORT: 3306RDS_DB_NAME: Your database nameRDS_USERNAME: Your Master UsernameRDS_PASSWORD: Your Master Password
- Final Security Link: In the RDS Security Group, add an Inbound Rule for port 3306 and set the Source to the Security Group ID of your Elastic Beanstalk environment.