Deploying Node JS service to AWS EC2 using Github Actions #32 for Microservices. Keep it simple and SEO-friendly.

Microservices deployment with GitHub Actions is like orchestrating a digital symphony. ๐ŸŽถ The checkout action sets the stage, followed by the setup node action tuning the instruments (Node.js). The push action takes center stage, copying the code to an AWS EC2 instance, guided by the SSH deploy action, ensuring a seamless performance. Finally, the deploy action gracefully restarts the server, concluding the symphony. ๐Ÿš€

Key Takeaways ๐Ÿš€

  • Deploying Node.js microservices to AWS EC2 servers using GitHub Actions streamlines the workflow for developers.
  • GitHub Actions automate the process of creating workflows and deployment pipelines.
  • Actions allow for the creation of jobs to check dependencies, run tests, evaluate coverage, and execute migrations.
  • Predefined actions such as checkout, setup-node, and deploy simplify the setup and execution of tasks.
  • Utilizing GitHub Secrets ensures the secure configuration of runtime environment variables.
  • Workflow files, organized within the .github/workflows directory, specify the sequence of actions to be executed.
  • Each workflow file, such as setup.yml, test.yml, or deploy.yml, can isolate specific steps for clarity and efficiency.
  • Actions handle tasks like copying code to remote servers (e.g., EC2 instances) using SCP commands, eliminating the need for manual intervention.
  • Deployment scripts, such as, facilitate the process of restarting servers and updating applications seamlessly.
  • GitHub Runners execute workflows, enabling efficient code testing, deployment, and management.

๐Ÿ› ๏ธ Setup and Workflow

๐Ÿ›’ Checking Dependencies

The workflow begins with the checkout action, fetching the latest code from the repository.

  • Installation of node.js and npm dependencies is automated using the setup-node action.

๐Ÿงช Testing and Building

  • Executing npm commands, including npm install and npm run build, ensures code compilation and readiness for deployment.

๐Ÿš€ Pushing to Remote Servers

๐Ÿ“ฆ Copying Code to EC2 Instances

  • GitHub Actions streamline the process of copying code to remote servers, requiring only essential details like private keys and host information.

๐Ÿš€ Deploying Applications

  • Deployment actions involve SSHing into remote instances and executing shell scripts to restart servers and update applications seamlessly.

๐Ÿ’ก Pro Tips

  • Leverage GitHub Secrets for securely storing sensitive information like access keys and private SSH keys.
  • Organize workflows into separate YAML files for clarity and ease of maintenance.
  • Utilize predefined actions to automate common tasks like code checkout, setup, and deployment.
  • Ensure global installation of necessary tools like pm2 for seamless execution of deployment scripts.

๐ŸŒŸ Conclusion

GitHub Actions empower developers to automate the deployment of Node.js microservices to AWS EC2 servers effortlessly. By leveraging predefined actions and secure configurations, teams can streamline their CI/CD pipelines, enhancing productivity and code quality.


Q: Can GitHub Actions be used with other cloud providers?
A: Yes, GitHub Actions are versatile and can be adapted to deploy applications on various cloud platforms, including AWS, Azure, and Google Cloud.

Q: Are there limitations to the size of projects that can benefit from GitHub Actions?
A: GitHub Actions are suitable for projects of all sizes, from small-scale microservices to large enterprise applications. The modular and customizable nature of actions allows for flexibility in workflow design.

Q: How can I troubleshoot deployment issues with GitHub Actions?
A: GitHub Actions provide detailed logs for each workflow step, enabling developers to identify and address any issues promptly. Additionally, thorough testing and validation of deployment scripts can help prevent potential errors during execution.

About the Author

Code with tkssharma
22.1K subscribers

About the Channel๏ผš

@tkssharma Welcome to my channel Code with tkssharma Learn Geek stuff [Angular, Nest JS, Sveltekit, React, Sveltekit, Next JS, Redux, Nodejs, Nest JS, Web Development, Docker, AWS, Vue JS, All about Javascript]Hi, I’m Tarun – a full-stack software developer from India (having 12 years of working experience). I build open-source projects and write about modern JavaScript, Node.js, design, and web development. If you like my stuff Please subscribe to My channel and Fell free to hit One-click unsubscribe anytime. I have 2000 youtube videos on the latest technologies.โญ๏ธโญ๏ธ Watch all my Playlist 100+ playlistsโญ๏ธ Support my channelโญ๏ธ โญ๏ธ GitHub link for Reference โญ๏ธ โญ๏ธ Covering full stack clone apps โญ๏ธ covering all about javascript client side & server side โญ๏ธ Like, Share my work
Share the Post: