@jaypie/constructs 1.2.44 → 1.2.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,15 @@ import * as wafv2 from "aws-cdk-lib/aws-wafv2";
9
9
  import { Construct } from "constructs";
10
10
  import { HostConfig } from "./helpers";
11
11
  export interface JaypieWafConfig {
12
+ /**
13
+ * Unique name for this distribution's WAF resources. Required when passing a
14
+ * WAF config object. Injected into the WebACL name and WAF log bucket name
15
+ * so multiple JaypieDistribution instances can coexist in the same
16
+ * account/env without S3/WAFv2 name collisions.
17
+ *
18
+ * Pass `waf: true` (or omit) to retain the legacy, non-namespaced names.
19
+ */
20
+ name: string;
12
21
  /**
13
22
  * Whether WAF is enabled
14
23
  * @default true
@@ -2689,14 +2689,17 @@ class JaypieDistribution extends constructs.Construct {
2689
2689
  sampledRequestsEnabled: true,
2690
2690
  },
2691
2691
  });
2692
+ const webAclName = wafConfig.name
2693
+ ? constructEnvName(`${wafConfig.name}-WebAcl`)
2694
+ : constructEnvName("WebAcl");
2692
2695
  const webAcl = new wafv2__namespace.CfnWebACL(this, "WebAcl", {
2693
2696
  defaultAction: { allow: {} },
2694
- name: constructEnvName("WebAcl"),
2697
+ name: webAclName,
2695
2698
  rules,
2696
2699
  scope: "CLOUDFRONT",
2697
2700
  visibilityConfig: {
2698
2701
  cloudWatchMetricsEnabled: true,
2699
- metricName: constructEnvName("WebAcl"),
2702
+ metricName: webAclName,
2700
2703
  sampledRequestsEnabled: true,
2701
2704
  },
2702
2705
  });
@@ -2712,8 +2715,14 @@ class JaypieDistribution extends constructs.Construct {
2712
2715
  let wafLogBucket;
2713
2716
  if (wafLogBucketProp === true) {
2714
2717
  // Create inline WAF logging bucket with Datadog forwarding
2715
- const createdBucket = new s3__namespace.Bucket(this, constructEnvName("WafLogBucket"), {
2716
- bucketName: `aws-waf-logs-${constructEnvName("waf").toLowerCase()}`,
2718
+ const wafLogBucketId = wafConfig.name
2719
+ ? constructEnvName(`${wafConfig.name}-WafLogBucket`)
2720
+ : constructEnvName("WafLogBucket");
2721
+ const wafLogBucketName = wafConfig.name
2722
+ ? `aws-waf-logs-${constructEnvName(`${wafConfig.name}-waf`).toLowerCase()}`
2723
+ : `aws-waf-logs-${constructEnvName("waf").toLowerCase()}`;
2724
+ const createdBucket = new s3__namespace.Bucket(this, wafLogBucketId, {
2725
+ bucketName: wafLogBucketName,
2717
2726
  lifecycleRules: [
2718
2727
  {
2719
2728
  expiration: cdk.Duration.days(90),