@flipboxlabs/aws-audit-cdk 1.1.0 → 1.1.2

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.
Files changed (41) hide show
  1. package/README.md +92 -9
  2. package/dist/audit-config.d.ts +11 -10
  3. package/dist/audit-config.d.ts.map +1 -1
  4. package/dist/audit-config.js +9 -8
  5. package/dist/cloudwatch/construct.d.ts +6 -0
  6. package/dist/cloudwatch/construct.d.ts.map +1 -1
  7. package/dist/cloudwatch/construct.js +9 -8
  8. package/dist/index.d.ts +2 -43
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +2 -43
  11. package/dist/lambda/audit-config-layer.d.ts +40 -0
  12. package/dist/lambda/audit-config-layer.d.ts.map +1 -0
  13. package/dist/lambda/audit-config-layer.js +50 -0
  14. package/dist/lambda/construct.d.ts +7 -0
  15. package/dist/lambda/construct.d.ts.map +1 -0
  16. package/dist/lambda/construct.js +6 -0
  17. package/dist/lambda/nodejs.function.d.ts +16 -0
  18. package/dist/lambda/nodejs.function.d.ts.map +1 -0
  19. package/dist/{lib → lambda}/nodejs.function.js +14 -1
  20. package/dist/rest-api/construct.d.ts +6 -0
  21. package/dist/rest-api/construct.d.ts.map +1 -1
  22. package/dist/rest-api/resources/app/construct.d.ts +6 -0
  23. package/dist/rest-api/resources/app/construct.d.ts.map +1 -1
  24. package/dist/rest-api/resources/app/construct.js +1 -0
  25. package/dist/rest-api/resources/app/resources/objects/construct.d.ts +6 -0
  26. package/dist/rest-api/resources/app/resources/objects/construct.d.ts.map +1 -1
  27. package/dist/rest-api/resources/app/resources/objects/construct.js +7 -5
  28. package/dist/rest-api/resources/app/resources/objects/resources/rerun/construct.d.ts +6 -0
  29. package/dist/rest-api/resources/app/resources/objects/resources/rerun/construct.d.ts.map +1 -1
  30. package/dist/rest-api/resources/app/resources/objects/resources/rerun/construct.js +7 -6
  31. package/dist/rest-api/resources/construct.d.ts +6 -0
  32. package/dist/rest-api/resources/construct.d.ts.map +1 -1
  33. package/dist/rest-api/resources/trace/construct.d.ts +6 -0
  34. package/dist/rest-api/resources/trace/construct.d.ts.map +1 -1
  35. package/dist/rest-api/resources/trace/construct.js +6 -5
  36. package/package.json +5 -5
  37. package/dist/lib/index.d.ts +0 -53
  38. package/dist/lib/index.d.ts.map +0 -1
  39. package/dist/lib/index.js +0 -52
  40. package/dist/lib/nodejs.function.d.ts +0 -6
  41. package/dist/lib/nodejs.function.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @flipboxlabs/aws-audit-cdk
2
2
 
3
- AWS Audit CDK - CDK constructs for AWS audit infrastructure.
3
+ AWS Audit CDK - CDK constructs for AWS audit infrastructure
4
4
 
5
5
  ## Installation
6
6
 
@@ -13,18 +13,101 @@ pnpm add @flipboxlabs/aws-audit-cdk
13
13
  ## Usage
14
14
 
15
15
  ```typescript
16
- import { CloudWatchConstruct } from '@flipboxlabs/aws-audit-cdk/cloudwatch';
17
- import { DynamoDBConstruct } from '@flipboxlabs/aws-audit-cdk/dynamodb';
18
- import { EventBridgeConstruct } from '@flipboxlabs/aws-audit-cdk/eventbridge';
19
- import { RestApiConstruct } from '@flipboxlabs/aws-audit-cdk/rest-api';
16
+ import * as cdk from "aws-cdk-lib";
17
+ import type { Construct } from "constructs";
18
+ import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
19
+ import { AuditConfigLayer } from "@flipboxlabs/aws-audit-cdk/lambda";
20
+ import { CloudWatchConstruct as CloudWatch } from "@flipboxlabs/aws-audit-cdk/cloudwatch";
21
+ import { DynamoDBConstruct as DynamoDB } from "@flipboxlabs/aws-audit-cdk/dynamodb";
22
+ import { EventBridgeConstruct as EventBridge } from "@flipboxlabs/aws-audit-cdk/eventbridge";
23
+ import { RestApiConstruct as RestAPI } from "@flipboxlabs/aws-audit-cdk/rest-api";
24
+
25
+ interface Props {
26
+ config: CDKConfig;
27
+ }
28
+
29
+ export class AuditStack extends cdk.NestedStack {
30
+ constructor(scope: Construct, id: string, props: Props) {
31
+ super(scope, id, { description: "Audit" });
32
+
33
+ // Create audit config layer with your apps and resource types
34
+ const auditConfigLayer = new AuditConfigLayer(this, "AuditConfigLayer", {
35
+ apps: ["Orders", "Inventory"],
36
+ resourceTypes: ["Order", "Product"],
37
+ });
38
+
39
+ // DynamoDB (storage)
40
+ const { table } = new DynamoDB(this, "DynamoDB", { config: props.config });
41
+
42
+ // EventBridge (events)
43
+ const { eventBus } = new EventBridge(this, "EventBridge", {
44
+ config: props.config,
45
+ });
46
+
47
+ // CloudWatch (logging subscription)
48
+ new CloudWatch(this, "CloudWatch", {
49
+ config: props.config,
50
+ lambda: { layers: [auditConfigLayer.layer] },
51
+ table,
52
+ eventBus,
53
+ });
54
+
55
+ // REST API (optional)
56
+ new RestAPI(this, "RestAPI", {
57
+ config: props.config,
58
+ lambda: { layers: [auditConfigLayer.layer] },
59
+ table,
60
+ eventBus,
61
+ });
62
+ }
63
+ }
20
64
  ```
21
65
 
22
66
  ## Constructs
23
67
 
