Security groups
- A virtual firewall around our EC2 instance
- They’re:
- Associated with network interfaces.
- Stateful.
- # Can only ALLOW.
- This is principle of least privilege.
- Can reference other security groups.
Create a security group
-
Go to “Security Groups” dashboard.
[!NOTE]
This is a direct link to “eu-central-1” availability zone. So you might wanna just search it.
-
Click on “Create security group” button:

-
Pick a meaningful name, write a good description.

-
Add allowed inbound rules, remember that AWS works with least privilege principle as baseline, for example here we have exposed SSH port to the world.

-
Then it is time to specify to where your EC2 instance can send a request – “Outbound rules”:

-
Finally add some tags if you need any.

Attach a new security group to an EC2 instance
Opening port 80 of an EC2 instance
Assume we need to allow an existing EC2 instance to be accessible through port 80.
- To do this we need to create a new security group which allows inbound requests from port 80.
-
Then we can attach the newly create security group to our EC2 instance:

-
Then you can find the new security group and attach your EC2 instance to it.

- Click on “save” button to apply changes. Now if you go to inbound rules tab of your EC2 instance you can see that now your EC2 instance is accessible through port 80 and 22.