@composurecdk/logs 0.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.
- package/README.md +52 -0
- package/dist/defaults.d.ts +8 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +23 -0
- package/dist/defaults.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/log-group-builder.d.ts +62 -0
- package/dist/log-group-builder.d.ts.map +1 -0
- package/dist/log-group-builder.js +43 -0
- package/dist/log-group-builder.js.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @composurecdk/logs
|
|
2
|
+
|
|
3
|
+
CloudWatch Logs builders for [ComposureCDK](../../README.md).
|
|
4
|
+
|
|
5
|
+
This package provides a fluent builder for CloudWatch log groups with secure, AWS-recommended defaults. It wraps the CDK [LogGroup](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.LogGroup.html) construct — refer to the CDK documentation for the full set of configurable properties.
|
|
6
|
+
|
|
7
|
+
## Log Group Builder
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createLogGroupBuilder } from "@composurecdk/logs";
|
|
11
|
+
|
|
12
|
+
const logGroup = createLogGroupBuilder().logGroupName("/my-app/api").build(stack, "ApiLogs");
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Every [LogGroupProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.LogGroupProps.html) property is available as a fluent setter on the builder.
|
|
16
|
+
|
|
17
|
+
## Secure Defaults
|
|
18
|
+
|
|
19
|
+
`createLogGroupBuilder` applies the following defaults. Each can be overridden via the builder's fluent API.
|
|
20
|
+
|
|
21
|
+
| Property | Default | Rationale |
|
|
22
|
+
| --------------- | ----------- | ------------------------------------------------------------------------------- |
|
|
23
|
+
| `retention` | `TWO_YEARS` | Prevents unbounded log accumulation while preserving a meaningful audit window. |
|
|
24
|
+
| `removalPolicy` | `RETAIN` | Logs are audit records that should survive infrastructure teardown. |
|
|
25
|
+
|
|
26
|
+
These defaults are guided by the [AWS Well-Architected Security Pillar — SEC04-BP01](https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/sec_detect_investigate_events_app_service_logging.html).
|
|
27
|
+
|
|
28
|
+
The defaults are exported as `LOG_GROUP_DEFAULTS` for visibility and testing:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { LOG_GROUP_DEFAULTS } from "@composurecdk/logs";
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Overriding defaults
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { RemovalPolicy } from "aws-cdk-lib";
|
|
38
|
+
import { RetentionDays } from "aws-cdk-lib/aws-logs";
|
|
39
|
+
|
|
40
|
+
const logGroup = createLogGroupBuilder()
|
|
41
|
+
.retention(RetentionDays.SIX_MONTHS)
|
|
42
|
+
.removalPolicy(RemovalPolicy.DESTROY)
|
|
43
|
+
.build(stack, "EphemeralLogs");
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Encryption
|
|
47
|
+
|
|
48
|
+
CloudWatch Logs encrypts all log data at rest using AWS-managed keys. For additional control (key rotation, CloudTrail audit, access revocation), provide a customer-managed KMS key:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
const logGroup = createLogGroupBuilder().encryptionKey(myKmsKey).build(stack, "EncryptedLogs");
|
|
52
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type LogGroupProps } from "aws-cdk-lib/aws-logs";
|
|
2
|
+
/**
|
|
3
|
+
* Secure, AWS-recommended defaults applied to every log group built with
|
|
4
|
+
* {@link createLogGroupBuilder}. Each property can be individually overridden
|
|
5
|
+
* via the builder's fluent API.
|
|
6
|
+
*/
|
|
7
|
+
export declare const LOG_GROUP_DEFAULTS: Partial<LogGroupProps>;
|
|
8
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEzE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,OAAO,CAAC,aAAa,CAerD,CAAC"}
|
package/dist/defaults.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RemovalPolicy } from "aws-cdk-lib";
|
|
2
|
+
import { RetentionDays } from "aws-cdk-lib/aws-logs";
|
|
3
|
+
/**
|
|
4
|
+
* Secure, AWS-recommended defaults applied to every log group built with
|
|
5
|
+
* {@link createLogGroupBuilder}. Each property can be individually overridden
|
|
6
|
+
* via the builder's fluent API.
|
|
7
|
+
*/
|
|
8
|
+
export const LOG_GROUP_DEFAULTS = {
|
|
9
|
+
/**
|
|
10
|
+
* Retain logs for two years. CloudWatch defaults to indefinite retention;
|
|
11
|
+
* an explicit policy prevents unbounded log accumulation while preserving
|
|
12
|
+
* a meaningful audit window.
|
|
13
|
+
* @see https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/sec_detect_investigate_events_app_service_logging.html
|
|
14
|
+
*/
|
|
15
|
+
retention: RetentionDays.TWO_YEARS,
|
|
16
|
+
/**
|
|
17
|
+
* Retain the log group when the stack is deleted. Logs are operational
|
|
18
|
+
* and audit records that should survive infrastructure teardown.
|
|
19
|
+
* @see https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/sec_detect_investigate_events_app_service_logging.html
|
|
20
|
+
*/
|
|
21
|
+
removalPolicy: RemovalPolicy.RETAIN,
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAsB,MAAM,sBAAsB,CAAC;AAEzE;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA2B;IACxD;;;;;OAKG;IACH,SAAS,EAAE,aAAa,CAAC,SAAS;IAElC;;;;OAIG;IACH,aAAa,EAAE,aAAa,CAAC,MAAM;CACpC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,GAGtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LogGroup, type LogGroupProps } from "aws-cdk-lib/aws-logs";
|
|
2
|
+
import { type IConstruct } from "constructs";
|
|
3
|
+
import { type IBuilder, type Lifecycle } from "@composurecdk/core";
|
|
4
|
+
type LogGroupBuilderProps = LogGroupProps;
|
|
5
|
+
/**
|
|
6
|
+
* The build output of a {@link ILogGroupBuilder}. Contains the CDK constructs
|
|
7
|
+
* created during {@link Lifecycle.build}, keyed by role.
|
|
8
|
+
*/
|
|
9
|
+
export interface LogGroupBuilderResult {
|
|
10
|
+
/** The CloudWatch log group construct created by the builder. */
|
|
11
|
+
logGroup: LogGroup;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A fluent builder for configuring and creating a CloudWatch log group.
|
|
15
|
+
*
|
|
16
|
+
* Each configuration property from the CDK {@link LogGroupProps} is exposed
|
|
17
|
+
* as an overloaded method: call with a value to set it (returns the builder
|
|
18
|
+
* for chaining), or call with no arguments to read the current value.
|
|
19
|
+
*
|
|
20
|
+
* The builder implements {@link Lifecycle}, so it can be used directly as a
|
|
21
|
+
* component in a {@link compose | composed system}. When built, it creates
|
|
22
|
+
* a log group with the configured properties and returns a
|
|
23
|
+
* {@link LogGroupBuilderResult}.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const logs = createLogGroupBuilder()
|
|
28
|
+
* .retention(RetentionDays.SIX_MONTHS);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export type ILogGroupBuilder = IBuilder<LogGroupBuilderProps, LogGroupBuilder>;
|
|
32
|
+
declare class LogGroupBuilder implements Lifecycle<LogGroupBuilderResult> {
|
|
33
|
+
props: Partial<LogGroupBuilderProps>;
|
|
34
|
+
build(scope: IConstruct, id: string): LogGroupBuilderResult;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new {@link ILogGroupBuilder} for configuring a CloudWatch log group.
|
|
38
|
+
*
|
|
39
|
+
* This is the entry point for defining a log group component. The returned
|
|
40
|
+
* builder exposes every {@link LogGroupProps} property as a fluent setter/getter
|
|
41
|
+
* and implements {@link Lifecycle} for use with {@link compose}.
|
|
42
|
+
*
|
|
43
|
+
* @returns A fluent builder for a CloudWatch log group.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const logs = createLogGroupBuilder()
|
|
48
|
+
* .retention(RetentionDays.SIX_MONTHS);
|
|
49
|
+
*
|
|
50
|
+
* // Use standalone:
|
|
51
|
+
* const result = logs.build(stack, "MyLogGroup");
|
|
52
|
+
*
|
|
53
|
+
* // Or compose into a system:
|
|
54
|
+
* const system = compose(
|
|
55
|
+
* { logs, api: createRestApiBuilder() },
|
|
56
|
+
* { logs: [], api: ["logs"] },
|
|
57
|
+
* );
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function createLogGroupBuilder(): ILogGroupBuilder;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=log-group-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-group-builder.d.ts","sourceRoot":"","sources":["../src/log-group-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAW,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG5E,KAAK,oBAAoB,GAAG,aAAa,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,iEAAiE;IACjE,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;AAE/E,cAAM,eAAgB,YAAW,SAAS,CAAC,qBAAqB,CAAC;IAC/D,KAAK,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAM;IAE1C,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,qBAAqB;CAS5D;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,qBAAqB,IAAI,gBAAgB,CAExD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { LogGroup } from "aws-cdk-lib/aws-logs";
|
|
2
|
+
import { Builder } from "@composurecdk/core";
|
|
3
|
+
import { LOG_GROUP_DEFAULTS } from "./defaults.js";
|
|
4
|
+
class LogGroupBuilder {
|
|
5
|
+
props = {};
|
|
6
|
+
build(scope, id) {
|
|
7
|
+
const mergedProps = {
|
|
8
|
+
...LOG_GROUP_DEFAULTS,
|
|
9
|
+
...this.props,
|
|
10
|
+
};
|
|
11
|
+
return {
|
|
12
|
+
logGroup: new LogGroup(scope, id, mergedProps),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new {@link ILogGroupBuilder} for configuring a CloudWatch log group.
|
|
18
|
+
*
|
|
19
|
+
* This is the entry point for defining a log group component. The returned
|
|
20
|
+
* builder exposes every {@link LogGroupProps} property as a fluent setter/getter
|
|
21
|
+
* and implements {@link Lifecycle} for use with {@link compose}.
|
|
22
|
+
*
|
|
23
|
+
* @returns A fluent builder for a CloudWatch log group.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const logs = createLogGroupBuilder()
|
|
28
|
+
* .retention(RetentionDays.SIX_MONTHS);
|
|
29
|
+
*
|
|
30
|
+
* // Use standalone:
|
|
31
|
+
* const result = logs.build(stack, "MyLogGroup");
|
|
32
|
+
*
|
|
33
|
+
* // Or compose into a system:
|
|
34
|
+
* const system = compose(
|
|
35
|
+
* { logs, api: createRestApiBuilder() },
|
|
36
|
+
* { logs: [], api: ["logs"] },
|
|
37
|
+
* );
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function createLogGroupBuilder() {
|
|
41
|
+
return Builder(LogGroupBuilder);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=log-group-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-group-builder.js","sourceRoot":"","sources":["../src/log-group-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,sBAAsB,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAiC,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAiCnD,MAAM,eAAe;IACnB,KAAK,GAAkC,EAAE,CAAC;IAE1C,KAAK,CAAC,KAAiB,EAAE,EAAU;QACjC,MAAM,WAAW,GAAG;YAClB,GAAG,kBAAkB;YACrB,GAAG,IAAI,CAAC,KAAK;SACU,CAAC;QAC1B,OAAO;YACL,QAAQ,EAAE,IAAI,QAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC;SAC/C,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,OAAO,CAAwC,eAAe,CAAC,CAAC;AACzE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@composurecdk/logs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Composable CloudWatch log group builder with secure defaults",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rm -rf dist",
|
|
20
|
+
"build": "tsc -p tsconfig.build.json",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"test": "vitest run --passWithNoTests",
|
|
23
|
+
"test:watch": "vitest"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [],
|
|
26
|
+
"author": "Jason Duffett (https://github.com/laazyj)",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"type": "module",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@composurecdk/core": "^0.1.0",
|
|
34
|
+
"aws-cdk-lib": "^2.0.0",
|
|
35
|
+
"constructs": "^10.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^25.5.0",
|
|
39
|
+
"aws-cdk-lib": "^2.245.0",
|
|
40
|
+
"constructs": "^10.6.0",
|
|
41
|
+
"typescript": "^6.0.2",
|
|
42
|
+
"vitest": "^4.1.2"
|
|
43
|
+
}
|
|
44
|
+
}
|