24
- - **CloudWatchConstruct** - CloudWatch log subscription for audit capture
25
- - **DynamoDBConstruct** - DynamoDB table for audit storage
26
- - **EventBridgeConstruct** - EventBridge bus for audit events
27
- - **RestApiConstruct** - REST API for querying audits
68
+ ### AuditConfigLayer
69
+
70
+ Creates a Lambda layer containing your audit configuration (apps and resource types). This layer is required by all other constructs.
71
+
72
+ ```typescript
73
+ import { AuditConfigLayer } from "@flipboxlabs/aws-audit-cdk/lambda";
74
+
75
+ const auditConfigLayer = new AuditConfigLayer(this, "AuditConfigLayer", {
76
+ apps: ["Orders", "Inventory"],
77
+ resourceTypes: ["Order", "Product"],
78
+ });
79
+ ```
80
+
81
+ ### CloudWatchConstruct
82
+
83
+ CloudWatch log subscription that captures audit logs and stores them in DynamoDB.
84
+
85
+ ### DynamoDBConstruct
86
+
87
+ DynamoDB table for audit storage with optimized indexes for querying by app, resource, and trace.
88
+
89
+ ### EventBridgeConstruct
90
+
91
+ EventBridge bus for audit events, enabling event-driven architectures.
92
+
93
+ ### RestApiConstruct
94
+
95
+ REST API for querying audits by resource or trace ID.
96
+
97
+ ## CDKConfig
98
+
99
+ The `CDKConfig` type defines the configuration passed to constructs:
100
+
101
+ ```typescript
102
+ type CDKConfig = {
103
+ env: string; // Environment name (e.g., "prod", "staging")
104
+ aws: {
105
+ account: string; // AWS account ID
106
+ region: string; // AWS region
107
+ };
108
+ service?: string; // Optional service name
109
+ };
110
+ ```
28
111
 
29
112
  ## Peer Dependencies
30
113
 
@@ -1,14 +1,13 @@
1
1
  /**
2
- * Shared audit configuration for the CDK.
2
+ * Audit configuration loaded from the Lambda layer.
3
3
  *
4
- * Defines the valid apps and resource types used across all handlers and schemas.
5
- * This config provides:
6
- * - Type-safe app and resourceType values
7
- * - Zod schemas for validation via `auditConfig.schemas`
4
+ * The `apps` and `resourceTypes` arrays are provided by the AuditConfigLayer
5
+ * construct at deploy time. This file creates the typed configuration object
6
+ * that handlers use.
8
7
  *
9
8
  * @example
10
9
  * ```typescript
11
- * import { auditConfig } from '../../audit-config.js';
10
+ * import { auditConfig, type App, type ResourceType } from '../../audit-config.js';
12
11
  *
13
12
  * // Use in handlers
14
13
  * const service = new AuditService(logger, auditConfig);
@@ -23,8 +22,8 @@
23
22
  export declare const auditConfig: {
24
23
  service: string | undefined;
25
24
  } & {
26
- readonly apps: readonly [];
27
- readonly resourceTypes: readonly [];
25
+ readonly apps: readonly string[];
26
+ readonly resourceTypes: readonly string[];
28
27
  } & {
29
28
  schemas: {
30
29
  app: import("zod").ZodEnum<{
@@ -44,16 +43,18 @@ export declare const auditConfig: {
44
43
  }, import("zod/v4/core").$strip>;
45
44
  };
46
45
  _types: {
47
- App: never;
48
- ResourceType: never;
46
+ App: string;
47
+ ResourceType: string;
49
48
  };
50
49
  };
51
50
  /**
52
51
  * Type alias for the App union type from the audit config.
52
+ * Note: At compile time this is `string` since the actual values come from the layer.
53
53
  */
54
54
  export type App = (typeof auditConfig)["_types"]["App"];
55
55
  /**
56
56
  * Type alias for the ResourceType union type from the audit config.
57
+ * Note: At compile time this is `string` since the actual values come from the layer.
57
58
  */
58
59
  export type ResourceType = (typeof auditConfig)["_types"]["ResourceType"];
59
60
  //# sourceMappingURL=audit-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"audit-config.d.ts","sourceRoot":"","sources":["../src/audit-config.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGtB,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,CAAC"}
