@ashishpandeyone/cdk-lambda-web-function 0.1.10 → 0.1.12

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/API.md CHANGED
@@ -63,6 +63,8 @@ new NodejsWebFunction(scope: Construct, id: string, props: NodejsWebFunctionProp
63
63
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.addEnvironment">addEnvironment</a></code> | Adds an environment variable. |
64
64
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.addPermission">addPermission</a></code> | Allows a principal in another account, an AWS service or an organization to call the function's endpoints, through the function's resource policy. |
65
65
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.addToRolePolicy">addToRolePolicy</a></code> | Adds a statement to the execution role's policy. |
66
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.encryptionKeyPolicyStatement">encryptionKeyPolicyStatement</a></code> | The key-policy statement Lambda needs to start this function's environments with `encryptionKey`: `kms:Decrypt` for `lambda.amazonaws.com`, limited to this function's revisions (`aws:SourceArn` and the encryption context Lambda sets). |
67
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.logEncryptionKeyPolicyStatement">logEncryptionKeyPolicyStatement</a></code> | The key-policy statement CloudWatch Logs needs in `region` to encrypt this function's log groups there with `logEncryptionKey`, limited to those groups (`kms:EncryptionContext:aws:logs:arn`). |
66
68
 
67
69
  ---
68
70
 
@@ -351,6 +353,36 @@ Adds a statement to the execution role's policy.
351
353
 
352
354
  ---
353
355
 
356
+ ##### `encryptionKeyPolicyStatement` <a name="encryptionKeyPolicyStatement" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.encryptionKeyPolicyStatement"></a>
357
+
358
+ ```typescript
359
+ public encryptionKeyPolicyStatement(): PolicyStatement
360
+ ```
361
+
362
+ The key-policy statement Lambda needs to start this function's environments with `encryptionKey`: `kms:Decrypt` for `lambda.amazonaws.com`, limited to this function's revisions (`aws:SourceArn` and the encryption context Lambda sets).
363
+
364
+ It's added to `encryptionKey` when the key is defined in this app. Add it to every replica of a multi-Region key
365
+ yourself: replicas don't share their primary's policy.
366
+
367
+ ##### `logEncryptionKeyPolicyStatement` <a name="logEncryptionKeyPolicyStatement" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.logEncryptionKeyPolicyStatement"></a>
368
+
369
+ ```typescript
370
+ public logEncryptionKeyPolicyStatement(region: string): PolicyStatement
371
+ ```
372
+
373
+ The key-policy statement CloudWatch Logs needs in `region` to encrypt this function's log groups there with `logEncryptionKey`, limited to those groups (`kms:EncryptionContext:aws:logs:arn`).
374
+
375
+ It's added to `logEncryptionKey` for the key's own region when the key is defined in this app. Add it to the
376
+ replica in every other region the function serves from yourself: replicas don't share their primary's policy.
377
+
378
+ ###### `region`<sup>Required</sup> <a name="region" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.logEncryptionKeyPolicyStatement.parameter.region"></a>
379
+
380
+ - *Type:* string
381
+
382
+ the region of the key or replica.
383
+
384
+ ---
385
+
354
386
  #### Static Functions <a name="Static Functions" id="Static Functions"></a>
355
387
 
356
388
  | **Name** | **Description** |
@@ -529,6 +561,8 @@ Imports an existing Web Function in this stack's account and region by its name.
529
561
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.property.logGroup">logGroup</a></code> | <code>aws-cdk-lib.aws_logs.ILogGroup</code> | The home-region log group that receives the logs of every region the function serves from. |
530
562
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.property.revisionId">revisionId</a></code> | <code>string</code> | The ID of the current revision. |
531
563
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.property.role">role</a></code> | <code>aws-cdk-lib.aws_iam.IRole</code> | The execution role. |
564
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.property.encryptionKey">encryptionKey</a></code> | <code>aws-cdk-lib.aws_kms.IKey</code> | The customer managed key of the function's revisions, if any. |
565
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.property.logEncryptionKey">logEncryptionKey</a></code> | <code>aws-cdk-lib.aws_kms.IKey</code> | The customer managed key of the function's log groups, if any. |
532
566
 
533
567
  ---
534
568
 
@@ -702,6 +736,30 @@ The execution role.
702
736
 
703
737
  ---
704
738
 
739
+ ##### `encryptionKey`<sup>Optional</sup> <a name="encryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.property.encryptionKey"></a>
740
+
741
+ ```typescript
742
+ public readonly encryptionKey: IKey;
743
+ ```
744
+
745
+ - *Type:* aws-cdk-lib.aws_kms.IKey
746
+
747
+ The customer managed key of the function's revisions, if any.
748
+
749
+ ---
750
+
751
+ ##### `logEncryptionKey`<sup>Optional</sup> <a name="logEncryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.property.logEncryptionKey"></a>
752
+
753
+ ```typescript
754
+ public readonly logEncryptionKey: IKey;
755
+ ```
756
+
757
+ - *Type:* aws-cdk-lib.aws_kms.IKey
758
+
759
+ The customer managed key of the function's log groups, if any.
760
+
761
+ ---
762
+
705
763
  #### Constants <a name="Constants" id="Constants"></a>
706
764
 
707
765
  | **Name** | **Type** | **Description** |
@@ -788,6 +846,8 @@ new WebFunction(scope: Construct, id: string, props: WebFunctionProps)
788
846
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.addEnvironment">addEnvironment</a></code> | Adds an environment variable. |
789
847
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.addPermission">addPermission</a></code> | Allows a principal in another account, an AWS service or an organization to call the function's endpoints, through the function's resource policy. |
790
848
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.addToRolePolicy">addToRolePolicy</a></code> | Adds a statement to the execution role's policy. |
849
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.encryptionKeyPolicyStatement">encryptionKeyPolicyStatement</a></code> | The key-policy statement Lambda needs to start this function's environments with `encryptionKey`: `kms:Decrypt` for `lambda.amazonaws.com`, limited to this function's revisions (`aws:SourceArn` and the encryption context Lambda sets). |
850
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.logEncryptionKeyPolicyStatement">logEncryptionKeyPolicyStatement</a></code> | The key-policy statement CloudWatch Logs needs in `region` to encrypt this function's log groups there with `logEncryptionKey`, limited to those groups (`kms:EncryptionContext:aws:logs:arn`). |
791
851
 
792
852
  ---
793
853
 
@@ -1076,6 +1136,36 @@ Adds a statement to the execution role's policy.
1076
1136
 
1077
1137
  ---
1078
1138
 
1139
+ ##### `encryptionKeyPolicyStatement` <a name="encryptionKeyPolicyStatement" id="@ashishpandeyone/cdk-lambda-web-function.WebFunction.encryptionKeyPolicyStatement"></a>
1140
+
1141
+ ```typescript
1142
+ public encryptionKeyPolicyStatement(): PolicyStatement
1143
+ ```
1144
+
1145
+ The key-policy statement Lambda needs to start this function's environments with `encryptionKey`: `kms:Decrypt` for `lambda.amazonaws.com`, limited to this function's revisions (`aws:SourceArn` and the encryption context Lambda sets).
1146
+
1147
+ It's added to `encryptionKey` when the key is defined in this app. Add it to every replica of a multi-Region key
1148
+ yourself: replicas don't share their primary's policy.
1149
+
1150
+ ##### `logEncryptionKeyPolicyStatement` <a name="logEncryptionKeyPolicyStatement" id="@ashishpandeyone/cdk-lambda-web-function.WebFunction.logEncryptionKeyPolicyStatement"></a>
1151
+
1152
+ ```typescript
1153
+ public logEncryptionKeyPolicyStatement(region: string): PolicyStatement
1154
+ ```
1155
+
1156
+ The key-policy statement CloudWatch Logs needs in `region` to encrypt this function's log groups there with `logEncryptionKey`, limited to those groups (`kms:EncryptionContext:aws:logs:arn`).
1157
+
1158
+ It's added to `logEncryptionKey` for the key's own region when the key is defined in this app. Add it to the
1159
+ replica in every other region the function serves from yourself: replicas don't share their primary's policy.
1160
+
1161
+ ###### `region`<sup>Required</sup> <a name="region" id="@ashishpandeyone/cdk-lambda-web-function.WebFunction.logEncryptionKeyPolicyStatement.parameter.region"></a>
1162
+
1163
+ - *Type:* string
1164
+
1165
+ the region of the key or replica.
1166
+
1167
+ ---
1168
+
1079
1169
  #### Static Functions <a name="Static Functions" id="Static Functions"></a>
1080
1170
 
1081
1171
  | **Name** | **Description** |
@@ -1254,6 +1344,8 @@ Imports an existing Web Function in this stack's account and region by its name.
1254
1344
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.property.logGroup">logGroup</a></code> | <code>aws-cdk-lib.aws_logs.ILogGroup</code> | The home-region log group that receives the logs of every region the function serves from. |
1255
1345
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.property.revisionId">revisionId</a></code> | <code>string</code> | The ID of the current revision. |
1256
1346
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.property.role">role</a></code> | <code>aws-cdk-lib.aws_iam.IRole</code> | The execution role. |
1347
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.property.encryptionKey">encryptionKey</a></code> | <code>aws-cdk-lib.aws_kms.IKey</code> | The customer managed key of the function's revisions, if any. |
1348
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.property.logEncryptionKey">logEncryptionKey</a></code> | <code>aws-cdk-lib.aws_kms.IKey</code> | The customer managed key of the function's log groups, if any. |
1257
1349
 
1258
1350
  ---
1259
1351
 
@@ -1427,6 +1519,30 @@ The execution role.
1427
1519
 
1428
1520
  ---
1429
1521
 
1522
+ ##### `encryptionKey`<sup>Optional</sup> <a name="encryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.WebFunction.property.encryptionKey"></a>
1523
+
1524
+ ```typescript
1525
+ public readonly encryptionKey: IKey;
1526
+ ```
1527
+
1528
+ - *Type:* aws-cdk-lib.aws_kms.IKey
1529
+
1530
+ The customer managed key of the function's revisions, if any.
1531
+
1532
+ ---
1533
+
1534
+ ##### `logEncryptionKey`<sup>Optional</sup> <a name="logEncryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.WebFunction.property.logEncryptionKey"></a>
1535
+
1536
+ ```typescript
1537
+ public readonly logEncryptionKey: IKey;
1538
+ ```
1539
+
1540
+ - *Type:* aws-cdk-lib.aws_kms.IKey
1541
+
1542
+ The customer managed key of the function's log groups, if any.
1543
+
1544
+ ---
1545
+
1430
1546
  #### Constants <a name="Constants" id="Constants"></a>
1431
1547
 
1432
1548
  | **Name** | **Type** | **Description** |
@@ -2965,8 +3081,10 @@ const nodejsWebFunctionProps: NodejsWebFunctionProps = { ... }
2965
3081
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.authType">authType</a></code> | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionAuthType">WebFunctionAuthType</a></code> | How callers of the endpoint are authenticated. |
2966
3082
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.applicationLogLevelV2">applicationLogLevelV2</a></code> | <code>aws-cdk-lib.aws_lambda.ApplicationLogLevel</code> | The minimum level of application logs to keep. |
2967
3083
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.description">description</a></code> | <code>string</code> | A description of the function's code and configuration. |
3084
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.encryptionKey">encryptionKey</a></code> | <code>aws-cdk-lib.aws_kms.IKey</code> | A customer managed KMS key for the function's revisions: their code and environment variables. |
2968
3085
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.endpoint">endpoint</a></code> | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionEndpointOptions">WebFunctionEndpointOptions</a></code> | The default endpoint (`fn.endpoint`): where it serves from, its name and limits. It serves the current revision; route it elsewhere with `fn.endpoint.routeTraffic()`. Add more endpoints with `addEndpoint`. |
2969
3086
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.environment">environment</a></code> | <code>{[ key: string ]: string}</code> | Environment variables. |
3087
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.logEncryptionKey">logEncryptionKey</a></code> | <code>aws-cdk-lib.aws_kms.IKey</code> | A customer managed KMS key for the function's log groups, in every region it serves from. |
2970
3088
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.logRemovalPolicy">logRemovalPolicy</a></code> | <code>aws-cdk-lib.RemovalPolicy</code> | What happens to the log groups when the function is removed: RETAIN or DESTROY. |
2971
3089
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.logRetention">logRetention</a></code> | <code>aws-cdk-lib.aws_logs.RetentionDays</code> | Retention for every log group of the function, in every region it serves from. |
2972
3090
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.maxConcurrencyPerEnvironment">maxConcurrencyPerEnvironment</a></code> | <code>number</code> | How many requests one execution environment handles at the same time (1-128). |
@@ -3021,6 +3139,27 @@ A description of the function's code and configuration.
3021
3139
 
3022
3140
  ---
3023
3141
 
3142
+ ##### `encryptionKey`<sup>Optional</sup> <a name="encryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.encryptionKey"></a>
3143
+
3144
+ ```typescript
3145
+ public readonly encryptionKey: IKey;
3146
+ ```
3147
+
3148
+ - *Type:* aws-cdk-lib.aws_kms.IKey
3149
+ - *Default:* an AWS owned key
3150
+
3151
+ A customer managed KMS key for the function's revisions: their code and environment variables.
3152
+
3153
+ A `PER_REGION` or `MULTI_REGION` endpoint needs a **multi-Region key** with a replica in every region it serves
3154
+ from, and each replica's policy must allow Lambda to decrypt (see `encryptionKeyPolicyStatement()`). A key defined
3155
+ in this app gets that statement added to its own policy.
3156
+
3157
+ Changing the key creates a new revision. Earlier revisions, including the ones kept as rollback targets, still
3158
+ need their key.
3159
+ [disable-awslint:prefer-ref-interface]
3160
+
3161
+ ---
3162
+
3024
3163
  ##### `endpoint`<sup>Optional</sup> <a name="endpoint" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.endpoint"></a>
3025
3164
 
3026
3165
  ```typescript
@@ -3049,6 +3188,26 @@ Names starting with `AWS_` are reserved.
3049
3188
 
3050
3189
  ---
3051
3190
 
3191
+ ##### `logEncryptionKey`<sup>Optional</sup> <a name="logEncryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.logEncryptionKey"></a>
3192
+
3193
+ ```typescript
3194
+ public readonly logEncryptionKey: IKey;
3195
+ ```
3196
+
3197
+ - *Type:* aws-cdk-lib.aws_kms.IKey
3198
+ - *Default:* CloudWatch Logs' own encryption
3199
+
3200
+ A customer managed KMS key for the function's log groups, in every region it serves from.
3201
+
3202
+ CloudWatch Logs needs a key in each group's region: for regions other than the key's own, the construct uses the
3203
+ replica of a **multi-Region key** there (the same key ID). Each key's policy must allow CloudWatch Logs in its
3204
+ region (see `logEncryptionKeyPolicyStatement()`). A key defined in this app gets that statement for its own region.
3205
+
3206
+ Removing the key decrypts nothing: the groups keep their existing events encrypted with it.
3207
+ [disable-awslint:prefer-ref-interface]
3208
+
3209
+ ---
3210
+
3052
3211
  ##### `logRemovalPolicy`<sup>Optional</sup> <a name="logRemovalPolicy" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.logRemovalPolicy"></a>
3053
3212
 
3054
3213
  ```typescript
@@ -3613,8 +3772,10 @@ const webFunctionOptions: WebFunctionOptions = { ... }
3613
3772
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.authType">authType</a></code> | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionAuthType">WebFunctionAuthType</a></code> | How callers of the endpoint are authenticated. |
3614
3773
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.applicationLogLevelV2">applicationLogLevelV2</a></code> | <code>aws-cdk-lib.aws_lambda.ApplicationLogLevel</code> | The minimum level of application logs to keep. |
3615
3774
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.description">description</a></code> | <code>string</code> | A description of the function's code and configuration. |
3775
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.encryptionKey">encryptionKey</a></code> | <code>aws-cdk-lib.aws_kms.IKey</code> | A customer managed KMS key for the function's revisions: their code and environment variables. |
3616
3776
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.endpoint">endpoint</a></code> | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionEndpointOptions">WebFunctionEndpointOptions</a></code> | The default endpoint (`fn.endpoint`): where it serves from, its name and limits. It serves the current revision; route it elsewhere with `fn.endpoint.routeTraffic()`. Add more endpoints with `addEndpoint`. |
3617
3777
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.environment">environment</a></code> | <code>{[ key: string ]: string}</code> | Environment variables. |
3778
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.logEncryptionKey">logEncryptionKey</a></code> | <code>aws-cdk-lib.aws_kms.IKey</code> | A customer managed KMS key for the function's log groups, in every region it serves from. |
3618
3779
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.logRemovalPolicy">logRemovalPolicy</a></code> | <code>aws-cdk-lib.RemovalPolicy</code> | What happens to the log groups when the function is removed: RETAIN or DESTROY. |
3619
3780
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.logRetention">logRetention</a></code> | <code>aws-cdk-lib.aws_logs.RetentionDays</code> | Retention for every log group of the function, in every region it serves from. |
3620
3781
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.maxConcurrencyPerEnvironment">maxConcurrencyPerEnvironment</a></code> | <code>number</code> | How many requests one execution environment handles at the same time (1-128). |
@@ -3664,6 +3825,27 @@ A description of the function's code and configuration.
3664
3825
 
3665
3826
  ---
3666
3827
 
3828
+ ##### `encryptionKey`<sup>Optional</sup> <a name="encryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.encryptionKey"></a>
3829
+
3830
+ ```typescript
3831
+ public readonly encryptionKey: IKey;
3832
+ ```
3833
+
3834
+ - *Type:* aws-cdk-lib.aws_kms.IKey
3835
+ - *Default:* an AWS owned key
3836
+
3837
+ A customer managed KMS key for the function's revisions: their code and environment variables.
3838
+
3839
+ A `PER_REGION` or `MULTI_REGION` endpoint needs a **multi-Region key** with a replica in every region it serves
3840
+ from, and each replica's policy must allow Lambda to decrypt (see `encryptionKeyPolicyStatement()`). A key defined
3841
+ in this app gets that statement added to its own policy.
3842
+
3843
+ Changing the key creates a new revision. Earlier revisions, including the ones kept as rollback targets, still
3844
+ need their key.
3845
+ [disable-awslint:prefer-ref-interface]
3846
+
3847
+ ---
3848
+
3667
3849
  ##### `endpoint`<sup>Optional</sup> <a name="endpoint" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.endpoint"></a>
3668
3850
 
3669
3851
  ```typescript
@@ -3692,6 +3874,26 @@ Names starting with `AWS_` are reserved.
3692
3874
 
3693
3875
  ---
3694
3876
 
3877
+ ##### `logEncryptionKey`<sup>Optional</sup> <a name="logEncryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.logEncryptionKey"></a>
3878
+
3879
+ ```typescript
3880
+ public readonly logEncryptionKey: IKey;
3881
+ ```
3882
+
3883
+ - *Type:* aws-cdk-lib.aws_kms.IKey
3884
+ - *Default:* CloudWatch Logs' own encryption
3885
+
3886
+ A customer managed KMS key for the function's log groups, in every region it serves from.
3887
+
3888
+ CloudWatch Logs needs a key in each group's region: for regions other than the key's own, the construct uses the
3889
+ replica of a **multi-Region key** there (the same key ID). Each key's policy must allow CloudWatch Logs in its
3890
+ region (see `logEncryptionKeyPolicyStatement()`). A key defined in this app gets that statement for its own region.
3891
+
3892
+ Removing the key decrypts nothing: the groups keep their existing events encrypted with it.
3893
+ [disable-awslint:prefer-ref-interface]
3894
+
3895
+ ---
3896
+
3695
3897
  ##### `logRemovalPolicy`<sup>Optional</sup> <a name="logRemovalPolicy" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.logRemovalPolicy"></a>
3696
3898
 
3697
3899
  ```typescript
@@ -4372,8 +4574,10 @@ const webFunctionProps: WebFunctionProps = { ... }
4372
4574
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.authType">authType</a></code> | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionAuthType">WebFunctionAuthType</a></code> | How callers of the endpoint are authenticated. |
4373
4575
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.applicationLogLevelV2">applicationLogLevelV2</a></code> | <code>aws-cdk-lib.aws_lambda.ApplicationLogLevel</code> | The minimum level of application logs to keep. |
4374
4576
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.description">description</a></code> | <code>string</code> | A description of the function's code and configuration. |
4577
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.encryptionKey">encryptionKey</a></code> | <code>aws-cdk-lib.aws_kms.IKey</code> | A customer managed KMS key for the function's revisions: their code and environment variables. |
4375
4578
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.endpoint">endpoint</a></code> | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionEndpointOptions">WebFunctionEndpointOptions</a></code> | The default endpoint (`fn.endpoint`): where it serves from, its name and limits. It serves the current revision; route it elsewhere with `fn.endpoint.routeTraffic()`. Add more endpoints with `addEndpoint`. |
4376
4579
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.environment">environment</a></code> | <code>{[ key: string ]: string}</code> | Environment variables. |
4580
+ | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.logEncryptionKey">logEncryptionKey</a></code> | <code>aws-cdk-lib.aws_kms.IKey</code> | A customer managed KMS key for the function's log groups, in every region it serves from. |
4377
4581
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.logRemovalPolicy">logRemovalPolicy</a></code> | <code>aws-cdk-lib.RemovalPolicy</code> | What happens to the log groups when the function is removed: RETAIN or DESTROY. |
4378
4582
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.logRetention">logRetention</a></code> | <code>aws-cdk-lib.aws_logs.RetentionDays</code> | Retention for every log group of the function, in every region it serves from. |
4379
4583
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.maxConcurrencyPerEnvironment">maxConcurrencyPerEnvironment</a></code> | <code>number</code> | How many requests one execution environment handles at the same time (1-128). |
@@ -4426,6 +4630,27 @@ A description of the function's code and configuration.
4426
4630
 
4427
4631
  ---
4428
4632
 
4633
+ ##### `encryptionKey`<sup>Optional</sup> <a name="encryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.encryptionKey"></a>
4634
+
4635
+ ```typescript
4636
+ public readonly encryptionKey: IKey;
4637
+ ```
4638
+
4639
+ - *Type:* aws-cdk-lib.aws_kms.IKey
4640
+ - *Default:* an AWS owned key
4641
+
4642
+ A customer managed KMS key for the function's revisions: their code and environment variables.
4643
+
4644
+ A `PER_REGION` or `MULTI_REGION` endpoint needs a **multi-Region key** with a replica in every region it serves
4645
+ from, and each replica's policy must allow Lambda to decrypt (see `encryptionKeyPolicyStatement()`). A key defined
4646
+ in this app gets that statement added to its own policy.
4647
+
4648
+ Changing the key creates a new revision. Earlier revisions, including the ones kept as rollback targets, still
4649
+ need their key.
4650
+ [disable-awslint:prefer-ref-interface]
4651
+
4652
+ ---
4653
+
4429
4654
  ##### `endpoint`<sup>Optional</sup> <a name="endpoint" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.endpoint"></a>
4430
4655
 
4431
4656
  ```typescript
@@ -4454,6 +4679,26 @@ Names starting with `AWS_` are reserved.
4454
4679
 
4455
4680
  ---
4456
4681
 
4682
+ ##### `logEncryptionKey`<sup>Optional</sup> <a name="logEncryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.logEncryptionKey"></a>
4683
+
4684
+ ```typescript
4685
+ public readonly logEncryptionKey: IKey;
4686
+ ```
4687
+
4688
+ - *Type:* aws-cdk-lib.aws_kms.IKey
4689
+ - *Default:* CloudWatch Logs' own encryption
4690
+
4691
+ A customer managed KMS key for the function's log groups, in every region it serves from.
4692
+
4693
+ CloudWatch Logs needs a key in each group's region: for regions other than the key's own, the construct uses the
4694
+ replica of a **multi-Region key** there (the same key ID). Each key's policy must allow CloudWatch Logs in its
4695
+ region (see `logEncryptionKeyPolicyStatement()`). A key defined in this app gets that statement for its own region.
4696
+
4697
+ Removing the key decrypts nothing: the groups keep their existing events encrypted with it.
4698
+ [disable-awslint:prefer-ref-interface]
4699
+
4700
+ ---
4701
+
4457
4702
  ##### `logRemovalPolicy`<sup>Optional</sup> <a name="logRemovalPolicy" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.logRemovalPolicy"></a>
4458
4703
 
4459
4704
  ```typescript
package/README.md CHANGED
@@ -279,6 +279,70 @@ table.grantReadWriteData(api); // the default role trusts lambda.amazo
279
279
  - **The default execution role can only write to the function's own log groups**: the home region's, and the `.local` copy in every region it serves from. That's the minimum AWS documents for Web Functions. It doesn't use `AWSLambdaBasicExecutionRole`, which can also create any log group. Pass `role` to use your own, and include those log permissions.
280
280
  - **Renaming the function replaces it and changes its URL.** A generated name depends on the construct path, so moving the construct renames it too.
281
281
 
282
+ ### Encryption
283
+
284
+ Lambda encrypts each revision's code and environment variables with an AWS owned key. To use your own key, pass `encryptionKey`:
285
+
286
+ ```ts
287
+ declare const keyStack: Stack; // deploys first
288
+ declare const replicaStack: Stack; // in us-east-1, deploys before this stack
289
+
290
+ const key = new kms.Key(keyStack, 'Key', { multiRegion: true });
291
+ const api = new WebFunction(this, 'Api', {
292
+ runtime: lambda.Runtime.NODEJS_24_X,
293
+ code: lambda.Code.fromAsset('build'),
294
+ authType: WebFunctionAuthType.AWS_IAM,
295
+ endpoint: { endpointType: WebFunctionEndpointType.PER_REGION, regions: ['us-east-1'] },
296
+ encryptionKey: key,
297
+ });
298
+
299
+ // One replica per region the endpoint serves from, with Lambda's statement in its own policy.
300
+ new kms.CfnReplicaKey(replicaStack, 'KeyReplica', {
301
+ primaryKeyArn: key.keyArn,
302
+ keyPolicy: new iam.PolicyDocument({
303
+ statements: [
304
+ new iam.PolicyStatement({ principals: [new iam.AccountRootPrincipal()], actions: ['kms:*'], resources: ['*'] }),
305
+ api.encryptionKeyPolicyStatement(),
306
+ ],
307
+ }),
308
+ });
309
+ ```
310
+
311
+ - **A key defined in your app gets Lambda's statement automatically.** It allows `kms:Decrypt` for `lambda.amazonaws.com`, limited to this function's revisions through `aws:SourceArn` and the encryption context Lambda sets. For an imported key, add `encryptionKeyPolicyStatement()` to its policy yourself.
312
+ - **`PER_REGION` and `MULTI_REGION` endpoints need a multi-Region key**, with a replica in every region they serve from. The replicas must exist before the endpoint, so put the key and its replicas in stacks that deploy before the function's. Replica policies aren't copied from the primary, so each one needs `encryptionKeyPolicyStatement()`. With a single-Region key, the endpoint fails to activate in its other regions and the whole deployment rolls back. The construct fails synthesis instead, when it can tell: a key in your app without `multiRegion`, or an imported key whose ID doesn't start with `mrk-`.
313
+ - **CloudFormation's role creates the revisions**, so it needs `kms:DescribeKey`, `kms:GenerateDataKey` and `kms:Decrypt` on the key. A key's default policy delegates to IAM, and CDK's default deployment role is allowed.
314
+ - **Changing the key creates a new revision.** Earlier revisions keep their key, including the ones kept as rollback targets (`revisionRetention`). Keep the old key enabled while any of them might serve traffic again.
315
+ - **Disabling the key, or removing Lambda's access, stops new execution environments from starting.** Running ones keep their decrypted copy for a while, so this doesn't contain traffic immediately.
316
+
317
+ Log groups are encrypted by CloudWatch Logs. To use your own key for them too, pass `logEncryptionKey`. It can be the same key:
318
+
319
+ ```ts
320
+ declare const key: kms.Key; // multiRegion: true, in the function's region
321
+ declare const replica: kms.CfnReplicaKey; // in us-east-1
322
+
323
+ const api = new WebFunction(this, 'Api', {
324
+ runtime: lambda.Runtime.NODEJS_24_X,
325
+ code: lambda.Code.fromAsset('build'),
326
+ authType: WebFunctionAuthType.AWS_IAM,
327
+ endpoint: { endpointType: WebFunctionEndpointType.PER_REGION, regions: ['us-east-1'] },
328
+ logEncryptionKey: key,
329
+ });
330
+
331
+ // The replica's policy also allows CloudWatch Logs in its region, for this function's groups.
332
+ replica.keyPolicy = new iam.PolicyDocument({
333
+ statements: [
334
+ new iam.PolicyStatement({ principals: [new iam.AccountRootPrincipal()], actions: ['kms:*'], resources: ['*'] }),
335
+ api.logEncryptionKeyPolicyStatement('us-east-1'),
336
+ ],
337
+ });
338
+ ```
339
+
340
+ - **CloudWatch Logs only uses a key in the group's own region.** The groups in the key's region use the key. Groups in other regions use the multi-Region key's replica there, which has the same key ID. With a single-Region key, synthesis fails as soon as a group is in another region.
341
+ - **A key defined in your app gets CloudWatch Logs' statement for its own region.** It allows `logs.<region>.amazonaws.com` to use the key for this function's log groups only. Add `logEncryptionKeyPolicyStatement(region)` to each replica's policy, and to an imported key's.
342
+ - **The construct's provider sets the key on each group, and needs `kms:DescribeKey` on it to do so.** The construct grants that through IAM, which a key's default policy allows. If a key's policy doesn't delegate to IAM, allow the provider's role in the key policy.
343
+ - **Adding or changing the key encrypts new events only.** Existing events stay encrypted with the key they were written with. Removing `logEncryptionKey` sets the groups back to CloudWatch Logs' encryption.
344
+ - **Retained log groups need their key to stay readable.** The default `logRemovalPolicy` is `RETAIN`, so keep the key while you keep the logs.
345
+
282
346
  ### Defaults for every function (property injection)
283
347
 
284
348
  To give every function under a scope the same defaults, register a property injector for `WebFunction.PROPERTY_INJECTION_ID`, as you would for aws-cdk-lib's constructs. For example, a team's log retention: