how to re deploy a node app on Amazon EC2 - node.js

I deployed a node js app on AWS EC2 amazon linux 2 so now I'm trying to update my project how can I push new changes of node app to EC2

The simplest way I've found for EC2 is to SSH to the machine, then do a git pull from your repo, onto the machine.

Related

Running Node app in Docker container with aws-sdk

Background
I have a node app that essentially needs to use aws-sdk to access S3 bucket and perform other operations. In my local machine I have a .aws config file that sits in ~/.aws/config. I want to run this node app in a docker container (so that I can deploy it to EC2 later).
The problem
How do I configure my docker container to use the aws config file so that the node app running in it can use aws-sdk?
Clarification
I do not want to use IAM. I specifically want to use aws config file which has the secret access key etc.
You can do what AWS is doing when they explain how to use their containers on local machines. For example, for local AWS Glue they simply share the ~/.aws/ with the docker container using:
-v ~/.aws:/root/.aws:ro
Obviously you would have to adjust the paths above to match your local and docker setup.
The other way is to pass the AWS credentials using docker environment variables.

Node.js environment variables on AWS EC2 instance

How can I set the environment variables that I'm using in my Node.js application on AWS EC2? I tried to export them inside the instance console but it didn't work. It's running on an ubuntu server 20.04 btw.(p.s. my application is coming from a git repository, so there isn't a .env file there).
Manual Start:
Variable=ThisIsTheValue node index
System D:
Environment=Variable=ThisisTheValue
ExecStart=/usr/bin/node /path/to/index.js

How to store environment variables on AWS EC2?

I'm using dotenv to fetch and use environment variables from a .env file in my node app while running it locally. But this .env file can't be committed to github for security reasons. I'm using codepipeline and codedeploy to deploy the app continuously to ec2 but then the environment variables are missing on the ec2 instance server.
How do I configure the environment variables for my node.js app in AWS EC2 (ubuntu AMI) ?
The best secure way is to use AWS system Manager
Rerference:
https://aws.amazon.com/blogs/mt/use-parameter-store-to-securely-access-secrets-and-config-data-in-aws-codedeploy/
Its secure and fully compatible with codedeploy

How to deploy docker node.js application onto Amazon EC2 with Amazon EC2 container service

I have built a node.js application in the docker, every time when I need to run it, I just run the docker and run the command node app.js.
I have set it up on Amazon EC2, but in a vanilla way by register and log into the Amazon EC2 instance, pull the docker image, then run and log into the docker and run the command node app.js.
Now, since Amazon has this EC2 container service, I was told that I can do these two things automatically:
EC2 runs the docker
Docker runs node app.js
The advantage of doing this is that whenever either docker is crashed or the app is crashed, both of them are crashed, therefore that EC2 can automatically run the command again and rescue them.
How can I set this function up?
It comes by default when you set up an ECS task. Make sure the task is marked as 'essential' in your task's container and that you have at least one task requested in your ECS service, and it will automatically restart a failed/crashed container for you.

Node js and MongoDB app on AWS

What are the steps for deploying a Node js app, with express.js framework and MongoDB as database on AWS?
This is my first such activity and I am not able to find any reliable source over the net.
Deploy nodejs-express-mongoDB backend on AWS EC2 Ubuntu(16.04)
Back-end is a private repo on Gitlab.
Steps:
1: Create EC2 Ubuntu server on AWS,
create EC2 instance
2: Connect personal computer with AWS server - use to control cloud Ubuntu server on personal computer,
Connecting Linux Instance from Windows Using PuTTY
3: Clone repo from Gitlab to Ubuntu server,
Configure ssh key on linux server
Clone gitlab repo to linux server
4: Install Nodejs and MongoDB on Ubuntu server,
Install Nodejs
Install MongoDB
Install MongoDB
5: Launch MongoDB and run Nodejs to start node server,
6: Test back-end server using Postman or Browser.
Other useful linkYouTube
AWS has a full documentation for this on their website. These documentations are extremely thorough and you should read these first.
MongoDB on AWS
Node.js on AWS
Express.js on AWS
Here's a tutorial from 2015.

Resources