EC2

EC2 instances are virtual servers that you can provision and manage in the cloud.

Instance Types

EC2 provides a wide range of instance types optimized for various use cases:

  • General Purpose (e.g., t3, m5)
  • Compute Optimized (e.g., c5)
  • Memory Optimized (e.g., r5)
  • Accelerated Computing (e.g., p3, g4)
  • Storage Optimized (e.g., i3, d2)

Choose the instance type based on your application's requirements.

Connecting to EC2 Instances

SSH

To connect via SSH, ensure you have the private key associated with the instance:

chmod 400 /path/to/private-key.pem
ssh -i /path/to/private-key.pem ec2-user@ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com

EC2 Serial Console

For instances that support it (typically those running on AWS Nitro System):

  1. Go to the EC2 Console
  2. Select the instance
  3. Click Connect > EC2 Serial Console > Connect

Note

If no login prompt appears, try pressing Enter.

CLI Tools for EC2 Interaction

SSH Config

Optimize your SSH connections by editing ~/.ssh/config:

Host aws-instance
    Hostname ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com
    User ec2-user
    IdentityFile ~/.ssh/aws-key.pem

Now connect with: ssh aws-instance

SCP (Secure Copy)

Transfer files to/from your EC2 instance:

# Local to EC2
scp localfile.txt aws-instance:~/

# EC2 to Local
scp aws-instance:~/remotefile.txt .

Rsync

Synchronize directories:

rsync -avz --progress /local/dir/ aws-instance:/remote/dir/

Tmux

For persistent sessions, use tmux. Connect with:

ssh -t aws-instance tmux attach

Vim

Edit remote files directly:

vim scp://aws-instance//path/to/remote/file

Copy current buffer to EC2:

:!scp % aws-instance:~/path/to/remote/file

Resources

For more information, refer to the EC2 User Guide

Created by Ryan D. Najac for the Palomero Lab at the Institute for Cancer Genetics.
Page last updated on 2025-02-14.