1
+ {"version":3,"file":"audit-config.d.ts","sourceRoot":"","sources":["../src/audit-config.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,WAAW;;;mBACT,SAAS,MAAM,EAAE;4BACC,SAAS,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;CAChD,CAAC;AAEH;;;GAGG;AACH,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,CAAC"}
@@ -1,15 +1,16 @@
1
1
  import { defineAuditConfig } from "@flipboxlabs/aws-audit-sdk";
2
+ // @ts-expect-error - This import is resolved at runtime from the Lambda layer
3
+ import { apps, resourceTypes } from "/opt/nodejs/audit-config.js";
2
4
  /**
3
- * Shared audit configuration for the CDK.
5
+ * Audit configuration loaded from the Lambda layer.
4
6
  *
5
- * Defines the valid apps and resource types used across all handlers and schemas.
6
- * This config provides:
7
- * - Type-safe app and resourceType values
8
- * - Zod schemas for validation via `auditConfig.schemas`
7
+ * The `apps` and `resourceTypes` arrays are provided by the AuditConfigLayer
8
+ * construct at deploy time. This file creates the typed configuration object
9
+ * that handlers use.
9
10
  *
10
11
  * @example
11
12
  * ```typescript
12
- * import { auditConfig } from '../../audit-config.js';
13
+ * import { auditConfig, type App, type ResourceType } from '../../audit-config.js';
13
14
  *
14
15
  * // Use in handlers
15
16
  * const service = new AuditService(logger, auditConfig);
@@ -22,6 +23,6 @@ import { defineAuditConfig } from "@flipboxlabs/aws-audit-sdk";
22
23
  * ```
23
24
  */
24
25
  export const auditConfig = defineAuditConfig({
25
- apps: [],
26
- resourceTypes: [],
26
+ apps: apps,
27
+ resourceTypes: resourceTypes,
27
28
  });
@@ -1,11 +1,17 @@
1
1
  import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
2
  import type * as dynamodb from "aws-cdk-lib/aws-dynamodb";
3
3
  import type * as events from "aws-cdk-lib/aws-events";
4
+ import type * as lambda from "aws-cdk-lib/aws-lambda";
4
5
  import { Construct } from "constructs";
5
6
  type Props = {
6
7
  config: CDKConfig;
7
8
  table: dynamodb.ITable;
8
9
  eventBus: events.IEventBus;
10
+ /** Lambda configuration */
11
+ lambda: {
12
+ /** Lambda layers to attach to the function */
13
+ layers: lambda.ILayerVersion[];
14
+ };
9
15
  subscriptionFilter?: {
10
16
  /** Scope of the subscription filter policy. Defaults to "ALL". */
11
17
  scope?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../src/cloudwatch/construct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAGtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAE3B,kBAAkB,CAAC,EAAE;QACpB,kEAAkE;QAClE,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,oGAAoG;QACpG,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;CACF,CAAC;AAEF,qBAAa,mBAAoB,SAAQ,SAAS;gBACrC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAoDtD"}
1
+ {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../src/cloudwatch/construct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAEtD,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAC3B,2BAA2B;IAC3B,MAAM,EAAE;QACP,8CAA8C;QAC9C,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;KAC/B,CAAC;IAEF,kBAAkB,CAAC,EAAE;QACpB,kEAAkE;QAClE,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,oGAAoG;QACpG,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;CACF,CAAC;AAEF,qBAAa,mBAAoB,SAAQ,SAAS;gBACrC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAyDtD"}
@@ -3,25 +3,26 @@ import { AUDIT_LOG_IDENTIFIER } from "@flipboxlabs/aws-audit-sdk";
3
3
  import { ServicePrincipal } from "aws-cdk-lib/aws-iam";
4
4
  import * as logs from "aws-cdk-lib/aws-logs";
5
5
  import { Construct } from "constructs";
6
- import { ESMNodeFunctionFactory } from "../lib/index.js";
6
+ import { ESMNodeFunctionFactory } from "../lambda/nodejs.function.js";
7
7
  export class CloudWatchConstruct extends Construct {
8
8
  constructor(scope, id, props) {
9
9
  super(scope, id);
10
10
  const ref = `${[props.config.env.toUpperCase(), "Account", "CloudWatch", "Subscription"].join("-")}`;
11
11
  // Lambda Function
12
- const lambda = ESMNodeFunctionFactory(props.config)(this, "subscription", {
12
+ const lambdaFn = ESMNodeFunctionFactory(props.config)(this, "subscription", {
13
13
  functionName: ref,
14
14
  entry: url.fileURLToPath(new URL("subscription.handler.ts", import.meta.url).toString()),
15
+ layers: props.lambda.layers,
15
16
  currentVersionOptions: {
16
17
  retryAttempts: 2,
17
18
  },
18
19
  });
19
20
  // Allow writes to DynamoDB
20
- props.table.grantWriteData(lambda);
21
+ props.table.grantWriteData(lambdaFn);
21
22
  // Allow puts to EventBridge
22
- props.eventBus.grantPutEventsTo(lambda);
23
+ props.eventBus.grantPutEventsTo(lambdaFn);
23
24
  // Permissions
24
- lambda.addPermission("LogProcessorPermission", {
25
+ lambdaFn.addPermission("LogProcessorPermission", {
25
26
  principal: new ServicePrincipal("logs.amazonaws.com"),
26
27
  action: "lambda:InvokeFunction",
27
28
  sourceArn: `arn:aws:logs:${props.config.aws.region}:${props.config.aws.account}:log-group:*`,
@@ -32,15 +33,15 @@ export class CloudWatchConstruct extends Construct {
32
33
  policyName: `${props.config.env.toUpperCase()}AccountLevelSubscriptionPolicy`,
33
34
  policyType: "SUBSCRIPTION_FILTER_POLICY",
34
35
  policyDocument: JSON.stringify({
35
- DestinationArn: lambda.functionArn,
36
+ DestinationArn: lambdaFn.functionArn,
36
37
  Distribution: "Random",
37
38
  FilterPattern: `{ $.${AUDIT_LOG_IDENTIFIER}.operation = * }`,
38
39
  }),
39
40
  scope: props.subscriptionFilter?.scope ?? "ALL",
40
41
  selectionCriteria: props.subscriptionFilter?.selectionCriteria ??
41
- `LogGroupName NOT IN ["/aws/lambda/${lambda.functionName}"]`,
42
+ `LogGroupName NOT IN ["/aws/lambda/${lambdaFn.functionName}"]`,
42
43
  });
43
44
  // Add explicit dependency on the Lambda function
44
- accountPolicy.node.addDependency(lambda);
45
+ accountPolicy.node.addDependency(lambdaFn);
45
46
  }
46
47
  }
package/dist/index.d.ts CHANGED
@@ -4,50 +4,9 @@
4
4
  * Provides constructs for deploying audit infrastructure. Import and compose
5
5
  * the constructs in your own stack as needed.
6
6
  *
7
- * @example
8
- * ```typescript
9
- * import * as cdk from "aws-cdk-lib";
10
- * import type { Construct } from "constructs";
11
- * import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
7
+ * See the README for full usage examples.
12
8
  *
13
- * // Import constructs from the bootstrap directory
14
- * import { CloudWatchConstruct as CloudWatch } from "@flipboxlabs/aws-audit-cdk/cloudwatch";
15
- * import { DynamoDBConstruct as DynamoDB } from "@flipboxlabs/aws-audit-cdk/dynamodb";
16
- * import { EventBridgeConstruct as EventBridge } from "@flipboxlabs/aws-audit-cdk/eventbridge";
17
- * import { RestApiConstruct as RestAPI } from "@flipboxlabs/aws-audit-cdk/rest-api";
18
- *
19
- * interface Props {
20
- * config: CDKConfig;
21
- * }
22
- *
23
- * export class AuditStack extends cdk.NestedStack {
24
- * constructor(scope: Construct, id: string, props: Props) {
25
- * super(scope, id, { description: "Audit" });
26
- *
27
- * // DynamoDB (storage)
28
- * const { table } = new DynamoDB(this, "DynamoDB", { config: props.config });
29
- *
30
- * // EventBridge (events)
31
- * const { eventBus } = new EventBridge(this, "EventBridge", {
32
- * config: props.config,
33
- * });
34
- *
35
- * // CloudWatch (logging subscription)
36
- * new CloudWatch(this, "CloudWatch", {
37
- * config: props.config,
38
- * table,
39
- * eventBus,
40
- * });
41
- *
42
- * // REST API (optional)
43
- * new RestAPI(this, "RestAPI", {
44
- * config: props.config,
45
- * table,
46
- * eventBus,
47
- * });
48
- * }
49
- * }
50
- * ```
9
+ * @packageDocumentation
51
10
  */
52
11
  export * from "./constants.js";
53
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -4,49 +4,8 @@
4
4
  * Provides constructs for deploying audit infrastructure. Import and compose
5
5
  * the constructs in your own stack as needed.
6
6
  *
7
- * @example
8
- * ```typescript
9
- * import * as cdk from "aws-cdk-lib";
10
- * import type { Construct } from "constructs";
11
- * import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
7
+ * See the README for full usage examples.
12
8
  *
13
- * // Import constructs from the bootstrap directory
14
- * import { CloudWatchConstruct as CloudWatch } from "@flipboxlabs/aws-audit-cdk/cloudwatch";
15
- * import { DynamoDBConstruct as DynamoDB } from "@flipboxlabs/aws-audit-cdk/dynamodb";
16
- * import { EventBridgeConstruct as EventBridge } from "@flipboxlabs/aws-audit-cdk/eventbridge";
17
- * import { RestApiConstruct as RestAPI } from "@flipboxlabs/aws-audit-cdk/rest-api";
18
- *
19
- * interface Props {
20
- * config: CDKConfig;
21
- * }
22
- *
23
- * export class AuditStack extends cdk.NestedStack {
24
- * constructor(scope: Construct, id: string, props: Props) {
25
- * super(scope, id, { description: "Audit" });
26
- *
27
- * // DynamoDB (storage)
28
- * const { table } = new DynamoDB(this, "DynamoDB", { config: props.config });
29
- *
30
- * // EventBridge (events)
31
- * const { eventBus } = new EventBridge(this, "EventBridge", {
32
- * config: props.config,
33
- * });
34
- *
35
- * // CloudWatch (logging subscription)
36
- * new CloudWatch(this, "CloudWatch", {
37
- * config: props.config,
38
- * table,
39
- * eventBus,
40
- * });
41
- *
42
- * // REST API (optional)
43
- * new RestAPI(this, "RestAPI", {
44
- * config: props.config,
45
- * table,
46
- * eventBus,
47
- * });
48
- * }
49
- * }
50
- * ```
9
+ * @packageDocumentation
51
10
  */
52
11
  export * from "./constants.js";
@@ -0,0 +1,40 @@
1
+ import * as lambda from "aws-cdk-lib/aws-lambda";
2
+ import { Construct } from "constructs";
3
+ /**
4
+ * Input configuration for the audit config layer.
5
+ * Contains the apps and resource types that will be available to Lambda handlers.
6
+ */
7
+ export interface AuditConfigLayerProps {
8
+ /** List of valid application identifiers */
9
+ readonly apps: readonly string[];
10
+ /** List of valid resource type identifiers */
11
+ readonly resourceTypes: readonly string[];
12
+ }
13
+ /**
14
+ * Path where handlers should import the audit config from.
15
+ * This is the standard Lambda layer path for Node.js.
16
+ */
17
+ export declare const AUDIT_CONFIG_LAYER_PATH = "/opt/nodejs/audit-config.js";
18
+ /**
19
+ * Creates a Lambda layer containing the audit configuration.
20
+ *
21
+ * The layer exports raw `apps` and `resourceTypes` arrays that handlers
22
+ * can use with `defineAuditConfig` from the SDK.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * import { AuditConfigLayer } from "@flipboxlabs/aws-audit-cdk";
27
+ *
28
+ * const auditLayer = new AuditConfigLayer(this, "AuditConfigLayer", {
29
+ * apps: ["Orders", "Inventory"],
30
+ * resourceTypes: ["Order", "Product"],
31
+ * });
32
+ *
33
+ * // Pass auditLayer.layer to constructs that need it
34
+ * ```
35
+ */
36
+ export declare class AuditConfigLayer extends Construct {
37
+ readonly layer: lambda.LayerVersion;
38
+ constructor(scope: Construct, id: string, props: AuditConfigLayerProps);
39
+ }
40
+ //# sourceMappingURL=audit-config-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-config-layer.d.ts","sourceRoot":"","sources":["../../src/lambda/audit-config-layer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACrC,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,8CAA8C;IAC9C,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,gCAAgC,CAAC;AAErE;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;IAC9C,SAAgB,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC;gBAE/B,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB;CAuBtE"}
@@ -0,0 +1,50 @@
1
+ import * as fs from "node:fs";
2
+ import * as os from "node:os";
3
+ import * as path from "node:path";
4
+ import * as lambda from "aws-cdk-lib/aws-lambda";
5
+ import { Construct } from "constructs";
6
+ /**
7
+ * Path where handlers should import the audit config from.
8
+ * This is the standard Lambda layer path for Node.js.
9
+ */
10
+ export const AUDIT_CONFIG_LAYER_PATH = "/opt/nodejs/audit-config.js";
11
+ /**
12
+ * Creates a Lambda layer containing the audit configuration.
13
+ *
14
+ * The layer exports raw `apps` and `resourceTypes` arrays that handlers
15
+ * can use with `defineAuditConfig` from the SDK.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { AuditConfigLayer } from "@flipboxlabs/aws-audit-cdk";
20
+ *
21
+ * const auditLayer = new AuditConfigLayer(this, "AuditConfigLayer", {
22
+ * apps: ["Orders", "Inventory"],
23
+ * resourceTypes: ["Order", "Product"],
24
+ * });
25
+ *
26
+ * // Pass auditLayer.layer to constructs that need it
27
+ * ```
28
+ */
29
+ export class AuditConfigLayer extends Construct {
30
+ layer;
31
+ constructor(scope, id, props) {
32
+ super(scope, id);
33
+ // Generate config file content - exports raw data
34
+ // Handlers will call defineAuditConfig themselves
35
+ const configCode = `// Auto-generated audit configuration
36
+ export const apps = ${JSON.stringify(props.apps)};
37
+ export const resourceTypes = ${JSON.stringify(props.resourceTypes)};
38
+ `;
39
+ // Create temp directory with proper layer structure
40
+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "audit-config-"));
41
+ const nodejsDir = path.join(tempDir, "nodejs");
42
+ fs.mkdirSync(nodejsDir);
43
+ fs.writeFileSync(path.join(nodejsDir, "audit-config.js"), configCode);
44
+ this.layer = new lambda.LayerVersion(this, "Layer", {
45
+ code: lambda.Code.fromAsset(tempDir),
46
+ compatibleRuntimes: [lambda.Runtime.NODEJS_20_X],
47
+ description: "Audit configuration layer containing apps and resourceTypes",
48
+ });
49
+ }
50
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Lambda layer constructs for AWS Audit CDK.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export * from "./audit-config-layer.js";
7
+ //# sourceMappingURL=construct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../src/lambda/construct.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Lambda layer constructs for AWS Audit CDK.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export * from "./audit-config-layer.js";
@@ -0,0 +1,16 @@
1
+ import * as cdk from "aws-cdk-lib";
2
+ import * as nodejs from "aws-cdk-lib/aws-lambda-nodejs";
3
+ import type { Construct } from "constructs";
4
+ import type { CDKConfig } from "../constants.js";
5
+ /**
6
+ * Factory function that creates ESM Node.js Lambda functions with standard configuration.
7
+ *
8
+ * The audit config layer should be passed via the `layers` prop in NodejsFunctionProps.
9
+ *
10
+ * @param config - CDK configuration for environment variables
11
+ * @returns A function that creates configured NodejsFunction instances
12
+ *
13
+ * @internal
14
+ */
15
+ export declare const ESMNodeFunctionFactory: (config: CDKConfig) => (scope: Construct, id: string, props: nodejs.NodejsFunctionProps) => cdk.aws_lambda_nodejs.NodejsFunction;
16
+ //# sourceMappingURL=nodejs.function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodejs.function.d.ts","sourceRoot":"","sources":["../../src/lambda/nodejs.function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAGnC,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAC;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,SAAS,MACjB,OAAO,SAAS,EAAE,IAAI,MAAM,EAAE,OAAO,MAAM,CAAC,mBAAmB,yCA2D/D,CAAC"}
@@ -3,6 +3,17 @@ import * as iam from "aws-cdk-lib/aws-iam";
3
3
  import * as lambda from "aws-cdk-lib/aws-lambda";
4
4
  import * as nodejs from "aws-cdk-lib/aws-lambda-nodejs";
5
5
  import * as logs from "aws-cdk-lib/aws-logs";
6
+ import { AUDIT_CONFIG_LAYER_PATH } from "./audit-config-layer.js";
7
+ /**
8
+ * Factory function that creates ESM Node.js Lambda functions with standard configuration.
9
+ *
10
+ * The audit config layer should be passed via the `layers` prop in NodejsFunctionProps.
11
+ *
12
+ * @param config - CDK configuration for environment variables
13
+ * @returns A function that creates configured NodejsFunction instances
14
+ *
15
+ * @internal
16
+ */
6
17
  export const ESMNodeFunctionFactory = (config) => (scope, id, props) => {
7
18
  const nodejsFunction = new nodejs.NodejsFunction(scope, id, {
8
19
  tracing: lambda.Tracing.ACTIVE,
@@ -14,7 +25,8 @@ export const ESMNodeFunctionFactory = (config) => (scope, id, props) => {
14
25
  bundling: {
15
26
  minify: true,
16
27
  metafile: false,
17
- externalModules: ["aws-sdk", "@aws-sdk/*"],
28
+ // Mark audit config layer path as external so esbuild doesn't try to bundle it
29
+ externalModules: ["aws-sdk", "@aws-sdk/*", AUDIT_CONFIG_LAYER_PATH],
18
30
  format: nodejs.OutputFormat.ESM,
19
31
  platform: "node",
20
32
  target: "esnext",
@@ -43,6 +55,7 @@ export const ESMNodeFunctionFactory = (config) => (scope, id, props) => {
43
55
  if (config.service) {
44
56
  nodejsFunction.addEnvironment("SERVICE", config.service);
45
57
  }
58
+ // Add Lambda Insights layer
46
59
  nodejsFunction.addLayers(lambda.LayerVersion.fromLayerVersionArn(scope, `${id}InsightLayer`, `arn:aws:lambda:${cdk.Stack.of(scope).region}:580247275435:layer:LambdaInsightsExtension-Arm64:2`));
47
60
  return nodejsFunction;
48
61
  };
@@ -2,11 +2,17 @@ import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
2
  import * as apigateway from "aws-cdk-lib/aws-apigateway";
3
3
  import type * as dynamodb from "aws-cdk-lib/aws-dynamodb";
4
4
  import type * as events from "aws-cdk-lib/aws-events";
5
+ import type * as lambda from "aws-cdk-lib/aws-lambda";
5
6
  import { Construct } from "constructs";
6
7
  type Props = {
7
8
  config: CDKConfig;
8
9
  table: dynamodb.ITable;
9
10
  eventBus: events.IEventBus;
11
+ /** Lambda configuration */
12
+ lambda: {
13
+ /** Lambda layers to attach to the function */
14
+ layers: lambda.ILayerVersion[];
15
+ };
10
16
  /** Override REST API props. */
11
17
  restApi?: Partial<apigateway.RestApiProps>;
12
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../src/rest-api/construct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAC3B,+BAA+B;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;CAC3C,CAAC;AAIF,qBAAa,gBAAiB,SAAQ,SAAS;IAC9C,SAAgB,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;gBAEhC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CA6BtD"}
1
+ {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../src/rest-api/construct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAC3B,2BAA2B;IAC3B,MAAM,EAAE;QACP,8CAA8C;QAC9C,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;KAC/B,CAAC;IACF,+BAA+B;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;CAC3C,CAAC;AAIF,qBAAa,gBAAiB,SAAQ,SAAS;IAC9C,SAAgB,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;gBAEhC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CA6BtD"}
@@ -2,11 +2,17 @@ import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
2
  import type * as apigateway from "aws-cdk-lib/aws-apigateway";
3
3
  import type * as dynamodb from "aws-cdk-lib/aws-dynamodb";
4
4
  import type * as events from "aws-cdk-lib/aws-events";
5
+ import type * as lambda from "aws-cdk-lib/aws-lambda";
5
6
  import { Construct } from "constructs";
6
7
  type Props = {
7
8
  config: CDKConfig;
8
9
  table: dynamodb.ITable;
9
10
  eventBus: events.IEventBus;
11
+ /** Lambda configuration */
12
+ lambda: {
13
+ /** Lambda layers to attach to the function */
14
+ layers: lambda.ILayerVersion[];
15
+ };
10
16
  restApi: {
11
17
  resource: apigateway.IResource;
12
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../../../src/rest-api/resources/app/construct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAC3B,OAAO,EAAE;QACR,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,MAAO,SAAQ,SAAS;gBACzB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CActD"}
1
+ {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../../../src/rest-api/resources/app/construct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAC3B,2BAA2B;IAC3B,MAAM,EAAE;QACP,8CAA8C;QAC9C,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;KAC/B,CAAC;IACF,OAAO,EAAE;QACR,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,MAAO,SAAQ,SAAS;gBACzB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAetD"}
@@ -8,6 +8,7 @@ export default class extends Construct {
8
8
  config: props.config,
9
9
  table: props.table,
10
10
  eventBus: props.eventBus,
11
+ lambda: props.lambda,
11
12
  restApi: {
12
13
  resource: props.restApi.resource
13
14
  .addResource(API_RESOURCE.RESOURCE)
@@ -2,11 +2,17 @@ import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
2
  import * as apigateway from "aws-cdk-lib/aws-apigateway";
3
3
  import type * as dynamodb from "aws-cdk-lib/aws-dynamodb";
4
4
  import type * as events from "aws-cdk-lib/aws-events";
5
+ import type * as lambda from "aws-cdk-lib/aws-lambda";
5
6
  import { Construct } from "constructs";
6
7
  type Props = {
7
8
  config: CDKConfig;
8
9
  table: dynamodb.ITable;
9
10
  eventBus: events.IEventBus;
11
+ /** Lambda configuration */
12
+ lambda: {
13
+ /** Lambda layers to attach to the function */
14
+ layers: lambda.ILayerVersion[];
15
+ };
10
16
  restApi: {
11
17
  resource: apigateway.IResource;
12
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../../../../../src/rest-api/resources/app/resources/objects/construct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAC3B,OAAO,EAAE;QACR,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,MAAO,SAAQ,SAAS;gBACzB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAuDtD"}
1
+ {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../../../../../src/rest-api/resources/app/resources/objects/construct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAC3B,2BAA2B;IAC3B,MAAM,EAAE;QACP,8CAA8C;QAC9C,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;KAC/B,CAAC;IACF,OAAO,EAAE;QACR,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,MAAO,SAAQ,SAAS;gBACzB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CA6DtD"}
@@ -1,7 +1,7 @@
1
1
  import * as url from "node:url";
2
2
  import * as apigateway from "aws-cdk-lib/aws-apigateway";
3
3
  import { Construct } from "constructs";
4
- import { ESMNodeFunctionFactory } from "../../../../../lib/index.js";
4
+ import { ESMNodeFunctionFactory } from "../../../../../lambda/nodejs.function.js";
5
5
  import { API_RESOURCE } from "./constants.js";
6
6
  import ReRun from "./resources/rerun/construct.js";
7
7
  export default class extends Construct {
@@ -14,19 +14,20 @@ export default class extends Construct {
14
14
  "Resources",
15
15
  ].join("-");
16
16
  // Lambda
17
- const lambda = ESMNodeFunctionFactory(props.config)(this, "NodeFunction", {
17
+ const lambdaFn = ESMNodeFunctionFactory(props.config)(this, "NodeFunction", {
18
18
  functionName: ref,
19
19
  entry: url.fileURLToPath(new URL("handler.ts", import.meta.url).toString()),
20
+ layers: props.lambda.layers,
20
21
  currentVersionOptions: {
21
22
  retryAttempts: 1,
22
23
  },
23
24
  });
24
25
  // Logger / Metrics / Tracing
25
- lambda.addEnvironment("POWERTOOLS_SERVICE_NAME", "Resource");
26
+ lambdaFn.addEnvironment("POWERTOOLS_SERVICE_NAME", "Resource");
26
27
  // Audit
27
- props.table.grantReadWriteData(lambda);
28
+ props.table.grantReadWriteData(lambdaFn);
28
29
  // Integration
29
- const integration = new apigateway.LambdaIntegration(lambda);
30
+ const integration = new apigateway.LambdaIntegration(lambdaFn);
30
31
  const RESOURCE = props.restApi.resource
31
32
  .addResource(API_RESOURCE.RESOURCE)
32
33
  .addResource(`{${API_RESOURCE.RESOURCE_WILDCARD}}`);
@@ -40,6 +41,7 @@ export default class extends Construct {
40
41
  config: props.config,
41
42
  table: props.table,
42
43
  eventBus: props.eventBus,
44
+ lambda: props.lambda,
43
45
  restApi: {
44
46
  resource: ITEM_RESOURCE.addResource(`{${API_RESOURCE.RESOURCE_WILDCARD_ITEM_AUDIT}}`),
45
47
  },
@@ -2,11 +2,17 @@ import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
2
  import * as apigateway from "aws-cdk-lib/aws-apigateway";
3
3
  import type * as dynamodb from "aws-cdk-lib/aws-dynamodb";
4
4
  import type * as events from "aws-cdk-lib/aws-events";
5
+ import type * as lambda from "aws-cdk-lib/aws-lambda";
5
6
  import { Construct } from "constructs";
6
7
  type Props = {
7
8
  config: CDKConfig;
8
9
  table: dynamodb.ITable;
9
10
  eventBus: events.IEventBus;
11
+ /** Lambda configuration */
12
+ lambda: {
13
+ /** Lambda layers to attach to the function */
14
+ layers: lambda.ILayerVersion[];
15
+ };
10
16
  restApi: {
11
17
  resource: apigateway.IResource;
12
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../../../../../../../src/rest-api/resources/app/resources/objects/resources/rerun/construct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAC3B,OAAO,EAAE;QACR,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,MAAO,SAAQ,SAAS;gBACzB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAyCtD"}
1
+ {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../../../../../../../src/rest-api/resources/app/resources/objects/resources/rerun/construct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAC3B,2BAA2B;IAC3B,MAAM,EAAE;QACP,8CAA8C;QAC9C,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;KAC/B,CAAC;IACF,OAAO,EAAE;QACR,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,MAAO,SAAQ,SAAS;gBACzB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CA8CtD"}
@@ -1,7 +1,7 @@
1
1
  import * as url from "node:url";
2
2
  import * as apigateway from "aws-cdk-lib/aws-apigateway";
3
3
  import { Construct } from "constructs";
4
- import { ESMNodeFunctionFactory } from "../../../../../../../lib/index.js";
4
+ import { ESMNodeFunctionFactory } from "../../../../../../../lambda/nodejs.function.js";
5
5
  import { API_RESOURCE } from "./constants.js";
6
6
  export default class extends Construct {
7
7
  constructor(scope, id, props) {
@@ -13,21 +13,22 @@ export default class extends Construct {
13
13
  "Resource-Rerun",
14
14
  ].join("-");
15
15
  // Lambda
16
- const lambda = ESMNodeFunctionFactory(props.config)(this, "NodeFunction", {
16
+ const lambdaFn = ESMNodeFunctionFactory(props.config)(this, "NodeFunction", {
17
17
  functionName: ref,
18
18
  entry: url.fileURLToPath(new URL("handler.ts", import.meta.url).toString()),
19
+ layers: props.lambda.layers,
19
20
  currentVersionOptions: {
20
21
  retryAttempts: 1,
21
22
  },
22
23
  });
23
24
  // Logger / Metrics / Tracing
24
- lambda.addEnvironment("POWERTOOLS_SERVICE_NAME", "ResourceRerun");
25
+ lambdaFn.addEnvironment("POWERTOOLS_SERVICE_NAME", "ResourceRerun");
25
26
  // Audit
26
- props.table.grantReadWriteData(lambda);
27
+ props.table.grantReadWriteData(lambdaFn);
27
28
  // Put events
28
- props.eventBus.grantPutEventsTo(lambda);
29
+ props.eventBus.grantPutEventsTo(lambdaFn);
29
30
  // Integration
30
- const integration = new apigateway.LambdaIntegration(lambda);
31
+ const integration = new apigateway.LambdaIntegration(lambdaFn);
31
32
  const RESOURCE = props.restApi.resource.addResource(API_RESOURCE.RESOURCE);
32
33
  // /apps/{app}/objects/{object}/{item}/{audit}/rerun
33
34
  RESOURCE.addMethod("POST", integration, {
@@ -2,11 +2,17 @@ import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
2
  import type * as apigateway from "aws-cdk-lib/aws-apigateway";
3
3
  import type * as dynamodb from "aws-cdk-lib/aws-dynamodb";
4
4
  import type * as events from "aws-cdk-lib/aws-events";
5
+ import type * as lambda from "aws-cdk-lib/aws-lambda";
5
6
  import { Construct } from "constructs";
6
7
  interface Props {
7
8
  config: CDKConfig;
8
9
  table: dynamodb.ITable;
9
10
  eventBus: events.IEventBus;
11
+ /** Lambda configuration */
12
+ lambda: {
13
+ /** Lambda layers to attach to the function */
14
+ layers: lambda.ILayerVersion[];
15
+ };
10
16
  restApi: {
11
17
  resource: apigateway.IResource;
12
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../../src/rest-api/resources/construct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,UAAU,KAAK;IACd,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAC3B,OAAO,EAAE;QACR,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC;KAE/B,CAAC;CACF;AAED,qBAAa,yBAA0B,SAAQ,SAAS;gBAC3C,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAOtD"}
1
+ {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../../src/rest-api/resources/construct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,UAAU,KAAK;IACd,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;IAC3B,2BAA2B;IAC3B,MAAM,EAAE;QACP,8CAA8C;QAC9C,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;KAC/B,CAAC;IACF,OAAO,EAAE;QACR,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC;KAE/B,CAAC;CACF;AAED,qBAAa,yBAA0B,SAAQ,SAAS;gBAC3C,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAOtD"}
@@ -1,10 +1,16 @@
1
1
  import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
2
  import * as apigateway from "aws-cdk-lib/aws-apigateway";
3
3
  import type * as dynamodb from "aws-cdk-lib/aws-dynamodb";
4
+ import type * as lambda from "aws-cdk-lib/aws-lambda";
4
5
  import { Construct } from "constructs";
5
6
  type Props = {
6
7
  config: CDKConfig;
7
8
  table: dynamodb.ITable;
9
+ /** Lambda configuration */
10
+ lambda: {
11
+ /** Lambda layers to attach to the function */
12
+ layers: lambda.ILayerVersion[];
13
+ };
8
14
  restApi: {
9
15
  resource: apigateway.IResource;
10
16
  };
@@ -1 +1 @@
1
- {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../../../src/rest-api/resources/trace/construct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,OAAO,EAAE;QACR,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,MAAO,SAAQ,SAAS;gBACzB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAwCtD"}
1
+ {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../../../src/rest-api/resources/trace/construct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,KAAK,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IACvB,2BAA2B;IAC3B,MAAM,EAAE;QACP,8CAA8C;QAC9C,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;KAC/B,CAAC;IACF,OAAO,EAAE;QACR,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,MAAO,SAAQ,SAAS;gBACzB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CA6CtD"}
@@ -1,7 +1,7 @@
1
1
  import * as url from "node:url";
2
2
  import * as apigateway from "aws-cdk-lib/aws-apigateway";
3
3
  import { Construct } from "constructs";
4
- import { ESMNodeFunctionFactory } from "../../../lib/index.js";
4
+ import { ESMNodeFunctionFactory } from "../../../lambda/nodejs.function.js";
5
5
  import { API_RESOURCE } from "./constants.js";
6
6
  export default class extends Construct {
7
7
  constructor(scope, id, props) {
@@ -13,19 +13,20 @@ export default class extends Construct {
13
13
  "Trace",
14
14
  ].join("-");
15
15
  // Lambda
16
- const lambda = ESMNodeFunctionFactory(props.config)(this, "NodeFunction", {
16
+ const lambdaFn = ESMNodeFunctionFactory(props.config)(this, "NodeFunction", {
17
17
  functionName: ref,
18
18
  entry: url.fileURLToPath(new URL("handler.ts", import.meta.url).toString()),
19
+ layers: props.lambda.layers,
19
20
  currentVersionOptions: {
20
21
  retryAttempts: 1,
21
22
  },
22
23
  });
23
24
  // Logger / Metrics / Tracing
24
- lambda.addEnvironment("POWERTOOLS_SERVICE_NAME", "Trace");
25
+ lambdaFn.addEnvironment("POWERTOOLS_SERVICE_NAME", "Trace");
25
26
  // DynamoDB
26
- props.table.grantReadWriteData(lambda);
27
+ props.table.grantReadWriteData(lambdaFn);
27
28
  // Integration
28
- const integration = new apigateway.LambdaIntegration(lambda);
29
+ const integration = new apigateway.LambdaIntegration(lambdaFn);
29
30
  const RESOURCE = props.restApi.resource
30
31
  .addResource(API_RESOURCE.RESOURCE)
31
32
  .addResource(`{${API_RESOURCE.RESOURCE}}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipboxlabs/aws-audit-cdk",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "AWS Audit CDK - CDK constructs for AWS audit infrastructure",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -9,9 +9,9 @@
9
9
  "types": "./dist/index.d.ts",
10
10
  "import": "./dist/index.js"
11
11
  },
12
- "./lib": {
13
- "types": "./dist/lib/index.d.ts",
14
- "import": "./dist/lib/index.js"
12
+ "./lambda": {
13
+ "types": "./dist/lambda/construct.d.ts",
14
+ "import": "./dist/lambda/construct.js"
15
15
  },
16
16
  "./cloudwatch": {
17
17
  "types": "./dist/cloudwatch/construct.d.ts",
@@ -42,7 +42,7 @@
42
42
  "@middy/core": "^6.4.5",
43
43
  "qs": "^6.14.0",
44
44
  "zod": "^4.0.0",
45
- "@flipboxlabs/aws-audit-sdk": "^1.0.0"
45
+ "@flipboxlabs/aws-audit-sdk": "^1.1.1"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@tsconfig/node22": "^22.0.1",
@@ -1,53 +0,0 @@
1
- /**
2
- * AWS Audit CDK Library
3
- *
4
- * Provides constructs for deploying audit infrastructure. Import and compose
5
- * the constructs in your own stack as needed.
6
- *
7
- * @example
8
- * ```typescript
9
- * import * as cdk from "aws-cdk-lib";
10
- * import type { Construct } from "constructs";
11
- * import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
12
- *
13
- * // Import constructs from the bootstrap directory
14
- * import CloudWatch from "@flipboxlabs/aws-audit-cdk/bootstrap/cloudwatch/construct";
15
- * import DynamoDB from "@flipboxlabs/aws-audit-cdk/bootstrap/dynamodb/construct";
16
- * import EventBridge from "@flipboxlabs/aws-audit-cdk/bootstrap/eventbridge/construct";
17
- * import RestAPI from "@flipboxlabs/aws-audit-cdk/bootstrap/rest-api/construct";
18
- *
19
- * interface Props {
20
- * config: CDKConfig;
21
- * }
22
- *
23
- * export class AuditStack extends cdk.NestedStack {
24
- * constructor(scope: Construct, id: string, props: Props) {
25
- * super(scope, id, { description: "Audit" });
26
- *
27
- * // DynamoDB (storage)
28
- * const { table } = new DynamoDB(this, "DynamoDB", { config: props.config });
29
- *
30
- * // EventBridge (events)
31
- * const { eventBus } = new EventBridge(this, "EventBridge", {
32
- * config: props.config,
33
- * });
34
- *
35
- * // CloudWatch (logging subscription)
36
- * new CloudWatch(this, "CloudWatch", {
37
- * config: props.config,
38
- * table,
39
- * eventBus,
40
- * });
41
- *
42
- * // REST API (optional)
43
- * new RestAPI(this, "RestAPI", {
44
- * config: props.config,
45
- * table,
46
- * eventBus,
47
- * });
48
- * }
49
- * }
50
- * ```
51
- */
52
- export * from "./nodejs.function.js";
53
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,cAAc,sBAAsB,CAAC"}
package/dist/lib/index.js DELETED
@@ -1,52 +0,0 @@
1
- /**
2
- * AWS Audit CDK Library
3
- *
4
- * Provides constructs for deploying audit infrastructure. Import and compose
5
- * the constructs in your own stack as needed.
6
- *
7
- * @example
8
- * ```typescript
9
- * import * as cdk from "aws-cdk-lib";
10
- * import type { Construct } from "constructs";
11
- * import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
12
- *
13
- * // Import constructs from the bootstrap directory
14
- * import CloudWatch from "@flipboxlabs/aws-audit-cdk/bootstrap/cloudwatch/construct";
15
- * import DynamoDB from "@flipboxlabs/aws-audit-cdk/bootstrap/dynamodb/construct";
16
- * import EventBridge from "@flipboxlabs/aws-audit-cdk/bootstrap/eventbridge/construct";
17
- * import RestAPI from "@flipboxlabs/aws-audit-cdk/bootstrap/rest-api/construct";
18
- *
19
- * interface Props {
20
- * config: CDKConfig;
21
- * }
22
- *
23
- * export class AuditStack extends cdk.NestedStack {
24
- * constructor(scope: Construct, id: string, props: Props) {
25
- * super(scope, id, { description: "Audit" });
26
- *
27
- * // DynamoDB (storage)
28
- * const { table } = new DynamoDB(this, "DynamoDB", { config: props.config });
29
- *
30
- * // EventBridge (events)
31
- * const { eventBus } = new EventBridge(this, "EventBridge", {
32
- * config: props.config,
33
- * });
34
- *
35
- * // CloudWatch (logging subscription)
36
- * new CloudWatch(this, "CloudWatch", {
37
- * config: props.config,
38
- * table,
39
- * eventBus,
40
- * });
41
- *
42
- * // REST API (optional)
43
- * new RestAPI(this, "RestAPI", {
44
- * config: props.config,
45
- * table,
46
- * eventBus,
47
- * });
48
- * }
49
- * }
50
- * ```
51
- */
52
- export * from "./nodejs.function.js";
@@ -1,6 +0,0 @@
1
- import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
- import * as cdk from "aws-cdk-lib";
3
- import * as nodejs from "aws-cdk-lib/aws-lambda-nodejs";
4
- import type { Construct } from "constructs";
5
- export declare const ESMNodeFunctionFactory: (config: CDKConfig) => (scope: Construct, id: string, props: nodejs.NodejsFunctionProps) => cdk.aws_lambda_nodejs.NodejsFunction;
6
- //# sourceMappingURL=nodejs.function.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nodejs.function.d.ts","sourceRoot":"","sources":["../../src/lib/nodejs.function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAGnC,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAC;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,eAAO,MAAM,sBAAsB,GACjC,QAAQ,SAAS,MACjB,OAAO,SAAS,EAAE,IAAI,MAAM,EAAE,OAAO,MAAM,CAAC,mBAAmB,yCAyD/D,CAAC"}