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:
- Create a GitHub repository for your Node.js application if you haven’t already.
- Add a workflow file to your repository under the .github/workflows directory. You can name this file deploy.yml.
- 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.
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
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?
thanks for sharing you knowledge. saved my day. please keep posting good content
שאלה, כל הדברים שעשית בAWS הם חינמים?
או בתשלום?
תודה על הדרכה מקצועית!
I just would like to say, thank you for the clear explanatio. And now it’s much easier than I thought.
Thank you so much <3
what is username: ubuntu ? is it a common username? also is SSH_KEY the key from my local machine ~/.ssh?
The best explanation so far! Thank you!
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 🔥
Nice! 👍