As there is already a way to remove (not deleting) the security group from an ec2 instance from aws console, i am looking for a way to do it programatically by using python or aws cli. but not able to find any such offering. Please let me know if it is possible
1 Answer
Use modify_instance_attribute()
, passing a Groups
parameter:
Replaces the security groups of the instance with the specified security groups. You must specify at least one security group, even if it's just the default security group for the VPC. You must specify the security group ID, not the security group name.
So, rather than 'removing' a Security Group, you are actually telling it which Security Groups should be associated with the instance.
-
For anyone who came across this question looking for how to do this with the AWS CLI, the corresponding
modify-instance-attribute
AWS CLI command is documented here. Commented Apr 11, 2022 at 18:55