@flipboxlabs/aws-audit-cdk 1.1.0

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 (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -0
  3. package/dist/audit-config.d.ts +59 -0
  4. package/dist/audit-config.d.ts.map +1 -0
  5. package/dist/audit-config.js +27 -0
  6. package/dist/cloudwatch/construct.d.ts +20 -0
  7. package/dist/cloudwatch/construct.d.ts.map +1 -0
  8. package/dist/cloudwatch/construct.js +46 -0
  9. package/dist/cloudwatch/subscription.handler.d.ts +6 -0
  10. package/dist/cloudwatch/subscription.handler.d.ts.map +1 -0
  11. package/dist/cloudwatch/subscription.handler.js +34 -0
  12. package/dist/constants.d.ts +9 -0
  13. package/dist/constants.d.ts.map +1 -0
  14. package/dist/constants.js +1 -0
  15. package/dist/dynamodb/audit.d.ts +10 -0
  16. package/dist/dynamodb/audit.d.ts.map +1 -0
  17. package/dist/dynamodb/audit.js +114 -0
  18. package/dist/dynamodb/construct.d.ts +10 -0
  19. package/dist/dynamodb/construct.d.ts.map +1 -0
  20. package/dist/dynamodb/construct.js +10 -0
  21. package/dist/eventbridge/construct.d.ts +10 -0
  22. package/dist/eventbridge/construct.d.ts.map +1 -0
  23. package/dist/eventbridge/construct.js +13 -0
  24. package/dist/index.d.ts +53 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +52 -0
  27. package/dist/lib/index.d.ts +53 -0
  28. package/dist/lib/index.d.ts.map +1 -0
  29. package/dist/lib/index.js +52 -0
  30. package/dist/lib/nodejs.function.d.ts +6 -0
  31. package/dist/lib/nodejs.function.d.ts.map +1 -0
  32. package/dist/lib/nodejs.function.js +48 -0
  33. package/dist/rest-api/construct.d.ts +18 -0
  34. package/dist/rest-api/construct.d.ts.map +1 -0
  35. package/dist/rest-api/construct.js +34 -0
  36. package/dist/rest-api/index.d.ts +3 -0
  37. package/dist/rest-api/index.d.ts.map +1 -0
  38. package/dist/rest-api/index.js +2 -0
  39. package/dist/rest-api/resources/app/constants.d.ts +5 -0
  40. package/dist/rest-api/resources/app/constants.d.ts.map +1 -0
  41. package/dist/rest-api/resources/app/constants.js +4 -0
  42. package/dist/rest-api/resources/app/construct.d.ts +18 -0
  43. package/dist/rest-api/resources/app/construct.d.ts.map +1 -0
  44. package/dist/rest-api/resources/app/construct.js +18 -0
  45. package/dist/rest-api/resources/app/resources/objects/constants.d.ts +7 -0
  46. package/dist/rest-api/resources/app/resources/objects/constants.d.ts.map +1 -0
  47. package/dist/rest-api/resources/app/resources/objects/constants.js +6 -0
  48. package/dist/rest-api/resources/app/resources/objects/construct.d.ts +18 -0
  49. package/dist/rest-api/resources/app/resources/objects/construct.d.ts.map +1 -0
  50. package/dist/rest-api/resources/app/resources/objects/construct.js +48 -0
  51. package/dist/rest-api/resources/app/resources/objects/handler.d.ts +3 -0
  52. package/dist/rest-api/resources/app/resources/objects/handler.d.ts.map +1 -0
  53. package/dist/rest-api/resources/app/resources/objects/handler.js +40 -0
  54. package/dist/rest-api/resources/app/resources/objects/resources/rerun/constants.d.ts +4 -0
  55. package/dist/rest-api/resources/app/resources/objects/resources/rerun/constants.d.ts.map +1 -0
  56. package/dist/rest-api/resources/app/resources/objects/resources/rerun/constants.js +3 -0
  57. package/dist/rest-api/resources/app/resources/objects/resources/rerun/construct.d.ts +18 -0
  58. package/dist/rest-api/resources/app/resources/objects/resources/rerun/construct.d.ts.map +1 -0
  59. package/dist/rest-api/resources/app/resources/objects/resources/rerun/construct.js +38 -0
  60. package/dist/rest-api/resources/app/resources/objects/resources/rerun/handler.d.ts +3 -0
  61. package/dist/rest-api/resources/app/resources/objects/resources/rerun/handler.d.ts.map +1 -0
  62. package/dist/rest-api/resources/app/resources/objects/resources/rerun/handler.js +44 -0
  63. package/dist/rest-api/resources/app/resources/objects/resources/rerun/schema.d.ts +7 -0
  64. package/dist/rest-api/resources/app/resources/objects/resources/rerun/schema.d.ts.map +1 -0
  65. package/dist/rest-api/resources/app/resources/objects/resources/rerun/schema.js +10 -0
  66. package/dist/rest-api/resources/app/resources/objects/schema.d.ts +64 -0
  67. package/dist/rest-api/resources/app/resources/objects/schema.d.ts.map +1 -0
  68. package/dist/rest-api/resources/app/resources/objects/schema.js +16 -0
  69. package/dist/rest-api/resources/construct.d.ts +18 -0
  70. package/dist/rest-api/resources/construct.d.ts.map +1 -0
  71. package/dist/rest-api/resources/construct.js +10 -0
  72. package/dist/rest-api/resources/trace/constants.d.ts +4 -0
  73. package/dist/rest-api/resources/trace/constants.d.ts.map +1 -0
  74. package/dist/rest-api/resources/trace/constants.js +3 -0
  75. package/dist/rest-api/resources/trace/construct.d.ts +16 -0
  76. package/dist/rest-api/resources/trace/construct.d.ts.map +1 -0
  77. package/dist/rest-api/resources/trace/construct.js +38 -0
  78. package/dist/rest-api/resources/trace/handler.d.ts +3 -0
  79. package/dist/rest-api/resources/trace/handler.d.ts.map +1 -0
  80. package/dist/rest-api/resources/trace/handler.js +36 -0
  81. package/dist/rest-api/resources/trace/schema.d.ts +65 -0
  82. package/dist/rest-api/resources/trace/schema.d.ts.map +1 -0
  83. package/dist/rest-api/resources/trace/schema.js +14 -0
  84. package/dist/rest-api/utils.d.ts +7 -0
  85. package/dist/rest-api/utils.d.ts.map +1 -0
  86. package/dist/rest-api/utils.js +7 -0
  87. package/dist/test-config.d.ts +56 -0
  88. package/dist/test-config.d.ts.map +1 -0
  89. package/dist/test-config.js +24 -0
  90. package/package.json +102 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Flipbox Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @flipboxlabs/aws-audit-cdk
2
+
3
+ AWS Audit CDK - CDK constructs for AWS audit infrastructure.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @flipboxlabs/aws-audit-cdk
9
+ # or
10
+ pnpm add @flipboxlabs/aws-audit-cdk
11
+ ```
12
+
13
+ ## Usage
14
+
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';
20
+ ```
21
+
22
+ ## Constructs
23
+
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
28
+
29
+ ## Peer Dependencies
30
+
31
+ - `aws-cdk-lib` >= 2.135.0
32
+ - `constructs` >= 10.3.0
33
+
34
+ ## License
35
+
36
+ MIT
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Shared audit configuration for the CDK.
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`
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { auditConfig } from '../../audit-config.js';
12
+ *
13
+ * // Use in handlers
14
+ * const service = new AuditService(logger, auditConfig);
15
+ *
16
+ * // Use schemas for validation
17
+ * const PathSchema = z.object({
18
+ * app: auditConfig.schemas.app,
19
+ * object: auditConfig.schemas.resourceType,
20
+ * });
21
+ * ```
22
+ */
23
+ export declare const auditConfig: {
24
+ service: string | undefined;
25
+ } & {
26
+ readonly apps: readonly [];
27
+ readonly resourceTypes: readonly [];
28
+ } & {
29
+ schemas: {
30
+ app: import("zod").ZodEnum<{
31
+ [x: string]: string;
32
+ }>;
33
+ resourceType: import("zod").ZodEnum<{
34
+ [x: string]: string;
35
+ }>;
36
+ resourceReference: import("zod").ZodObject<{
37
+ app: import("zod").ZodEnum<{
38
+ [x: string]: string;
39
+ }>;
40
+ type: import("zod").ZodEnum<{
41
+ [x: string]: string;
42
+ }>;
43
+ id: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>>;
44
+ }, import("zod/v4/core").$strip>;
45
+ };
46
+ _types: {
47
+ App: never;
48
+ ResourceType: never;
49
+ };
50
+ };
51
+ /**
52
+ * Type alias for the App union type from the audit config.
53
+ */
54
+ export type App = (typeof auditConfig)["_types"]["App"];
55
+ /**
56
+ * Type alias for the ResourceType union type from the audit config.
57
+ */
58
+ export type ResourceType = (typeof auditConfig)["_types"]["ResourceType"];
59
+ //# sourceMappingURL=audit-config.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,27 @@
1
+ import { defineAuditConfig } from "@flipboxlabs/aws-audit-sdk";
2
+ /**
3
+ * Shared audit configuration for the CDK.
4
+ *
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`
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { auditConfig } from '../../audit-config.js';
13
+ *
14
+ * // Use in handlers
15
+ * const service = new AuditService(logger, auditConfig);
16
+ *
17
+ * // Use schemas for validation
18
+ * const PathSchema = z.object({
19
+ * app: auditConfig.schemas.app,
20
+ * object: auditConfig.schemas.resourceType,
21
+ * });
22
+ * ```
23
+ */
24
+ export const auditConfig = defineAuditConfig({
25
+ apps: [],
26
+ resourceTypes: [],
27
+ });
@@ -0,0 +1,20 @@
1
+ import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
+ import type * as dynamodb from "aws-cdk-lib/aws-dynamodb";
3
+ import type * as events from "aws-cdk-lib/aws-events";
4
+ import { Construct } from "constructs";
5
+ type Props = {
6
+ config: CDKConfig;
7
+ table: dynamodb.ITable;
8
+ eventBus: events.IEventBus;
9
+ subscriptionFilter?: {
10
+ /** Scope of the subscription filter policy. Defaults to "ALL". */
11
+ scope?: string;
12
+ /** Selection criteria for log groups. Defaults to excluding the subscription lambda's log group. */
13
+ selectionCriteria?: string;
14
+ };
15
+ };
16
+ export declare class CloudWatchConstruct extends Construct {
17
+ constructor(scope: Construct, id: string, props: Props);
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=construct.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,46 @@
1
+ import * as url from "node:url";
2
+ import { AUDIT_LOG_IDENTIFIER } from "@flipboxlabs/aws-audit-sdk";
3
+ import { ServicePrincipal } from "aws-cdk-lib/aws-iam";
4
+ import * as logs from "aws-cdk-lib/aws-logs";
5
+ import { Construct } from "constructs";
6
+ import { ESMNodeFunctionFactory } from "../lib/index.js";
7
+ export class CloudWatchConstruct extends Construct {
8
+ constructor(scope, id, props) {
9
+ super(scope, id);
10
+ const ref = `${[props.config.env.toUpperCase(), "Account", "CloudWatch", "Subscription"].join("-")}`;
11
+ // Lambda Function
12
+ const lambda = ESMNodeFunctionFactory(props.config)(this, "subscription", {
13
+ functionName: ref,
14
+ entry: url.fileURLToPath(new URL("subscription.handler.ts", import.meta.url).toString()),
15
+ currentVersionOptions: {
16
+ retryAttempts: 2,
17
+ },
18
+ });
19
+ // Allow writes to DynamoDB
20
+ props.table.grantWriteData(lambda);
21
+ // Allow puts to EventBridge
22
+ props.eventBus.grantPutEventsTo(lambda);
23
+ // Permissions
24
+ lambda.addPermission("LogProcessorPermission", {
25
+ principal: new ServicePrincipal("logs.amazonaws.com"),
26
+ action: "lambda:InvokeFunction",
27
+ sourceArn: `arn:aws:logs:${props.config.aws.region}:${props.config.aws.account}:log-group:*`,
28
+ sourceAccount: props.config.aws.account,
29
+ });
30
+ // Create an Account-Level Subscription Filter Policy
31
+ const accountPolicy = new logs.CfnAccountPolicy(this, "AccountLevelLogSubscriptionPolicy", {
32
+ policyName: `${props.config.env.toUpperCase()}AccountLevelSubscriptionPolicy`,
33
+ policyType: "SUBSCRIPTION_FILTER_POLICY",
34
+ policyDocument: JSON.stringify({
35
+ DestinationArn: lambda.functionArn,
36
+ Distribution: "Random",
37
+ FilterPattern: `{ $.${AUDIT_LOG_IDENTIFIER}.operation = * }`,
38
+ }),
39
+ scope: props.subscriptionFilter?.scope ?? "ALL",
40
+ selectionCriteria: props.subscriptionFilter?.selectionCriteria ??
41
+ `LogGroupName NOT IN ["/aws/lambda/${lambda.functionName}"]`,
42
+ });
43
+ // Add explicit dependency on the Lambda function
44
+ accountPolicy.node.addDependency(lambda);
45
+ }
46
+ }
@@ -0,0 +1,6 @@
1
+ import middy from "@middy/core";
2
+ import type { CloudWatchLogsEvent } from "aws-lambda";
3
+ export declare const handler: middy.MiddyfiedHandler<CloudWatchLogsEvent, void, Error, import("aws-lambda").Context, {
4
+ [key: string]: unknown;
5
+ }>;
6
+ //# sourceMappingURL=subscription.handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription.handler.d.ts","sourceRoot":"","sources":["../../src/cloudwatch/subscription.handler.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAgDtD,eAAO,MAAM,OAAO;;EAEkC,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { CLOUDWATCH_LOGS, extractDataFromEnvelope, } from "@aws-lambda-powertools/jmespath/envelopes";
2
+ import { Logger } from "@aws-lambda-powertools/logger";
3
+ import { injectLambdaContext } from "@aws-lambda-powertools/logger/middleware";
4
+ import { AUDIT_LOG_IDENTIFIER, AuditService } from "@flipboxlabs/aws-audit-sdk";
5
+ import middy from "@middy/core";
6
+ import { auditConfig } from "../audit-config.js";
7
+ const logger = new Logger({
8
+ logRecordOrder: ["level", "message"],
9
+ });
10
+ const service = new AuditService(logger, auditConfig);
11
+ const recordHandler = async (event) => {
12
+ const records = extractDataFromEnvelope(event, CLOUDWATCH_LOGS);
13
+ await Promise.allSettled(records.map(async (record) => {
14
+ const message = JSON.parse(record.message);
15
+ const audit = message[AUDIT_LOG_IDENTIFIER];
16
+ if (!audit) {
17
+ logger.warn("No audit log identifier found in message", { message });
18
+ return;
19
+ }
20
+ try {
21
+ logger.info("Storing audit to DynamoDB", { audit });
22
+ return await service.upsertItem(audit).then((result) => {
23
+ logger.info("Stored audit to DynamoDB", { result });
24
+ return result;
25
+ });
26
+ }
27
+ catch (error) {
28
+ logger.error("An error was caught trying to save audit item", {
29
+ error,
30
+ });
31
+ }
32
+ }));
33
+ };
34
+ export const handler = middy(async (event) => recordHandler(event)).use(injectLambdaContext(logger, { logEvent: true }));
@@ -0,0 +1,9 @@
1
+ export type CDKConfig = {
2
+ env: string;
3
+ aws: {
4
+ account: string;
5
+ region: string;
6
+ };
7
+ service?: string;
8
+ };
9
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KACf,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
+ import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
3
+ import { Construct } from "constructs";
4
+ export default class extends Construct {
5
+ readonly table: dynamodb.Table;
6
+ constructor(scope: Construct, id: string, props: {
7
+ config: CDKConfig;
8
+ });
9
+ }
10
+ //# sourceMappingURL=audit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/dynamodb/audit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAG5D,OAAO,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,CAAC,OAAO,MAAO,SAAQ,SAAS;IACrC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC;gBAG9B,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE;QACN,MAAM,EAAE,SAAS,CAAC;KAClB;CAkHF"}
@@ -0,0 +1,114 @@
1
+ import { DynamoDB } from "@flipboxlabs/aws-audit-sdk";
2
+ import * as cdk from "aws-cdk-lib";
3
+ import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
4
+ import { Construct } from "constructs";
5
+ export default class extends Construct {
6
+ table;
7
+ constructor(scope, id, props) {
8
+ super(scope, id);
9
+ /**
10
+ * DynamoDB Table
11
+ */
12
+ this.table = new dynamodb.Table(this, "AuditTable", {
13
+ tableName: DynamoDB.Table.Name(props.config),
14
+ removalPolicy: cdk.RemovalPolicy.RETAIN,
15
+ billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
16
+ partitionKey: {
17
+ name: DynamoDB.Keys.PARTITION_KEY,
18
+ type: dynamodb.AttributeType.STRING,
19
+ },
20
+ sortKey: {
21
+ name: DynamoDB.Keys.SORT_KEY,
22
+ type: dynamodb.AttributeType.STRING,
23
+ },
24
+ stream: dynamodb.StreamViewType.NEW_AND_OLD_IMAGES,
25
+ timeToLiveAttribute: DynamoDB.Attributes.TTL,
26
+ });
27
+ /**
28
+ * LSIs (we can't add LSIs later)
29
+ */
30
+ this.table.addLocalSecondaryIndex({
31
+ indexName: DynamoDB.Indexes.LSI1_N,
32
+ sortKey: {
33
+ name: DynamoDB.Keys.LSI1_N_SORT_KEY,
34
+ type: dynamodb.AttributeType.NUMBER,
35
+ },
36
+ });
37
+ this.table.addLocalSecondaryIndex({
38
+ indexName: DynamoDB.Indexes.LSI1_S,
39
+ sortKey: {
40
+ name: DynamoDB.Keys.LSI1_S_SORT_KEY,
41
+ type: dynamodb.AttributeType.STRING,
42
+ },
43
+ });
44
+ // List by Resource
45
+ this.table.addGlobalSecondaryIndex({
46
+ indexName: DynamoDB.Indexes.GSI1_SN,
47
+ partitionKey: {
48
+ name: DynamoDB.Keys.GSI1_SN_PARTITION_KEY,
49
+ type: dynamodb.AttributeType.STRING,
50
+ },
51
+ sortKey: {
52
+ name: DynamoDB.Keys.GSI1_SN_SORT_KEY,
53
+ type: dynamodb.AttributeType.NUMBER,
54
+ },
55
+ projectionType: dynamodb.ProjectionType.INCLUDE,
56
+ nonKeyAttributes: [
57
+ "operation",
58
+ "status",
59
+ "message",
60
+ "source",
61
+ "target",
62
+ "rerunable",
63
+ "createdAt",
64
+ ],
65
+ });
66
+ // List by Trace Id
67
+ this.table.addGlobalSecondaryIndex({
68
+ indexName: DynamoDB.Indexes.GSI1_SS,
69
+ partitionKey: {
70
+ name: DynamoDB.Keys.GSI1_SS_PARTITION_KEY,
71
+ type: dynamodb.AttributeType.STRING,
72
+ },
73
+ sortKey: {
74
+ name: DynamoDB.Keys.GSI1_SS_SORT_KEY,
75
+ type: dynamodb.AttributeType.STRING,
76
+ },
77
+ projectionType: dynamodb.ProjectionType.INCLUDE,
78
+ nonKeyAttributes: [
79
+ "operation",
80
+ "status",
81
+ "message",
82
+ "source",
83
+ "target",
84
+ "rerunable",
85
+ "createdAt",
86
+ DynamoDB.Keys.GSI1_SN_PARTITION_KEY,
87
+ DynamoDB.Keys.GSI1_SN_SORT_KEY,
88
+ ],
89
+ });
90
+ // this.table.addGlobalSecondaryIndex({
91
+ // indexName: Indexes.GSI2_SS,
92
+ // partitionKey: {
93
+ // name: Keys.GSI2_SS_PARTITION_KEY,
94
+ // type: dynamodb.AttributeType.STRING,
95
+ // },
96
+ // sortKey: {
97
+ // name: Keys.GSI2_SS_SORT_KEY,
98
+ // type: dynamodb.AttributeType.STRING,
99
+ // },
100
+ // projectionType: dynamodb.ProjectionType.INCLUDE,
101
+ // nonKeyAttributes: [
102
+ // "operation",
103
+ // "status",
104
+ // "message",
105
+ // "result",
106
+ // "error",
107
+ // "source",
108
+ // "target",
109
+ // "rerunable",
110
+ // "_createdAt",
111
+ // ],
112
+ // });
113
+ }
114
+ }
@@ -0,0 +1,10 @@
1
+ import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
+ import type * as dynamodb from "aws-cdk-lib/aws-dynamodb";
3
+ import { Construct } from "constructs";
4
+ export declare class DynamoDBConstruct extends Construct {
5
+ readonly table: dynamodb.ITable;
6
+ constructor(scope: Construct, id: string, props: {
7
+ config: CDKConfig;
8
+ });
9
+ }
10
+ //# sourceMappingURL=construct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../src/dynamodb/construct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,qBAAa,iBAAkB,SAAQ,SAAS;IAC/C,SAAgB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;gBAGtC,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE;QACN,MAAM,EAAE,SAAS,CAAC;KAClB;CAQF"}
@@ -0,0 +1,10 @@
1
+ import { Construct } from "constructs";
2
+ import AuditTable from "./audit.js";
3
+ export class DynamoDBConstruct extends Construct {
4
+ table;
5
+ constructor(scope, id, props) {
6
+ super(scope, id);
7
+ const { table } = new AuditTable(this, "AuditTable", props);
8
+ this.table = table;
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { CDKConfig } from "@flipboxlabs/aws-audit-cdk";
2
+ import * as events from "aws-cdk-lib/aws-events";
3
+ import { Construct } from "constructs";
4
+ export declare class EventBridgeConstruct extends Construct {
5
+ readonly eventBus: events.IEventBus;
6
+ constructor(scope: Construct, id: string, props: {
7
+ config: CDKConfig;
8
+ });
9
+ }
10
+ //# sourceMappingURL=construct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../../src/eventbridge/construct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,qBAAa,oBAAqB,SAAQ,SAAS;IAClD,SAAgB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC;gBAG1C,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE;QACN,MAAM,EAAE,SAAS,CAAC;KAClB;CASF"}
@@ -0,0 +1,13 @@
1
+ import { EventBridge } from "@flipboxlabs/aws-audit-sdk";
2
+ import * as events from "aws-cdk-lib/aws-events";
3
+ import { Construct } from "constructs";
4
+ export class EventBridgeConstruct extends Construct {
5
+ eventBus;
6
+ constructor(scope, id, props) {
7
+ super(scope, id);
8
+ // Our audit event bus
9
+ this.eventBus = new events.EventBus(this, "EventBus", {
10
+ eventBusName: EventBridge.Bus.Name(props.config),
11
+ });
12
+ }
13
+ }
@@ -0,0 +1,53 @@
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 { 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
+ * ```
51
+ */
52
+ export * from "./constants.js";
53
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,cAAc,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
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 { 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
+ * ```
51
+ */
52
+ export * from "./constants.js";
@@ -0,0 +1,53 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,cAAc,sBAAsB,CAAC"}