Skip to content

Commit

Permalink
fix(waf-v2): include Region dimension if specified (#317)
Browse files Browse the repository at this point in the history
The metrics specifically have a `Region` dimension when using a regional Web ACL (as opposed to a global Cloudfront one that lacks that dimension).

Also explicitly specify a `name` for the test resources, as it seems like `CfnWebACL` doesn't return a `name` if you don't set it.

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
  • Loading branch information
echeung-amzn authored Jan 28, 2023
1 parent 9002122 commit fdd5ac1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
8 changes: 6 additions & 2 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion lib/monitoring/aws-wafv2/WafV2MetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ const MetricNamespace = "AWS/WAFV2";
const AllRulesDimensionValue = "ALL";

export interface WafV2MetricFactoryProps {
readonly region?: string;
readonly acl: CfnWebACL;

/**
* Required if acl has a "REGIONAL" scope.
*/
readonly region?: string;
}

/**
Expand All @@ -22,6 +26,7 @@ export class WafV2MetricFactory {
this.dimensions = {
Rule: AllRulesDimensionValue,
WebACL: props.acl.name,
...(props.region && { Region: props.region }),
};
}

Expand Down
6 changes: 4 additions & 2 deletions test/monitoring/aws-wafv2/WafV2Monitoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TestMonitoringScope } from "../TestMonitoringScope";
test("snapshot test: no alarms", () => {
const stack = new Stack();
const acl = new CfnWebACL(stack, "DummyAcl", {
name: "DummyAclName",
defaultAction: { allow: {} },
scope: "REGIONAL",
visibilityConfig: {
Expand All @@ -20,7 +21,7 @@ test("snapshot test: no alarms", () => {

const scope = new TestMonitoringScope(stack, "Scope");

const monitoring = new WafV2Monitoring(scope, { acl });
const monitoring = new WafV2Monitoring(scope, { acl, region: "us-east-1" });

addMonitoringDashboardsToStack(stack, monitoring);
expect(Template.fromStack(stack)).toMatchSnapshot();
Expand All @@ -29,8 +30,9 @@ test("snapshot test: no alarms", () => {
test("snapshot test: all alarms", () => {
const stack = new Stack();
const acl = new CfnWebACL(stack, "DummyAcl", {
name: "DummyAclName",
defaultAction: { allow: {} },
scope: "REGIONAL",
scope: "CLOUDFRONT",
visibilityConfig: {
sampledRequestsEnabled: true,
cloudWatchMetricsEnabled: true,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fdd5ac1

Please sign in to comment.