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, 2020 in AWS by akhtar
• 38,260 points
1,960 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, 2020 by MD
• 95,460 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, 2020 in AWS by MD
• 95,460 points
1,916 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, 2020 in AWS by MD
• 95,460 points
2,631 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP