Working with geographic match conditions
Warning
Amazon WAF Classic support will end on September 30, 2025.
Note
This is Amazon WAF Classic documentation. You should only use this version if you created Amazon WAF resources, like rules and web ACLs, in Amazon WAF prior to November 2019, and you have not migrated them over to the latest version yet. To migrate your web ACLs, see Migrating your Amazon WAF Classic resources to Amazon WAF.
For the latest version of Amazon WAF, see Amazon WAF.
If you want to allow or block web requests based on the country that the requests originate from, create one or more geo match conditions. A geo match condition lists countries that your requests originate from. Later in the process, when you create a web ACL, you specify whether to allow or block requests from those countries.
You can use geo match conditions with other Amazon WAF Classic conditions or rules to build sophisticated filtering. For example, if you want to block certain countries, but still allow specific IP addresses from that country, you could create a rule containing a geo match condition and an IP match condition. Configure the rule to block requests that originate from that country and do not match the approved IP addresses. As another example, if you want to prioritize resources for users in a particular country, you could include a geo match condition in two different rate-based rules. Set a higher rate limit for users in the preferred country and set a lower rate limit for all other users.
Note
If you are using the CloudFront geo restriction feature to block a country from accessing your content, any request from that country is blocked and is not forwarded to Amazon WAF Classic. So if you want to allow or block requests based on geography plus other Amazon WAF Classic conditions, you should not use the CloudFront geo restriction feature. Instead, you should use an Amazon WAF Classic geo match condition.
Creating a geo match condition
If you want to allow some web requests and block others based on the countries that the requests originate from, create a geo match condition for the countries that you want to allow and another geo match condition for the countries that you want to block.
Note
When you add a geo match condition to a rule, you also can configure Amazon WAF Classic to allow or block web requests that do not originate from the country that you specify in the condition.
To create a geo match condition
Sign in to the Amazon Web Services Management Console and open the Amazon WAF console at https://console.amazonaws.cn/wafv2/
. If you see Switch to Amazon WAF Classic in the navigation pane, select it.
In the navigation pane, choose Geo match.
Choose Create condition.
Enter a name in the Name field.
The name can contain only alphanumeric characters (A-Z, a-z, 0-9) or the following special characters: _-!"#`+*},./ . You can't change the name of a condition after you create it.
Choose a Region.
-
Choose a Location type and a country. Location type can currently only be Country.
-
Choose Add location.
-
Choose Create.
Editing geo match conditions
You can add countries to or delete countries from your geo match condition.
To edit a geo match condition
Sign in to the Amazon Web Services Management Console and open the Amazon WAF console at https://console.amazonaws.cn/wafv2/
. If you see Switch to Amazon WAF Classic in the navigation pane, select it.
In the navigation pane, choose Geo match.
In the Geo match conditions pane, choose the geo match condition that you want to edit.
To add a country:
In the right pane, choose Add filter.
-
Choose a Location type and a country. Location type can currently only be Country.
Choose Add.
To delete a country:
In the right pane, select the values that you want to delete.
Choose Delete filter.
Deleting geo match conditions
If you want to delete a geo match condition, you must first remove all countries in the condition and remove the condition from all the rules that are using it, as described in the following procedure.
To delete a geo match condition
Sign in to the Amazon Web Services Management Console and open the Amazon WAF console at https://console.amazonaws.cn/wafv2/
. If you see Switch to Amazon WAF Classic in the navigation pane, select it.
Remove the geo match condition from the rules that are using it:
In the navigation pane, choose Rules.
Choose the name of a rule that is using the geo match condition that you want to delete.
In the right pane, choose Edit rule.
Choose the X next to the condition you want to delete.
Choose Update.
Repeat for all the remaining rules that are using the geo match condition that you want to delete.
Remove the filters from the condition you want to delete:
In the navigation pane, choose Geo match.
Choose the name of the geo match condition that you want to delete.
In the right pane, choose the check box next to Filter in order to select all of the filters.
Choose the Delete filter.
In the navigation pane, choose Geo match.
In the Geo match conditions pane, choose the geo match condition that you want to delete.
Choose Delete to delete the selected condition.