How to delete a security group using Boto3 module?

0 votes

Hi Team,

I have created a security group in AWS with the help of Boto3 module. Now I don't need that security group. how can I delete that using the boto3 module?

Oct 8 in AWS by akhtar
• 33,470 points
51 views

1 answer to this question.

0 votes

Hi@akhtar,

If you attempt to delete a security group that is associated with an instance, or is referenced by another security group, the operation fails with InvalidGroup.InUse in EC2-Classic or DependencyViolation in EC2-VPC. So you can delete the security group if it is not in use.

import boto3
from botocore.exceptions import ClientError
ec2 = boto3.client('ec2')
try:
    response = ec2.delete_security_group(GroupId='SECURITY_GROUP_ID')
    print('Security Group Deleted')
except ClientError as e:
    print(e)
answered Oct 8 by MD
• 79,390 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to delete a key pair using Boto3?

Hi@akhtar, You can delete a key pair using ...READ MORE

answered Oct 8 in AWS by MD
• 79,390 points
29 views
0 votes
1 answer

Create a security group and rules using Boto3 module.

Hi@akhtar, A security group is for use with ...READ MORE

answered Oct 8 in AWS by MD
• 79,390 points
56 views