An EC2 instance with every port open is an invitation. A Security Group lets you decide exactly who gets in and through which door. In this guide I create one that only allows SSH from a single IP, attach it to an instance, and then explain how they work, outbound rules, and the limits you need to know.
Note: the video is in Spanish (Spanish audio only).
Create the Security Group
- Open EC2 and, in the left menu, click Security Groups. You’ll see a default one.
- Click Create security group.
- Name:
ssh-access. Description: “Only SSH access allowed”. - VPC: the VPC your instance is in. I left the default one.
Notice there are no inbound rules, but there is an outbound rule allowing every connection from the instance out.
The inbound rule for SSH
Click Add rule under inbound rules. For the port you have two options:
- Under Type, choose SSH: port 22 fills in by itself. That list has services with predefined ports, such as HTTP or HTTPS.
- Or type port 22 directly.
Then set the source: only the addresses you put there can connect; everything else is rejected. You can use IPv4 or IPv6 addresses, or pick from the dropdown the IP you’re using to reach the AWS console.
I used a specific IP with a /32 mask, which means “only this IP”:
10.25.12.32/32
Add a description so you know where that IP comes from, then click Create. You’ll see the name, the Security Group ID, the description and the ID of the VPC it belongs to.
Attach it to an instance
When launching an instance, under Network settings you get two options: create a security group with rules for HTTP, HTTPS or SSH, or select an existing security group. Choose the second and pick ssh-access. Done.
What a Security Group is
It’s a virtual firewall controlling the connections into and out of the instances it’s attached to. The golden rule: open only the ports and IPs strictly needed for the service running on the instance.
Two examples:
- SSH: my advice is to allow it only from your private network, connecting to your internal network through a site-to-site VPN instead of exposing it to the internet.
- Web server: open port 80 (HTTP) or, better, 443 (HTTPS), and nothing else.
Why not a firewall installed inside the instance? Because the Security Group doesn’t use your instance’s resources to evaluate connections: your server only spends its resources running your application.
Outbound rules protect you too
Picture an instance that only needs to talk to a database on your internal network. Replace the outbound rule with a single one: the database server’s IP and its port (for example 3306 for MySQL, or your engine’s port).
If that instance is ever compromised, it can only reach the database: it can’t send data out to the internet.
Limits worth knowing
AWS services have quotas. For Security Groups, as covered in the video:
- Up to 2,500 Security Groups per region (you can ask for more).
- 60 inbound and 60 outbound rules per Security Group, counted separately for IPv4 and IPv6.
- Up to 5 Security Groups per network interface (can be raised to 16).
- Security Groups per interface multiplied by rules per group can’t go over 1,000.
To ask for more, go to Service Quotas, search for VPC and filter by security group. Quotas change, so confirm them there.
With this you can create Security Groups and tighten your instances’ security in a couple of minutes. If you don’t have an instance yet, start by launching your own server.
Found it useful? Watch the full video on YouTube (in Spanish) and subscribe to @Andrevops for more videos like this one.




