@@ -8,6 +8,11 @@ import {
8
8
import { LogGroup , RetentionDays } from 'aws-cdk-lib/aws-logs' ;
9
9
import type { Construct } from 'constructs' ;
10
10
11
+ /**
12
+ * The access mode for the table.
13
+ *
14
+ * Values are: read-only (RO) or read-write (RW)
15
+ */
11
16
type AccessMode = 'RO' | 'RW' ;
12
17
13
18
type BindTableProps = {
@@ -32,6 +37,22 @@ type BindTableProps = {
32
37
envVarName ?: string ;
33
38
} ;
34
39
40
+ /**
41
+ * Custom construct that extends the `NodejsFunction` construct to include a log group
42
+ * as well as some default properties for the function and a helper method to bind the function to a DynamoDB table.
43
+ *
44
+ * The function is created with the following properties:
45
+ * - `handler` set to `handler`
46
+ * - `runtime` set to `Runtime.NODEJS_20_X`
47
+ * - `tracing` set to `Tracing.ACTIVE`
48
+ * - `architecture` set to `Architecture.ARM_64`
49
+ * - `timeout` set to `Duration.seconds(30)`
50
+ * - `environment` set to `{ NODE_OPTIONS: '--enable-source-maps' }`
51
+ * - `logGroup` set to a new `LogGroup` with the log group name set to `/aws/lambda/${functionName}`
52
+ *
53
+ * By setting a custom log group, you can control the log retention policy and other log group settings
54
+ * without having to deploy custom resources.
55
+ */
35
56
export class FunctionWithLogGroup extends NodejsFunction {
36
57
public constructor ( scope : Construct , id : string , props : NodejsFunctionProps ) {
37
58
const { functionName } = props ;
0 commit comments