This is an AWS CDK Construct for IP Restrict Rule on WAF V2
npm install @gammarers/aws-waf-ip-restrict-rule
yarn add @gammarers/aws-waf-ip-restrict-rule
pip install gammarers.aws-waf-ip-restrict-rule
import { WAFIPRestrictRule } from '@gammarers/aws-waf-ip-restrict-rule';
const allowedIpSet = new wafv2.CfnIPSet(stack, 'AllowedIpSet', {
addresses: [
'203.0.113.0/24',
'198.51.100.0/24',
],
ipAddressVersion: 'IPV4',
scope: 'CLOUDFRONT',
name: 'AllowedIpSet',
});
const ipRestrictRule = new WAFIPRestrictRule({
allowIPSetArn: allowedIpSet.attrArn,
});
new wafv2.CfnWebACL(stack, 'WebACL', {
defaultAction: { allow: {} },
scope: 'CLOUDFRONT',
name: 'WebAclWithCustomRules',
visibilityConfig: {
cloudWatchMetricsEnabled: true,
metricName: 'WebAclMetric',
sampledRequestsEnabled: true,
},
rules: [
ipRestrictRule.allowRule({ priority: 1 }),
ipRestrictRule.blockRule({ priority: 2 }),
],
});
This project is licensed under the Apache-2.0 License.