Deploying Applications on Amazon EC2: A Hands-On Tutorial


Amazon EC2 (Elastic Compute Cloud) is one of the most widely used services in the AWS ecosystem. It offers scalable virtual servers in the cloud. This tutorial provides a practical, step-by-step guide to deploying applications on EC2, from launching an instance to accessing your application in the browser.


Step 1: Launching an EC2 Instance

  1. Navigate to the EC2 Dashboard on the AWS Console.

  2. Click on "Launch Instance" and choose an Amazon Machine Image (AMI), such as Amazon Linux 2 or Ubuntu.

  3. Select an instance type, such as t2.micro, for free tier eligibility.

  4. Configure instance details:

    • Set several instances.

    • Configure network and subnet.

  5. Add storage and tags (e.g., Name=MyWebApp).

  6. Create or select a key pair for SSH access.

  7. Configure security group:

    • Allow inbound SSH (port 22) and HTTP (port 80).

Click "Launch" to spin up the instance.


Step 2: Connect to Your Instance

Use SSH to connect from your local machine:


ssh -i my-key.pem ec2-user@your-public-ip


Replace my-key.pem and your-public-ip with your actual file and instance details.


Step 3: Install Your Application Dependencies

Install web server software, languages, or runtimes. For example, to deploy a Node.js app:


sudo yum update -y

curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -

sudo yum install -y nodejs git



Step 4: Deploy the Application

Clone your application or upload files manually:


git clone https://github.com/your-repo/your-app.git

cd your-app

npm install


Start the app (e.g., with pm2, node, or npm start):


node app.js


Ensure your application is bound to 0.0.0.0 so it’s accessible from outside.


Step 5: Configure Security and Access

Ensure your security group allows inbound traffic on the application port (e.g., port 80 or 3000).

Use the public IP address or public DNS to access the application in your browser:


http://your-ec2-public-ip:3000



Optional Enhancements

  • Use Elastic IP to ensure a static public IP.

  • Install Nginx or Apache as a reverse proxy.

  • Enable SSL with Let's Encrypt.

  • Use Amazon CloudWatch to monitor app performance.

  • Automate deployment with AWS CodeDeploy or GitHub Actions.


Conclusion

Deploying applications on Amazon EC2 gives you complete control over your environment. While EC2 offers flexibility and power, it balances manual setups with scalability needs by exploring services like ECS, EKS, or AWS Elastic Beanstalk for containerized and automated deployments.


Comments

Popular posts from this blog

Podcast - How to Obfuscate Code and Protect Your Intellectual Property (IP) Across PHP, JavaScript, Node.js, React, Java, .NET, Android, and iOS Apps

AWS Console Not Loading? Here’s How to Fix It Fast

YouTube Channel