Security group doesn't exist but I know it exists


I created a CFN stack for Kubernetes cluster and then deleted it and noticed that the VPC and ENI were left undeleted so wanted to remove the ENI but couldn't because a security group is attached to it. Tried to remove the SG and assign a default VPS SG but it says I don't have permissions to do that. I tried looking up the SG using aws cli but it says that the SG doesn't exist. I can see it right now in my console so why does it say it doesn't exist? I'm stuck. Please help me. How do I remove the ENI, VPC and the SG. Thank you in advance.

  • Search for the ENI to get the subnet and security group(s) it uses with the below command. Ensure you replace <ENI> and <REGION> placeholders with respective values. The output of the below command will be json which you can parse with something like jq. This should align with what you see in the console

    aws ec2 describe-network-interfaces --network-interface-ids <ENI> --filters Name=network-interface-id,Values=ENI --region <REGION> --output json --query 'NetworkInterfaces[0].{Subnet:SubnetId,SecurityGroups:Groups[*].GroupId}')

2 Answers

Are you in the same region using CLI?

profile picture
answered 2 years ago
  • AWS CLI does not have the option to specify the region

    aws ec2 describe-security-groups --filters Name=vpc-id,Values=... --group-ids ...

    An error occurred (InvalidGroup.NotFound) when calling the DescribeSecurityGroups operation: The security group '...' does not exist But I am on the security group page in the console now as we speak so it does exist.


Try adding in --region at the end of your CLI command to whatever region you see the Security Group in.

For example:

aws ec2 describe-security-groups ... --group-ids --region us-east-1

You can also run an aws configure get region to get the region of what region your CLI is setup for.

That would be my first look - ensure where you are looking in console matches the region in your CLI.

answered 2 years ago
  • You are a genius! Bullseye! That solved my problem. Thank you very much!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions