- You can find the source code for this video in my GitHub Repo.
Intro
In this video, I'll show you how to integrate AWS API Gateway with EC2 instances using AWS console and terraform.
Install Expres App on Ubuntu
Secure private key.
sudo chmod 600 ~/Downloads/devops.pem
SSH to the Ubuntu.
ssh -i ~/Downloads/devops.pem ubuntu@<ip>
Update package list.
Install NodeJS and npm package manager.
sudo apt -y install nodejs npm
Clone GitHub repo.
cd /opt
sudo git clone -b 118 https://github.com/antonputra/tutorials.git
Update owner on the folder.
sudo chown -R ubuntu:ubuntu /opt/tutorials/
Install dependencies.
cd tutorials/lessons/118/my-app/
npm ci
Create systemd file.
sudo vim /etc/systemd/system/my-app.service
/etc/systemd/system/my-app.service |
---|
| [Unit]
Description=My App
[Service]
Type=simple
ExecStart=/usr/bin/node /opt/tutorials/lessons/118/my-app/app.js
WorkingDirectory=/opt/tutorials/lessons/118/my-app/
User=nobody
Group=nogroup
# Environment variables:
Environment=NODE_ENV=production
# Allow many incoming connections
LimitNOFILE=infinity
# Allow core dumps for debugging
LimitCORE=infinity
StandardInput=null
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=my-app
# Restart service after 10 seconds if node service crashes
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
|
Enable the service.
sudo systemctl enable my-app.service
Start the service.
sudo systemctl start my-app.service
Check status of the service.
sudo systemctl status my-app.service
Check log for errors.
journalctl -u my-app -f --no-pager
The rest of the tutorial you can find in the video and the source code in my github repository.