Amazon Web Services (AWS) - Delete Security Group using the AWS CLI

by
Jeremy Canfield |
Updated: March 24 2023
| Amazon Web Services (AWS) articles
A Security Group is used to allow or deny requests coming in (ingress) and/or requests going out (egress). For example, a Security Group could be used to only allow requests within a certain IP address range to come in (ingress) and go out (egress) of an EC2 Instance.
This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.
The aws ec2 describe-security-groups command can be used to list your EC2 security groups.
aws ec2 describe-security-groups
Something like this should be returned.
{
"SecurityGroups": [
{
"Description": "My security group",
"GroupName": "my-security-group",
"IpPermissions": [],
"OwnerId": "713123474252",
"GroupId": "sg-071234ca116e3abcd",
"IpPermissionsEgress": [
{
"IpProtocol": "-1",
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"Ipv6Ranges": [],
"PrefixListIds": [],
"UserIdGroupPairs": []
}
],
"VpcId": "vpc-011234cfa335abcd1"
}
]
}
The aws ec2 delete-security-group command can be used to delete a Security Group.
aws ec2 delete-security-group --group-name my-security-group
Did you find this article helpful?
If so, consider buying me a coffee over at