Deploy to EC2
Security Group
Setup the following security group configuration
Connect with SSH
- Update the permission of downloaded certificate file
chmod 400 .pem
- Connect to the distant server with the command
ssh -i .pem ec2-user@
Install node with nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install node
- Test node installation with
node -e "console.log('Running Node.js ' + process.version)"
Checkout the official documentation on how to setup node in ec2 linux
Port Forwarding from 80 to 8000
Use the following command for port forwarding
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000
Install MongoDB community edition
- Verify Linux Distribution with
grep ^NAME /etc/*release
The result should be Amazon Linux or Amazon Linux AMI
- Create a /etc/yum.repos.d/mongodb-org-4.4.repo file so that you can install MongoDB directly using yum:
cd /etc/yum.repos.d
sudo touch mongodb-org-4.4.repo
- Add the following Configuration to created file with nano or vim
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
- Install MongoDB packages with
sudo yum install -y mongodb-org
- Setup storage directory for MongoDb
cd /
sudo mkdir data
cd data
sudo mkdir db
cd ../..
cd home/ec2-user
sudo service mongod start
Checkout common errors faced during this
Checkout the offficial Documentation
Install PostgreSQL
Follow this article for installing PostgreSQL
after install use this command to open db shell
sudo su - postgres
Transfer node project to ec2
You can use programs like filezilla to transfer project files the method I use personally is to send zipped file using scp command
- Delete node_modules directory from project
- Zip the project directory
zip -r server.zip
- Transfer zipped file using scp
scp -i .pem server.zip ec2-user@:
- Now connect back to instance with SSH and unzip the file
unzip server.zip
Run Application with screen
install the node modules and run the app with screen
screen npm start
you can detach the screen without terminating by
i. ctrl+A
ii. D
Bucket Policy for S3
Use the following bucket policy in S3 Bucket for public read access
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::/*"
}
]
}
CloudFront Guide
Use this tutorial for setting up cloudfront
Steps to get SSL Certificate to EC2 instance
- move nameserver to Route 53
- request certificate from ACM
- create load balancer targeting to ec2 instance
- create a record pointing to load balancer in route 53