🚀 Automate Your Resume Hosting with CI/CD and AWS EC2 🌐
Tags: github, cloud
Published: 2024-07-14 14:25:17

**Introduction:**

_CI/CD is a method used in modern software development to automate the process of integrating code changes, testing them, and deploying applications. This approach ensures that code changes are continuously tested and deployed, leading to faster development cycles and more reliable applications._

_In this project, we utilize CI/CD to host a personal resume website on an EC2 instance using GitHub Actions. By automating the deployment process, any updates made to the resume repository are automatically reflected on the live website. This not only reduces manual effort but also ensures that the resume is always current and available to potential employers or collaborators.By integrating GitHub Actions with AWS, you can achieve continuous deployment, ensuring that any changes made to your resume are automatically reflected online._

_**This article helps you understand how you can automatically deploy your code to AWS EC2 from GitHub**._

**Step-1:** _Launch an EC2 instance with the Ubuntu server. Modify the security group inbound rules to allow SSH (port 22), HTTP (port 80), and HTTPS (port 443)._


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yu81w8nszsovtmm6g6s2.png)

**Step-2:** _Create a public repository on GitHub for example Host-Resume-on-ec2-githubactions._
_Add an index.html file containing the code for your resume website_.
_Add a CSS file for styling your resume_.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mg2ai9vxr2icvy19vr3n.png)

**Step-3:** _Add secrets to the repository for secure information storage._

**EC2_SSH_KEY**: _Your key pair file for SSH access._
**HOST_DNS**: _The public DNS of your EC2 instance._
**USERNAME**: _The username for SSH (e.g., ubuntu)._
**TARGET_DIR**: _The target directory on the EC2 instance (e.g., home)._


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c3xwecblcdmx70g57xe2.png)

**Step-4:** _Create a .github/workflows directory in your repository._
_Add a YAML file (e.g., github-actions-ec2.yml) with the following code to automate deployment_:

_Add the following code so that your actions only run when you push to main branch._


```
# Trigger deployment only on push to main branch
on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: Deploy to EC2 on master branch push
    runs-on: ubuntu-latest

    steps:
      - name: Checkout the files
        uses: actions/checkout@v2

      - name: Deploy to Server 1
        uses: easingthemes/ssh-deploy@main
        env:
          SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }}
          REMOTE_HOST: ${{ secrets.HOST_DNS }}
          REMOTE_USER: ${{ secrets.USERNAME }}
          TARGET: ${{ secrets.TARGET_DIR }}

      - name: Executing remote ssh commands using ssh key
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.HOST_DNS }}
          username: ${{ secrets.USERNAME }}
          key: ${{ secrets.EC2_SSH_KEY }}
          script: |
            sudo apt-get -y update
            sudo apt-get install -y apache2
            sudo systemctl start apache2
            sudo systemctl enable apache2
            cd home
            sudo mv * /var/www/html
```
_Once done with this your workflow will be created and using the public IP address if the EC2 instance you can view the resume._

If any update was done in your main branch you can able to view by refreshing the page.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zos5rbymecmg7qxsdm12.png)

 

**Conclusion:**

_Hosting a resume on an EC2 instance using GitHub Actions combines the power of cloud infrastructure with the automation of CI/CD workflows. This method ensures that your resume is always up-to-date and accessible, demonstrating technical skills and modern development practices. This approach can be extended to various applications, making it a versatile solution for web hosting needs._