Deploy and Expose Your First App to AWS EC2

Deploy and Expose Your First App to AWS EC2

Introdction

Deploying applications to the cloud is a crucial skill in today’s tech landscape. In this blog, we’ll walk through the process of deploying a simple Node.js application to AWS EC2, By the end, you’ll know how to take your app from local development to being accessible on the internet.

1. Setting Up AWS EC2

AWS EC2 (Elastic Compute Cloud) enables you to set up virtual servers in the cloud. Start by creating an AWS account and accessing the EC2 dashboard. Choose an Ubuntu operating system and a T2 micro instance (suitable for small projects and eligible under AWS’s free tier).

2. Cloning the Application Repository

After launching your EC2 instance, connect via SSH. Use the git clone <repository-url> command to clone your application’s codebase from GitHub. This step brings your project files to the remote server.

3. Preparing the Environment

Create a .env file to manage sensitive configuration details like API keys securely. Environment variables allow you to decouple sensitive data from your application code, making it easier to maintain security.

4. Installing Dependencies

Navigate to your project directory and run npm install to install all dependencies listed in your package.json file. This ensures your app has all necessary libraries to run.

5. Configuring Security Groups

Security groups act as firewalls for your EC2 instance. Update inbound rules to allow traffic on the port your application will run (e.g., port 3000). This configuration makes your app accessible via the public IP address assigned to your instance.

6. Running and Exposing the Application

Start your Node.js application with npm run start and test it by visiting the public IP address in your browser. Ensure your security group settings are correctly configured to avoid connectivity issues.

7. Why This Matters

Deploying applications to the cloud demonstrates your ability to scale projects, collaborate effectively, and manage infrastructure. Whether you're working on personal projects or enterprise-level solutions, these skills are essential in the DevOps toolkit.

Conclusion

This hands-on experience bridges the gap between local development and cloud deployment, making you one step closer to mastering DevOps. Share your progress, and let’s grow together on this #100DaysOfDevOps journey!