You can attach up to 5 security groups to an EC2 instance, this gives you the flexibility to define more rules in a manageable way. This how-to guide will explain in detailed steps how you can attach or change security groups (sg) on an Amazon EC2 instance via the AWS Console or the AWS CLI. Here are the steps that allow you to associate a security group to a running EC2 instance.