How to Launch an AWS EC2 Instance: Step by Step
Launching an EC2 instance means picking an image, a size, a key pair and a security group, then starting the server. Here is the sequence, from login to running.
On this page
Short answer
To launch an AWS EC2 instance, open the EC2 console, pick an Amazon Machine Image, choose an instance type, create or select a key pair, set up a security group, add storage, and launch. The instance usually starts within a few minutes, after which you connect with SSH and check that it responds.
What is an AWS EC2 instance?
An Amazon EC2 instance is a virtual server running in Amazon Web Services. It is a computer in the cloud that you rent by the hour or second, with its own processor, memory, storage and network address.
EC2 is the base building block of most AWS workloads. Web servers, APIs, batch jobs and test environments all run on instances, and each instance can be started, stopped, resized or replaced without touching physical hardware.
Launching an instance is a configuration task, not a coding task. You pick a pre-built image, a size, network rules and a login key, and AWS provisions the server. Most teams launch their first instance for a test or a small website, then scale up once they know the workload. The steps below follow the order the console asks for them.
What do you need before you launch?
Before you launch, you need an AWS account with a payment method, access to the EC2 console, and a decision on four things: which region the instance runs in, what software it needs, who may connect to it, and how long it will run.
Region matters because it sets where your data lives and how far it travels to your users. Pick the region closest to your users, and check that the instance type you want is available there.
Decide the lifetime up front. A test instance that runs for a day needs different settings from a production server that runs for a year. Short-lived instances can use the smallest size and the default storage; long-lived ones need backups, monitoring and a plan for patching.
You should also know who will connect. If only your team connects, the security group can allow only your office addresses. If the public connects, the instance needs a web server and ports 80 and 443 open. Cloud services covers how teams plan this kind of setup.
How do you pick an AMI and an instance type?
An Amazon Machine Image, or AMI, is the template the instance is built from. It holds the operating system and any pre-installed software. Amazon Linux, Ubuntu and Windows Server are the usual starting points, and AWS offers free-tier images for new accounts.
Pick the AMI that matches what you will run. A web server needs a Linux image with a web stack or a clean base you configure yourself. A Windows application needs a Windows Server image. Changing the operating system later means launching a new instance, so choose carefully.
The instance type sets the processor, memory and network performance. Types are grouped into families: general purpose for balanced work, compute-optimised for processing, and memory-optimised for databases and caches. Start with the smallest general-purpose type that fits, and resize later if the server struggles.
Use this table to narrow the choice:
| Family | Best for | Example use |
|---|---|---|
| General purpose | Balanced work | Web servers, small APIs |
| Compute optimised | Heavy processing | Batch jobs, video work |
| Memory optimised | Large data in memory | Databases, caches |
| Storage optimised | Fast local disks | Data processing |
| Burstable | Low, spiky use | Test servers, small sites |
Burstable types suit test and small workloads because they cost less when idle and burst when needed. Production servers usually need a fixed type so performance does not vary.
How do key pairs, security groups and storage work?
A key pair is how you log in. AWS creates a private key file that you download once and keep safe, and the matching public key is placed on the instance. Without the private key file you cannot log in, so store it somewhere safe and never share it in chat or email.
A security group is a firewall around the instance. It lists which ports are open and to whom. For a web server, open ports 80 and 443 to everyone and port 22 only to your own addresses. For a private server, open port 22 only to your office or VPN addresses and nothing else.
Storage is an Elastic Block Store volume attached to the instance. The default size on the launch screen is usually enough to start; add more only if you know the workload needs it. Enable deletion on termination for test instances, so the volume does not keep costing money after the instance is gone.
Check each of these three before you launch, because all three are harder to fix after the instance is running. A lost key pair or an open port 22 is a security problem, not a minor mistake.
What are the launch steps?
Launching an EC2 instance takes a few minutes once the choices are made. Follow the console in this order:
- Open the EC2 console and pick a region. Choose the region closest to your users.
- Click Launch instance and name it. Use a name that says what it does, such as web-server-test.
- Pick an AMI. Choose Amazon Linux or Ubuntu for a web server, or the image your application needs.
- Pick an instance type. Start small; a general-purpose or burstable type fits most first launches.
- Create or select a key pair. Download the private key file and store it safely.
- Set the security group. Open 80 and 443 for a web server, and 22 only to your addresses.
- Set the storage size. Accept the default unless you know you need more.
- Review and launch. Check the summary screen, then launch and wait for the instance state to change to running.
The console shows a launch status screen. When the state reads "running" and the status checks pass, the instance is ready to connect to. That usually takes a few minutes.
How do you connect and check the instance?
Connect with SSH from your terminal, using the private key file and the public address shown in the console. The command uses the key file, the default user for your AMI, and the instance address. Amazon Linux uses the user ec2-user; Ubuntu uses ubuntu.
Once connected, check three things. First, confirm the operating system version and that the disk has free space. Second, check that the service you need is running, such as a web server responding on port 80. Third, check the security group again from the console to confirm only the intended ports are open.
If the connection fails, the usual causes are a wrong key file, the wrong user name, or a security group that blocks port 22 from your address. Fix those three before looking further. AWS serverless architecture covers the alternative for workloads that do not need a standing server.
Tag the instance with its purpose and owner while you are in the console. A tagged instance is easy to find and easy to clean up later; an untagged one becomes a mystery cost in the next bill. Teams that run many instances usually manage them with DevOps services rather than by hand.
Example (hypothetical): a team launches a test server
Example (hypothetical): a small team needs a test server for a new API. It launches two burstable instances in one region, each with the default storage and a security group that allows port 22 only from the office and port 80 to everyone.
The team plans to run both instances all month to test under load. Two instances running 24 hours a day for 30 days is 2 times 24 times 30, or 1,440 instance-hours. The team tracks instance-hours as its cost unit and checks the AWS bill weekly, so a runaway process shows up before the month ends.
After a week the team finds one instance is idle most of the time, so it stops that instance and keeps one running. The change halves the instance-hours to 720 for the rest of the month, and the team notes the pattern: test servers should stop when nobody is testing.
The lesson is to plan the lifetime and check the bill early. A test instance left running after the test ends is the most common EC2 cost surprise.
What are the common mistakes?
The most common EC2 launch mistakes are losing the key pair, opening port 22 to everyone, and leaving test instances running. All three are easy to prevent and expensive to fix.
- Losing the key pair. The private key file is shown once. Lose it and you cannot log in without extra work.
- Opening port 22 to the world. SSH open to everyone invites automated login attempts. Limit it to your addresses.
- Leaving instances running. A test server that nobody uses still bills by the hour. Stop or terminate it.
- Picking the wrong region. Data and users far from the region mean slow responses and surprise transfer costs.
- No tags or owner. Untagged instances are hard to find, hard to clean up and hard to bill to the right team.
Key takeaways
- An EC2 instance is a virtual server you rent by the hour, configured from an image, a size, a key and a firewall
- Pick the region, AMI and instance type before you launch; changing them later means a new instance
- Store the private key file safely — it is shown once and you cannot log in without it
- Open port 22 only to your own addresses and ports 80 and 443 only for a public web server
- Tag every instance and stop test servers when the test ends
Frequently asked questions
How long does it take to launch an EC2 instance?
Usually a few minutes. The console steps take about five minutes once you know your choices, and the instance reaches the running state shortly after. Status checks then take another minute or two before the instance is ready to connect to.
What is the difference between an AMI and an instance type?
An AMI is the template the instance is built from, holding the operating system and software. An instance type is the size of the server, setting its processor, memory and network performance. You pick both at launch.
Can I change the instance type after launching?
Yes, for most instance types. Stop the instance, change its type in the console, and start it again. You cannot change the operating system this way; that needs a new instance built from a different AMI.
What happens if I lose my key pair?
You cannot log in with SSH until you replace the key, which takes extra steps and downtime. Store the private key file safely from the start, keep a backup in a secure place, and never share it in chat or email.
How do I stop paying for an EC2 instance I no longer need?
Stop the instance to pause billing for the server, or terminate it to remove it entirely. Remember that attached storage volumes can keep billing after termination unless deletion on termination is enabled, so check the volumes too.
Is EC2 the right choice for a small website?
It can be, but a small static site is often cheaper and simpler on managed hosting or a serverless setup. EC2 fits when you need a full server you control, such as a custom API or a test environment that mirrors production.