Sep 24, 2018

Adding security group to existing EC2 instance

Step to do from AWS console:

1. Login to the AWS console and select EC2 service
2. Select the instance to which you want to add additional security groups
3. Under Actions select "Networking>>Change Security groups"
4. In this page, you can assign any additional Security group which exists in your account to this instance along with the ones you have already attached
[ please note you have to select the previously attached Security groups as well if you want them, as this operation is change security groups]


If you already have AWS cli installed, you can run the below command to change the security groups:

aws ec2 modify-instance-attribute --instance-<instance-id> --groups <security group IDs>

Again, here you will have to provide the list of all security groups you want to be attached to the instance separated by space, if you just provide one security group them the previously attached security group will be removed and only this security group will be attached.