home
Use a private key to tunnel into an EC2 instance on AWS with SSH
ssh -L ${bind_port}:${remote_host}:${remote_port} -i ${private_key_path}.pem ec2-user@${remote_machine_domain}
Here you can fill in the variables to customize your command. You can also click button below to grab the url with the variables you already filled in. Visiting that url will pre-fill them in you next visit. That allows you to customize and save your snippets. You don't have to fill all the variables, just the ones you think will change less often.
copy the url
copy
sh
ssh -L ${bind_port}:${remote_host}:${remote_port} -i ${private_key_path}.pem ec2-user@${remote_machine_domain}

Tunneling into some instance allows us to use command locally and have its effect on the remote machine.

For example, we have a database server on our local machine. We can do migrations on it.

copy
env
DATABASE_URL="postgres://endrevegh:postgres_password@localhost:5432/chat_example

So in case of prisma we can use this command to fire up the migrations.

copy
sh
prisma migrate up

What happens when the database sits on a remote machine. We can ssh into the remote machine, bind the port of the remote db to our local port and then run

The -i modifier allows us to use private keys in our machine.

Here we assume the file (key) bastion-key.pem is in the same folder as the command is issued.

copy
sh
ssh -i bastion-key.pem ec2-user@someawsdomain.com