I thought I would share my personal deployment checklist for AWS EC2. I remember the first time I deployed, I felt like there were a lot of gotchas. I've put together this checklist, which helps me keep track of the different steps it takes to create a new EC2 instance you can ssh into, configuring its environment, and deploying on it.
For first-timers deploying to AWS, I hope you find this helpful.
Create a new EC2 instance.
Defaults / free tier are fine, except for Security Groups and Key Pair.
- The included port 22 is for SSH.
- Open Port 80. Can use your laptop IP address or leave it as 0.0.0.0 which leaves it exposed to any IP.
- Add other ports as necessary. If your server "listens" on 3000, then add 3000. But you may want to consider using
nginxto only listen on port 80 but "route" relevant requests to 3000, 8000, etc.
- Make a new Key Pair (.pem) and download it. Move it to
~/.ssh. You can do that with
mv <drag file to terminal to get current path> ~/.ssh
SSH into your instance.
You need to configure the read/write authorizations on your ssh key. Then you need to add that key to the destination site and finally add the key to your keychain. Keychain is going to run through all possible ssh keys whenever you try to connect to a site.
chmod 400 ~/.ssh/<your key>. If you need to debug this step, use
ls -lh <filepath>, which will tell you permissions. should just be
rat the front.
ssh -i identityFile ec2-user@<your host ip address>
ssh-add ~/.ssh/<your key>.pem
eval "$(ssh-agent -s)"- starts the ssh-agent
ssh ec2-user@<your host ip address>
Install necessary software.
You'll need git at a minimum. Rest is app-specific. This example is for nvm/node/yarn.
sudo yum install git.
which gitto make sure it's working.
- Install nvm:
curl -o- [https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh](https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh) | bash
- Install node:
nvm install node
- Install your version:
nvm install <your local version #>
- Install yarn:
npm install -g yarn@<your version #>
Your local is already set up to ssh nicely with git. New EC2 instance isn't (yet).
ssh-keygen -t rsa -b 4096 -C "firstname.lastname@example.org"Use an empty passphrase when prompted.
- Add the key to your ssh-agent with
eval "$(ssh-agent -s)"and
- If you have problems with this, see step 2 above.
- You then need to copy the content of this newly generate
id_rsafile into your github security. use
pbcopy < ~/.ssh/id_rsa.pubor
vim ~/.ssh/id_rsa.pubto do this.
- If you need to debug, git has a guide here.
Set up the directory.
Finally, clone the repo.
git clone <repo .git>
- Any files not pushed to github, like
.env, need to be copied over. use
scp <drag .env file to terminal> ec2-user@<your host ip address>
- if you need this to run while you're not in ec2 terminal, use
pm2 start <app.js or runfilename.js>
There are many ways to configure an EC2 instance and set it up, but I hope this barebones guide is useful to beginners debugging their deployment. I'll be writing a future post that demonstrates ways to set up testing, logging, and CICD on EC2.