I have an Amazon EC2 instance running and I will like to add another security group to that instance and then remove the current security group from that instance. Is this possible?
I have an Amazon EC2 instance running and I will like to add another security group to that instance and then remove the current security group from that instance. Is this possible?
Update: As of January 2014, you can now change security groups for running AWS EC2 instances.
AWS Console
Simply right-click on an instance, and click on
Change Security Group
Add/remove security groups as appropriate and click
Assign Security Groups
when doneEC2 Command Line
Use the following command:
AWS Command Line
Use the following command:
Note, you must specify all security groups with which you'd like the instance associated.
Update 2015-02-27:
This is now possible, see the answer below.
Old reply:
Amazon's FAQ says it's not possible to define a security group anywhere but at launch time.
It is now possible to do this. Click on the actions menu and Change Security Groups - Select the Security Groups you would like to use.
This requires downtime on your instance. There may be some other options available using the API.
As towo said you can't change a security group of an instance anywhere but launch time.
Unless you are using a VPC where security groups differ from EC2 security groups.
This page outlines the differences between EC2 and VPC security groups.
http://docs.amazonwebservices.com/AmazonVPC/latest/UserGuide/VPC_SecurityGroups.html
So if you require the extra functionality of the VPC groups (Changing groups, control ingress/engress traffic, etc.), you may want to look at the additional functionality provided by VPCs.
If you are using boto3 you need to call modify_attribute and pass a list of group ids
http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Instance.modify_attribute
As of 2016 Nov 24. above answer given by @hanxue is right but not complete. There are two types of instances in AWS: instances inside private cloud called vpc instances and public instances called Ec2 Classic. You can only change security groups of VPC instances but not EC2-classic. Aws official documentation screenshot you would like to see. docs you would like to see
In the new AWS GUI, just select the instance that you want to add a security group to, select actions on the top navigation area, then select on security. You are welcome
5 security groups
> You can have 50 inbound and 50 outbound rules per security group > giving a total of 100 combined inbound and outbound. You can assign up > to 5 security groups to a network interface. If you need to increase > or decrease this limit, you can contact AWS Support.
However according the this FAQ "modify the settings for the current security group - which will affect all instances running in the specific group" you can change gradually redefine the existing ones. As I'm trying this now for my scenario through the EC2 console, my records where all erased!