@ashishpandeyone/cdk-lambda-web-function 0.1.11 → 0.1.13

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
@@ -64,6 +64,7 @@ new NodejsWebFunction(scope: Construct, id: string, props: NodejsWebFunctionProp
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
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`). |
67
68
 
68
69
  ---
69
70
 
@@ -363,6 +364,25 @@ The key-policy statement Lambda needs to start this function's environments with
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
364
365
  yourself: replicas don't share their primary's policy.
365
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
+
366
386
  #### Static Functions <a name="Static Functions" id="Static Functions"></a>
367
387
 
368
388
  | **Name** | **Description** |
@@ -542,6 +562,7 @@ Imports an existing Web Function in this stack's account and region by its name.
542
562
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.property.revisionId">revisionId</a></code> | <code>string</code> | The ID of the current revision. |
543
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. |
544
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. |
545
566
 
546
567
  ---
547
568
 
@@ -727,6 +748,18 @@ The customer managed key of the function's revisions, if any.
727
748
 
728
749
  ---
729
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
+
730
763
  #### Constants <a name="Constants" id="Constants"></a>
731
764
 
732
765
  | **Name** | **Type** | **Description** |
@@ -814,6 +847,7 @@ new WebFunction(scope: Construct, id: string, props: WebFunctionProps)
814
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. |
815
848
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.addToRolePolicy">addToRolePolicy</a></code> | Adds a statement to the execution role's policy. |
816
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`). |
817
851
 
818
852
  ---
819
853
 
@@ -1113,6 +1147,25 @@ The key-policy statement Lambda needs to start this function's environments with
1113
1147
  It's added to `encryptionKey` when the key is defined in this app. Add it to every replica of a multi-Region key
1114
1148
  yourself: replicas don't share their primary's policy.
1115
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
+
1116
1169
  #### Static Functions <a name="Static Functions" id="Static Functions"></a>
1117
1170
 
1118
1171
  | **Name** | **Description** |
@@ -1292,6 +1345,7 @@ Imports an existing Web Function in this stack's account and region by its name.
1292
1345
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.property.revisionId">revisionId</a></code> | <code>string</code> | The ID of the current revision. |
1293
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. |
1294
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. |
1295
1349
 
1296
1350
  ---
1297
1351
 
@@ -1477,6 +1531,18 @@ The customer managed key of the function's revisions, if any.
1477
1531
 
1478
1532
  ---
1479
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
+
1480
1546
  #### Constants <a name="Constants" id="Constants"></a>
1481
1547
 
1482
1548
  | **Name** | **Type** | **Description** |
@@ -3018,6 +3084,7 @@ const nodejsWebFunctionProps: NodejsWebFunctionProps = { ... }
3018
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. |
3019
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`. |
3020
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. |
3021
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. |
3022
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. |
3023
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). |
@@ -3121,6 +3188,26 @@ Names starting with `AWS_` are reserved.
3121
3188
 
3122
3189
  ---
3123
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
+
3124
3211
  ##### `logRemovalPolicy`<sup>Optional</sup> <a name="logRemovalPolicy" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.logRemovalPolicy"></a>
3125
3212
 
3126
3213
  ```typescript
@@ -3688,6 +3775,7 @@ const webFunctionOptions: WebFunctionOptions = { ... }
3688
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. |
3689
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`. |
3690
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. |
3691
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. |
3692
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. |
3693
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). |
@@ -3786,6 +3874,26 @@ Names starting with `AWS_` are reserved.
3786
3874
 
3787
3875
  ---
3788
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
+
3789
3897
  ##### `logRemovalPolicy`<sup>Optional</sup> <a name="logRemovalPolicy" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.logRemovalPolicy"></a>
3790
3898
 
3791
3899
  ```typescript
@@ -4469,6 +4577,7 @@ const webFunctionProps: WebFunctionProps = { ... }
4469
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. |
4470
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`. |
4471
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. |
4472
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. |
4473
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. |
4474
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). |
@@ -4570,6 +4679,26 @@ Names starting with `AWS_` are reserved.
4570
4679
 
4571
4680
  ---
4572
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
+
4573
4702
  ##### `logRemovalPolicy`<sup>Optional</sup> <a name="logRemovalPolicy" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.logRemovalPolicy"></a>
4574
4703
 
4575
4704
  ```typescript
package/README.md CHANGED
@@ -314,6 +314,35 @@ new kms.CfnReplicaKey(replicaStack, 'KeyReplica', {
314
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
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
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
+
317
346
  ### Defaults for every function (property injection)
318
347
 
319
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: