,

Tutorial: How to Use GitHub Actions to Automatically Deploy Node.js to AWS

Posted by






GitHub Actions Automate Node.js Deployment to AWS | GitHub Actions Tutorial

GitHub Actions Automate Node.js Deployment to AWS

Welcome to our GitHub Actions tutorial where we will show you how to automate the deployment of a Node.js application to AWS using GitHub Actions.

What are GitHub Actions?

GitHub Actions is a feature of GitHub that allows you to automate your software development workflows. It enables you to build, test, and deploy your code directly from your GitHub repository.

Setting up GitHub Actions for Node.js Deployment

To get started, follow these steps:

  1. Create a GitHub repository for your Node.js application if you haven’t already.
  2. Add a workflow file to your repository under the .github/workflows directory. You can name this file deploy.yml.
  3. Open the deploy.yml file and add the necessary job steps to build and deploy your Node.js application to AWS.

Example deploy.yml file

        
name: Deploy to AWS

on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Setup Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '14'

    - name: Install dependencies
      run: npm install

    - name: Build and deploy to AWS
      run: |
        # Replace this with your actual deployment script
        npm run build
        aws s3 sync build/ s3://your-bucket-name
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        
    

Configuring AWS Credentials

In the example deploy.yml file above, we make use of AWS credentials to deploy the Node.js application to an S3 bucket. These credentials should be stored as secrets in your GitHub repository for security purposes.

Conclusion

By following these steps, you will have successfully set up GitHub Actions to automate the deployment of your Node.js application to AWS. This will save you time and effort by eliminating the need for manual deployment processes.


0 0 votes
Article Rating
10 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Rayan Abid
1 year ago

Hi! Thank you so much for such a detailed video.

I did everything but it is failing in handshake and I'm getting this error.

2023/10/14 23:02:39 ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

do you know what might be the issue?

Thank you

Ido Band
1 year ago

Works like a charm! thank you. should I add 'pm2 save' and 'pm2 startup' after 'pm2 restart <id>' to the commands in the yml file?

hades unseen
1 year ago

thanks for sharing you knowledge. saved my day. please keep posting good content

PutiTP
1 year ago

שאלה, כל הדברים שעשית בAWS הם חינמים?
או בתשלום?
תודה על הדרכה מקצועית!

VladokAR
1 year ago

I just would like to say, thank you for the clear explanatio. And now it’s much easier than I thought.

KHUONGPRO OFFICAL
1 year ago

Thank you so much <3

The Stats Lab
1 year ago

what is username: ubuntu ? is it a common username? also is SSH_KEY the key from my local machine ~/.ssh?

The Stats Lab
1 year ago

The best explanation so far! Thank you!

Phaoris
1 year ago

Could you please make a tutorial about deploying a typescript nodejs express GitHub actions AWS EC2 ?
There is no factual tutorial on the internet about this topic!!
I mean, building the project with GitHub actions and send only the dist folder to AWS and launch it there with PM2 start server or something

Thank you for all your informative tutorials 🔥

Avi Whol
1 year ago

Nice! 👍