
During EC2 launch: networking & security group choices
When you reach the networking section of the EC2 launch wizard, choose the VPC and subnet you want. For security groups, you have two main options:- Use an existing security group you already created, or
- Create a new security group during the launch and then modify it after launch.
Common security group rule examples
Security groups let you allow specific inbound traffic and control outbound traffic. Examples:- Allow SSH from a specific IP: Protocol TCP, Port 22, Source
203.0.113.5/32 - Allow HTTP from anywhere: Protocol TCP, Port 80, Source
0.0.0.0/0 - Allow HTTPS from anywhere: Protocol TCP, Port 443, Source
0.0.0.0/0 - Custom app port: Protocol TCP, Port 8080, Source
10.0.1.0/24
Do not leave SSH open to
0.0.0.0/0 unless you have an additional layer of protection (bastion host, VPN, or strict key-based access). Always restrict SSH to known IPs or CIDR ranges when possible.Key conceptual differences: Security groups vs NACLs
- Security groups are stateful: if you allow inbound traffic on a port, the return traffic is automatically allowed outbound without an explicit rule.
- Security groups are applied to network interfaces (ENIs) and operate at the resource (instance) level.
- Security group rules are allow-only: anything not explicitly allowed is implicitly denied.
- NACLs are applied at the subnet level and are stateless: you must configure both inbound and outbound rules; return traffic is not automatically allowed. NACL rules can be explicit allow or deny and are evaluated by rule number order.
Use security groups for fine-grained, resource-level access control. Use NACLs for subnet-wide, stateless controls or when you need explicit deny rules that apply to all instances in a subnet.
Best practices & next steps
- Apply the principle of least privilege: open only required ports and restrict source IPs.
- Reuse security groups for resources that need the same access patterns to simplify management.
- Use separate security groups for management (SSH), web traffic (HTTP/HTTPS), and application ports. Attach multiple security groups to a single instance if needed.
- Monitor and audit security group rules regularly; AWS Config and CloudTrail can help detect changes.
- When you need to expose an instance to the internet, consider using a bastion host, AWS Systems Manager Session Manager, or a VPN instead of opening SSH to the world.
- Select the instance → Network interfaces → Security groups → Manage security groups.
- Edit inbound rules to add HTTP/HTTPS or to restrict SSH to a known IP.
- Add additional security groups to the instance if you want to combine rule sets.
Links and references
- EC2 (Elastic Compute Cloud) course reference
- AWS RDS course reference
- AWS Security Groups documentation: https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html
- NACLs overview: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html