The problem
Security groups that started with three rules now carry fifty partner CIDRs, office ranges and on-premises subnets. Then a deployment fails:
An error occurred (RulesPerSecurityGroupLimitExceeded) when calling the AuthorizeSecurityGroupIngress operation:
The maximum number of rules per security group has been reached.
Or a launch fails with SecurityGroupsPerInterfaceLimitExceeded. Raising the quota is the obvious answer, but it has a ceiling and side effects. This guide gets you to a design that scales.
How the quotas interact
| Quota | Default | Notes |
|---|---|---|
| Inbound rules per security group | 60 | Counted separately for IPv4 and IPv6 |
| Outbound rules per security group | 60 | Same quota value as inbound; counted separately |
| Security groups per network interface | 5 | Maximum 16 |
| Rules per group × groups per interface | ≤ 1,000 | The hard ceiling; you can't raise both |
So raising rules per group to 200 caps groups per interface at 5, and raising groups per interface to 16 caps rules per group at 62. Check current values:
aws service-quotas list-service-quotas --service-code vpc \
--query "Quotas[?contains(QuotaName,'security group')].{Name:QuotaName,Code:QuotaCode,Value:Value}" \
--output table
Two counting rules surprise people:
- A prefix list reference counts as its
MaxEntries, not as one rule and not as the entries in use. A list with max entries 50 referenced once costs 50 rules, even if it holds 3 CIDRs. - A security group reference counts as one rule, no matter how many instances are in the referenced group.
Step 1: measure what you're using
SG=sg-0abc1234def567890
aws ec2 describe-security-group-rules --filters Name=group-id,Values=$SG \
--query "SecurityGroupRules[].{Egress:IsEgress,Proto:IpProtocol,From:FromPort,To:ToPort,V4:CidrIpv4,V6:CidrIpv6,PL:PrefixListId,Ref:ReferencedGroupInfo.GroupId}" \
--output table
To see the effective cost including prefix list weights, use a script:
import boto3
from collections import Counter
ec2 = boto3.client("ec2")
pl_weight = {p["PrefixListId"]: p.get("MaxEntries", 0)
for page in ec2.get_paginator("describe_managed_prefix_lists").paginate()
for p in page["PrefixLists"]}
cost = Counter()
for page in ec2.get_paginator("describe_security_group_rules").paginate():
for r in page["SecurityGroupRules"]:
family = "v6" if r.get("CidrIpv6") else "v4"
weight = pl_weight.get(r["PrefixListId"], 1) if r.get("PrefixListId") else 1
key = (r["GroupId"], "out" if r["IsEgress"] else "in", family)
cost[key] += weight
for (gid, direction, fam), n in cost.most_common(25):
print(f"{n:>4} {gid} {direction} {fam}")
Treat the output as a guide. Groups near 60 (or your raised quota) are the ones to fix first.
Tip
AWS-managed prefix lists have weights too. The CloudFront origin-facing list (
com.amazonaws.global.cloudfront.origin-facing) carries a large weight, so a single reference can use most of a default 60-rule group. CheckMaxEntriesfor any AWS-managed list before you reference it.
Step 2: move CIDR lists into managed prefix lists
A prefix list replaces dozens of near-identical rules with one reference, and lets several groups (and route tables) share one source of truth.
Size MaxEntries for realistic growth, not for "just in case". Every unit of MaxEntries costs a rule in every group that references it.
aws ec2 create-managed-prefix-list \
--prefix-list-name partner-vendor-a \
--address-family IPv4 \
--max-entries 20 \
--entries Cidr=203.0.113.0/26,Description="vendor-a dc1" Cidr=198.51.100.16/28,Description="vendor-a dc2" \
--tag-specifications 'ResourceType=prefix-list,Tags=[{Key=owner,Value=netops}]'
Reference it from the security group, then remove the individual CIDR rules:
PL=pl-0123456789abcdef0
aws ec2 authorize-security-group-ingress --group-id $SG \
--ip-permissions "IpProtocol=tcp,FromPort=443,ToPort=443,PrefixListIds=[{PrefixListId=$PL,Description=vendor-a}]"
# Find the old rule IDs that the prefix list now covers, then revoke them
aws ec2 describe-security-group-rules --filters Name=group-id,Values=$SG \
--query "SecurityGroupRules[?CidrIpv4=='203.0.113.0/26' && !IsEgress].SecurityGroupRuleId" --output text
aws ec2 revoke-security-group-ingress --group-id $SG --security-group-rule-ids sgr-0aaa1111bbb22222c
Warning
Add the prefix list rule first and revoke the old CIDR rules afterwards. Revoking first blocks new connections from the partner until the replacement rule exists. If the group is already at its quota, the add will fail. Revoke a few low-risk rules first or temporarily raise the quota.
Step 3: change entries safely
Prefix lists are versioned. Modifications need the current version, which protects against two engineers editing at once:
VER=$(aws ec2 describe-managed-prefix-lists --prefix-list-ids $PL \
--query "PrefixLists[0].Version" --output text)
aws ec2 modify-managed-prefix-list --prefix-list-id $PL --current-version $VER \
--add-entries Cidr=192.0.2.0/27,Description="vendor-a dr" \
--remove-entries Cidr=198.51.100.16/28
aws ec2 get-managed-prefix-list-entries --prefix-list-id $PL
Every security group and route table that references the list picks up the change. Before editing, see what depends on it:
aws ec2 get-managed-prefix-list-associations --prefix-list-id $PL \
--query "PrefixListAssociations[].{Resource:ResourceId,Owner:ResourceOwner}" --output table
To grow the list, resize it in a separate call (--max-entries can't be combined with entry changes). The resize fails if any referencing group would exceed its rule quota, which is the check you want:
aws ec2 modify-managed-prefix-list --prefix-list-id $PL --current-version $VER --max-entries 30
If you need to roll back a bad edit, restore-managed-prefix-list-version returns the entries of an earlier version:
aws ec2 restore-managed-prefix-list-version --prefix-list-id $PL \
--previous-version 3 --current-version $VER
Step 4: share prefix lists across accounts
Central network teams own the lists; workload accounts reference them. Share through AWS RAM:
aws ram create-resource-share --name netops-prefix-lists \
--resource-arns arn:aws:ec2:eu-west-1:111122223333:prefix-list/$PL \
--principals arn:aws:organizations::111122223333:organization/o-abc123example
Consumers can reference a shared list in their security groups and route tables but can't edit it. The owner's edits reach every consumer at once, so put change control on the owning account.
Step 5: replace CIDRs with group references where you can
Inside a VPC, the cleanest rule says "the app tier may reach the database tier", not "10.20.1.0/24 may reach 10.20.8.0/24":
aws ec2 authorize-security-group-ingress --group-id sg-db000000000000001 \
--ip-permissions "IpProtocol=tcp,FromPort=5432,ToPort=5432,UserIdGroupPairs=[{GroupId=sg-app00000000000001,Description=app-tier}]"
One rule, independent of subnet growth. References also work:
- Across VPC peering in the same Region (reference the peer's group ID). Run
aws ec2 describe-stale-security-groups --vpc-id vpc-...after deleting a peering or a group, so dangling references don't hide. - Across Transit Gateway VPC attachments in the same Region, if security group referencing support is enabled on the transit gateway and the attachments. Check the TGW documentation for current limitations, for example traffic through inspection appliances and cross-Region peering.
Step 6: request quota increases with the ceiling in mind
Decide which dimension you need:
| Workload shape | Raise |
|---|---|
| Few groups per ENI, long partner lists | Rules per group (for example to 100-200), keep 5 groups per ENI |
| Many composable role groups per ENI (EKS security groups for pods, layered baselines) | Groups per ENI, keep rules per group low |
aws service-quotas request-service-quota-increase --service-code vpc \
--quota-code <code-from-list-service-quotas> --desired-value 120
Caution
Raising rules per group can stop you from raising groups per interface later, because of the 1,000 ceiling. Groups that grow to the new limit also make the change hard to undo. Raise only what the design needs and record why.
Symptom → cause → fix
| Symptom | Cause | Fix |
|---|---|---|
RulesPerSecurityGroupLimitExceeded with few visible rules | Prefix list references counted at MaxEntries | Lower MaxEntries or split the group |
| Prefix list resize fails | A referencing group would exceed its quota | Find it with get-managed-prefix-list-associations |
SecurityGroupsPerInterfaceLimitExceeded | More than 5 groups on an ENI (launch template plus EKS/ECS additions) | Consolidate groups or raise groups per ENI |
| Rule references a group that no longer exists | Peering or group deleted | describe-stale-security-groups, then clean up |
| Partner blocked after a list edit | Wrong CIDR removed in a shared list | restore-managed-prefix-list-version |
Prevent it next time
- Put recurring CIDR sets in prefix lists owned by one team and shared through RAM.
- Keep
MaxEntriestight and review it with the rule-cost script monthly. - Prefer group references inside and between VPCs.
- Alarm on Service Quotas utilization for the security group quotas.
- Manage prefix list entries in IaC with code review, because one edit changes access everywhere.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get