Skip to content

Commit

Permalink
introduce logging to WAF, bumping up to 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Park committed Sep 9, 2024
1 parent 58c3bc3 commit 288d968
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 additions & 1 deletion packages/waf/lib/waf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { aws_wafv2 } from "aws-cdk-lib";
import { aws_wafv2, RemovalPolicy } from "aws-cdk-lib";
import { LogGroup, RetentionDays } from "aws-cdk-lib/aws-logs";
import { Construct } from "constructs";

export const REGIONAL = "REGIONAL";
Expand Down Expand Up @@ -76,6 +77,21 @@ export interface WebApplicationFirewallProps {
* Priority numbers must be equal to or bigger than 30
*/
postProcessCustomRules?: aws_wafv2.CfnWebACL.RuleProperty[];

/**
* Enable CloudWatch logging. Default: false
*/
enableLogging?: boolean;

/**
* Define CloudWatch log retention period. Default: 1 year
*/
logRetentionDays?: RetentionDays;

/**
* Define CloudWatch log removal policy. Default: RETAIN
*/
logRemovalPolicy?: RemovalPolicy;
}

export class WebApplicationFirewall extends Construct {
Expand Down Expand Up @@ -391,5 +407,21 @@ export class WebApplicationFirewall extends Construct {
});
});
}

if (props.enableLogging) {
const wafLogGroup = new LogGroup(this, `WAF-Logs-${this.web_acl.name}`, {
retention: props.logRetentionDays
? props.logRetentionDays
: RetentionDays.ONE_YEAR,
removalPolicy: props.logRemovalPolicy
? props.logRemovalPolicy
: RemovalPolicy.RETAIN,
logGroupName: `aws-waf-logs-${this.web_acl.name}`,
});
new aws_wafv2.CfnLoggingConfiguration(this, "CloudWatchLogging", {
logDestinationConfigs: [`${wafLogGroup.logGroupArn}`],
resourceArn: this.web_acl.attrArn,
});
}
}
}
2 changes: 1 addition & 1 deletion packages/waf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aligent/cdk-waf",
"version": "2.1.0",
"version": "2.2.0",
"main": "index.js",
"license": "GPL-3.0-only",
"homepage": "https://github.com/aligent/aws-cdk-waf-stack#readme",
Expand Down

0 comments on commit 288d968

Please sign in to comment.