-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from unstubbable/waf
Associate an AWS WAF web ACL with the CDN
- Loading branch information
Showing
4 changed files
with
83 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import {MainStack} from './main-stack.js'; | ||
import {WafStack} from './waf-stack.js'; | ||
|
||
const app = new cdk.App(); | ||
|
||
const wafStack = new WafStack(app, `mfng-waf`, { | ||
crossRegionReferences: true, | ||
env: { | ||
// For a web ACL with CLOUDFRONT scope, the WAF resources must be created in | ||
// the US East (N. Virginia) Region, us-east-1. | ||
region: `us-east-1`, | ||
}, | ||
}); | ||
|
||
new MainStack(app, `mfng-app`, { | ||
crossRegionReferences: true, | ||
env: { | ||
// Cross stack/region references are only supported for stacks with an | ||
// explicit region defined. | ||
region: process.env.AWS_REGION, | ||
}, | ||
webAcl: wafStack.webAcl, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import type {Construct} from 'constructs'; | ||
|
||
export class WafStack extends cdk.Stack { | ||
#webAcl: cdk.aws_wafv2.CfnWebACL; | ||
|
||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
this.#webAcl = new cdk.aws_wafv2.CfnWebACL(this, `waf`, { | ||
name: `mfng-waf`, | ||
scope: `CLOUDFRONT`, | ||
defaultAction: { | ||
allow: {}, | ||
}, | ||
visibilityConfig: { | ||
cloudWatchMetricsEnabled: false, | ||
metricName: `mfng-waf-metric`, | ||
sampledRequestsEnabled: true, | ||
}, | ||
}); | ||
} | ||
|
||
get webAcl(): cdk.aws_wafv2.CfnWebACL { | ||
return this.#webAcl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters