Security Groups and EC2 Networking

Learn about protecting your EC2 instances with security groups.

A very important component of EC2 networking is the security group (SG). We can think of a security group as a firewall around our resources (like EC2 instances) within our VPC. So, a security group allows us to restrict access to our EC2 instances.


In this lesson, we’ll learn to create security groups through the CLI and attach them to our EC2 instances. We’ll cover the basics here to get SSH access to the EC2 instance that we created. In the chapter about networking, we’ll look at the details of security groups.

One thing to internalize right away:

To get the best security for our cloud architecture, it is important to create these security groups as restrictive as possible. In general, it is a good idea to follow the least privilege principle and only maintain the absolute minimum access.

This might make it a bit more cumbersome to set up resources at the beginning, but it will definitely pay off in the long run.

Now, let’s take a quick look at the settings available for security groups in the EC2 Launch wizard:

Get hands-on with 1200+ tech skills courses.