How to Deploy NodeJS App on AWS EC2 Instance using Terraform, Ansible & Docker | DevOps tutorials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
terraform apply press enter so let's copy the IP address and paste it into the browser colon 3000 press enter so you can see in one click we can deploy our node.js application into the ec2 installs hello everyone welcome to my YouTube channel in the today's video we will see how we can deploy our node.js app on the AWS ec2 installs with the help of terraform and NC world so let's start with the video so for this video we need a terraform and unstable install on our machine so if you don't have terraform and NC will installed on your machine so then you can go to my YouTube channel where I have created a video on how to install a terraform in Mac OS so or you can follow the official documentation so from where you can download and install the terraform and civil so I already have terraform so you can check the version so I have 1.4.6 version of terraform and we can check the ansible also so as you can see and civil is already installed so let's move on to the first part so this is the sample node.js app which I have created so I have used Express framework so we will deploy this application onto the ec2 installs so for this project I have created a Docker file so using this file this file will create the docker image for the node.js app and this app will run in the docker container so in this file you can see we have used node 16 Alpine version and we have set the working directory to app folder and then we have copy the package.json file into the working directory and then we have installed the dependencies and then copy the rest of the files and then we have exposed our 3000 port on which our node.js application is listening after that we have used a command npm start so this command will run the app into the container I already uploaded this app onto GitHub so you can check it out so this is the repository node.js demo where you can find the app.js file and the docker file so we will use this repository into the ansible configuration file next I have created a terraform file which will create the AC to installs and set up all the infrastructure on the AWS account so this is the main terraform file so as you can see we have required to provide us AWS provider and then we have initialized the provider so for initialization we need access key and secret key so let's go to uh AWS account so this is my AWS account let's create a new user demo user attach existing policy select administrator access click on next and create user so then click on the demo user go to the security credentials create access key select the first option command line interface I understand the work configuration recommendation so this is the description so this is the access key and secret key copy the access key and paste it here copy the secret key and paste it so in this way we can initialize the AWS provider so in this block we are creating a pem file or a private key and we will use this private key to generate our AWS key pair and then we are storing the private keypam file into our local machine as well next we have created a security group in the security group we have opened 22 port and 3000 port and we have opened all traffic for the outgoing so in this block we are creating the AWS instance so here I am using the ubuntu's image and I am using the instance type T2 micro so here I am assigning the key pair which I have already created and uh here I am assigning the security group so in this block I have called The ansible Playbook so once the install says launched so this command will execute so let's see the ncle file configuration which we have created Docker installed so in this file we have created some tasks so the first task is update the actor Repository so next command is install the docker dependencies so next we have installed the docker compose next we will clone the node.js app from the other Repository so this is the URL for the node.js app and this is the destination folder where our node.js app will clone next we will build the docker image using the docker file which is already present in the node.js app next we will run the docker image which we have created into the docker container so this is the NCL file so as you can see I have used this file Docker install Dot yml in that and civil Playbook so this is the IP of the AWS instance which we have created so we have specified user Ubuntu and then the private key so this is the location where our private key will be generated and this is the file name of the Prime file so let's deploy our node.js application so first go to the folder so as you can see these are the file so first we have to initialize the terraform so we can use command terraform init so this will install the required dependencies which we have specified in that terraform file so this is done so to check the plan we can use command terraform plan so here we have to enter the name of the Pam file foreign so this is the plan so as you can see this is the AWS installs we are creating we will be using the ubuntu's image installs type T2 micro Prime file code Circle and so on so this is the key pair we are generating and this is the security group to run this file we can use command terraform apply so this command will create the AC roon stance first on the AWS and then this will install the docker and clone the application node.js application and then this will run the application into the docker container press enter the name of Pam file say code Saga press enter enter yes and press enter so you can see this is creating easy to installs let's go to our AWS account search for ec2 click on instances where you can see one easy to install is created currently it's in initializing state so here we are getting some issue so the path we have provided for the Pam file which is not correct so let's change this path so get the latest path so copy this path and paste it here so let's just try first so this will delete the easy to install which we have just created so you can see so let's apply again press enter code Sagar and then yes so this will create a new AC roon stance it's going stance is creating and civil file is executing installing Docker current dependencies install Docker compose cloning the node.js app building the image running documenting so that's all so let's copy the IP address and paste it into the browser colon 3000 because our application is running on 3000 port press enter so as you can see in one click we can deploy our node.js application into the AC to install in the next video we will use the Jenkins and we will use a sub domain instead of this IP so hope you like this video if you are getting any issues or any error so you can comment in the comment section I will love to reply so if you like this content please subscribe to my YouTube channel for more such videos thanks for watching
Info
Channel: Code Sagar
Views: 1,981
Rating: undefined out of 5
Keywords:
Id: alAZl5udvAI
Channel Id: undefined
Length: 11min 20sec (680 seconds)
Published: Sun Jun 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.