This project provides a comprehensive guide to deploying a simple web application on AWS EC2 using GitHub, Node.js, and CodeDeploy. The guide includes setting up an EC2 instance, cloning a GitHub repository, installing necessary dependencies, configuring the CodeDeploy agent, and deploying an Express.js application. It also covers creating deployment scripts and setting up AWS CodeBuild for continuous integration to automate the deployment process.
- AWS EC2
- GitHub
- CodeDeploy
- Node.js
- Express.js
- Continuous Integration
- Deployment Scripts
- Web Application
-
SSH into the EC2 Instance
cd Downloads chmod 400 webapp.pem ssh -i "webapp.pem" ec2-user@ec2-184-72-68-27.compute-1.amazonaws.com
-
Clone the GitHub Repository
git clone https://github.com/atulkamble/webapp cd webapp
-
Install Git and Configure User Details
sudo yum install git -y git config --global user.name "Atul Kamble" git config --global user.email "atul_kamble@hotmail.com"
-
Update EC2 Instance and Install Required Packages
sudo yum update -y sudo yum install ruby -y sudo yum install wget -y
-
Install CodeDeploy Agent
cd /home/ec2-user sudo wget https://aws-codedeploy-us-east-2.s3.us-east-2.amazonaws.com/latest/install sudo chmod +x ./install sudo ./install auto sudo service codedeploy-agent start sudo service codedeploy-agent status
-
Set Up the Node.js Application
-
Initialize the Node.js project and install Express:
npm init -y npm install express
-
Create the application file (
app.js
):touch app.js sudo nano app.js
-
Sample
app.js
:const express = require('express'); const app = express(); app.get('/', (req, res) => { res.send('Hello World from EC2!'); }); const port = process.env.PORT || 3000; app.listen(port, () => { console.log(`Server running on port ${port}`); });
-
-
Access the Application
- Open the following in your browser (replace with the actual instance public IP):
http://184.72.68.27:3000/
- Open the following in your browser (replace with the actual instance public IP):
-
Set Up Deployment Scripts
-
Create and edit the
appspec.yml
file:sudo touch appspec.yml sudo nano appspec.yml
-
Create the
install_dependencies.sh
script:sudo touch install_dependencies.sh sudo nano install_dependencies.sh
-
Create the
start_server.sh
script:sudo touch start_server.sh sudo nano start_server.sh
-
Add the changes to Git and push them:
git add . git commit -m "Added appspec.yml and deployment scripts" git push origin main
-
-
Set Up CodeBuild (Optional for CI/CD)
- Create and edit the
buildspec.yml
file:sudo touch buildspec.yml sudo nano buildspec.yml
- Create and edit the
This README.md
outlines all the key steps for deploying the web application using AWS services and GitHub. Let me know if any updates are needed!