Skip to content

This is an AWS CDK Construct for IP Restriction Rule Group on WAF V2

License

Notifications You must be signed in to change notification settings

gammarers/aws-waf-ip-restrict-rule

Repository files navigation

AWS WAF(V2) IP Restrict Rule

GitHub npm (scoped) PyPI GitHub Workflow Status (branch) GitHub release (latest SemVer)

View on Construct Hub

This is an AWS CDK Construct for IP Restrict Rule on WAF V2

Install

TypeScript

install by npm

npm install @gammarers/aws-waf-ip-restrict-rule

install by yarn

yarn add @gammarers/aws-waf-ip-restrict-rule

Python

pip install gammarers.aws-waf-ip-restrict-rule

Example

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 }),
  ],
});

License

This project is licensed under the Apache-2.0 License.