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

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,7 @@ 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). |
66
67
 
67
68
  ---
68
69
 
@@ -351,6 +352,17 @@ Adds a statement to the execution role's policy.
351
352
 
352
353
  ---
353
354
 
355
+ ##### `encryptionKeyPolicyStatement` <a name="encryptionKeyPolicyStatement" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.encryptionKeyPolicyStatement"></a>
356
+
357
+ ```typescript
358
+ public encryptionKeyPolicyStatement(): PolicyStatement
359
+ ```
360
+
361
+ 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).
362
+
363
+ It's added to `encryptionKey` when the key is defined in this app. Add it to every replica of a multi-Region key
364
+ yourself: replicas don't share their primary's policy.
365
+
354
366
  #### Static Functions <a name="Static Functions" id="Static Functions"></a>
355
367
 
356
368
  | **Name** | **Description** |
@@ -529,6 +541,7 @@ Imports an existing Web Function in this stack's account and region by its name.
529
541
  | <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
542
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.property.revisionId">revisionId</a></code> | <code>string</code> | The ID of the current revision. |
531
543
  | <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
+ | <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. |
532
545
 
533
546
  ---
534
547
 
@@ -702,6 +715,18 @@ The execution role.
702
715
 
703
716
  ---
704
717
 
718
+ ##### `encryptionKey`<sup>Optional</sup> <a name="encryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction.property.encryptionKey"></a>
719
+
720
+ ```typescript
721
+ public readonly encryptionKey: IKey;
722
+ ```
723
+
724
+ - *Type:* aws-cdk-lib.aws_kms.IKey
725
+
726
+ The customer managed key of the function's revisions, if any.
727
+
728
+ ---
729
+
705
730
  #### Constants <a name="Constants" id="Constants"></a>
706
731
 
707
732
  | **Name** | **Type** | **Description** |
@@ -788,6 +813,7 @@ new WebFunction(scope: Construct, id: string, props: WebFunctionProps)
788
813
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.addEnvironment">addEnvironment</a></code> | Adds an environment variable. |
789
814
  | <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
815
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.addToRolePolicy">addToRolePolicy</a></code> | Adds a statement to the execution role's policy. |
816
+ | <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). |
791
817
 
792
818
  ---
793
819
 
@@ -1076,6 +1102,17 @@ Adds a statement to the execution role's policy.
1076
1102
 
1077
1103
  ---
1078
1104
 
1105
+ ##### `encryptionKeyPolicyStatement` <a name="encryptionKeyPolicyStatement" id="@ashishpandeyone/cdk-lambda-web-function.WebFunction.encryptionKeyPolicyStatement"></a>
1106
+
1107
+ ```typescript
1108
+ public encryptionKeyPolicyStatement(): PolicyStatement
1109
+ ```
1110
+
1111
+ 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).
1112
+
1113
+ It's added to `encryptionKey` when the key is defined in this app. Add it to every replica of a multi-Region key
1114
+ yourself: replicas don't share their primary's policy.
1115
+
1079
1116
  #### Static Functions <a name="Static Functions" id="Static Functions"></a>
1080
1117
 
1081
1118
  | **Name** | **Description** |
@@ -1254,6 +1291,7 @@ Imports an existing Web Function in this stack's account and region by its name.
1254
1291
  | <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
1292
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunction.property.revisionId">revisionId</a></code> | <code>string</code> | The ID of the current revision. |
1256
1293
  | <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
+ | <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. |
1257
1295
 
1258
1296
  ---
1259
1297
 
@@ -1427,6 +1465,18 @@ The execution role.
1427
1465
 
1428
1466
  ---
1429
1467
 
1468
+ ##### `encryptionKey`<sup>Optional</sup> <a name="encryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.WebFunction.property.encryptionKey"></a>
1469
+
1470
+ ```typescript
1471
+ public readonly encryptionKey: IKey;
1472
+ ```
1473
+
1474
+ - *Type:* aws-cdk-lib.aws_kms.IKey
1475
+
1476
+ The customer managed key of the function's revisions, if any.
1477
+
1478
+ ---
1479
+
1430
1480
  #### Constants <a name="Constants" id="Constants"></a>
1431
1481
 
1432
1482
  | **Name** | **Type** | **Description** |
@@ -2965,6 +3015,7 @@ const nodejsWebFunctionProps: NodejsWebFunctionProps = { ... }
2965
3015
  | <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
3016
  | <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
3017
  | <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. |
3018
+ | <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
3019
  | <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
3020
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.environment">environment</a></code> | <code>{[ key: string ]: string}</code> | Environment variables. |
2970
3021
  | <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. |
@@ -3021,6 +3072,27 @@ A description of the function's code and configuration.
3021
3072
 
3022
3073
  ---
3023
3074
 
3075
+ ##### `encryptionKey`<sup>Optional</sup> <a name="encryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.encryptionKey"></a>
3076
+
3077
+ ```typescript
3078
+ public readonly encryptionKey: IKey;
3079
+ ```
3080
+
3081
+ - *Type:* aws-cdk-lib.aws_kms.IKey
3082
+ - *Default:* an AWS owned key
3083
+
3084
+ A customer managed KMS key for the function's revisions: their code and environment variables.
3085
+
3086
+ A `PER_REGION` or `MULTI_REGION` endpoint needs a **multi-Region key** with a replica in every region it serves
3087
+ from, and each replica's policy must allow Lambda to decrypt (see `encryptionKeyPolicyStatement()`). A key defined
3088
+ in this app gets that statement added to its own policy.
3089
+
3090
+ Changing the key creates a new revision. Earlier revisions, including the ones kept as rollback targets, still
3091
+ need their key.
3092
+ [disable-awslint:prefer-ref-interface]
3093
+
3094
+ ---
3095
+
3024
3096
  ##### `endpoint`<sup>Optional</sup> <a name="endpoint" id="@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunctionProps.property.endpoint"></a>
3025
3097
 
3026
3098
  ```typescript
@@ -3613,6 +3685,7 @@ const webFunctionOptions: WebFunctionOptions = { ... }
3613
3685
  | <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
3686
  | <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
3687
  | <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. |
3688
+ | <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
3689
  | <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
3690
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.environment">environment</a></code> | <code>{[ key: string ]: string}</code> | Environment variables. |
3618
3691
  | <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. |
@@ -3664,6 +3737,27 @@ A description of the function's code and configuration.
3664
3737
 
3665
3738
  ---
3666
3739
 
3740
+ ##### `encryptionKey`<sup>Optional</sup> <a name="encryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.encryptionKey"></a>
3741
+
3742
+ ```typescript
3743
+ public readonly encryptionKey: IKey;
3744
+ ```
3745
+
3746
+ - *Type:* aws-cdk-lib.aws_kms.IKey
3747
+ - *Default:* an AWS owned key
3748
+
3749
+ A customer managed KMS key for the function's revisions: their code and environment variables.
3750
+
3751
+ A `PER_REGION` or `MULTI_REGION` endpoint needs a **multi-Region key** with a replica in every region it serves
3752
+ from, and each replica's policy must allow Lambda to decrypt (see `encryptionKeyPolicyStatement()`). A key defined
3753
+ in this app gets that statement added to its own policy.
3754
+
3755
+ Changing the key creates a new revision. Earlier revisions, including the ones kept as rollback targets, still
3756
+ need their key.
3757
+ [disable-awslint:prefer-ref-interface]
3758
+
3759
+ ---
3760
+
3667
3761
  ##### `endpoint`<sup>Optional</sup> <a name="endpoint" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionOptions.property.endpoint"></a>
3668
3762
 
3669
3763
  ```typescript
@@ -4372,6 +4466,7 @@ const webFunctionProps: WebFunctionProps = { ... }
4372
4466
  | <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
4467
  | <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
4468
  | <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. |
4469
+ | <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
4470
  | <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
4471
  | <code><a href="#@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.environment">environment</a></code> | <code>{[ key: string ]: string}</code> | Environment variables. |
4377
4472
  | <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. |
@@ -4426,6 +4521,27 @@ A description of the function's code and configuration.
4426
4521
 
4427
4522
  ---
4428
4523
 
4524
+ ##### `encryptionKey`<sup>Optional</sup> <a name="encryptionKey" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.encryptionKey"></a>
4525
+
4526
+ ```typescript
4527
+ public readonly encryptionKey: IKey;
4528
+ ```
4529
+
4530
+ - *Type:* aws-cdk-lib.aws_kms.IKey
4531
+ - *Default:* an AWS owned key
4532
+
4533
+ A customer managed KMS key for the function's revisions: their code and environment variables.
4534
+
4535
+ A `PER_REGION` or `MULTI_REGION` endpoint needs a **multi-Region key** with a replica in every region it serves
4536
+ from, and each replica's policy must allow Lambda to decrypt (see `encryptionKeyPolicyStatement()`). A key defined
4537
+ in this app gets that statement added to its own policy.
4538
+
4539
+ Changing the key creates a new revision. Earlier revisions, including the ones kept as rollback targets, still
4540
+ need their key.
4541
+ [disable-awslint:prefer-ref-interface]
4542
+
4543
+ ---
4544
+
4429
4545
  ##### `endpoint`<sup>Optional</sup> <a name="endpoint" id="@ashishpandeyone/cdk-lambda-web-function.WebFunctionProps.property.endpoint"></a>
4430
4546
 
4431
4547
  ```typescript
package/README.md CHANGED
@@ -279,6 +279,41 @@ 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
+
282
317
  ### Defaults for every function (property injection)
283
318
 
284
319
  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:
@@ -50,7 +50,7 @@ const web_function_1 = require("./web-function");
50
50
  * bundle, and `NODE_OPTIONS=--enable-source-maps` when source maps are on.
51
51
  */
52
52
  class NodejsWebFunction extends web_function_1.WebFunction {
53
- static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction", version: "0.1.10" };
53
+ static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.NodejsWebFunction", version: "0.1.11" };
54
54
  /**
55
55
  * Identifies this class to property injectors (`PropertyInjectors.of(scope).add(...)`). A `NodejsWebFunction` gets
56
56
  * its own injector first, then `WebFunction`'s, as aws-cdk-lib's `NodejsFunction` does with `Function`'s.
@@ -11,7 +11,7 @@ const MAX_STEPS = 20;
11
11
  * How an endpoint moves its traffic to a new revision.
12
12
  */
13
13
  class WebFunctionDeployment {
14
- static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.WebFunctionDeployment", version: "0.1.10" };
14
+ static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.WebFunctionDeployment", version: "0.1.11" };
15
15
  /**
16
16
  * All traffic moves to the new revision at once, as soon as it's ready (the default).
17
17
  */
@@ -53,7 +53,7 @@ const web_function_grants_1 = require("./web-function-grants");
53
53
  * Endpoints are created only through `WebFunction`, which owns their log groups in every region, so the constructor is private.
54
54
  */
55
55
  class WebFunctionEndpoint extends constructs_1.Construct {
56
- static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.WebFunctionEndpoint", version: "0.1.10" };
56
+ static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.WebFunctionEndpoint", version: "0.1.11" };
57
57
  /**
58
58
  * Creates an endpoint of a Web Function. Used by `WebFunction`.
59
59
  *
@@ -42,7 +42,7 @@ const iam = __importStar(require("aws-cdk-lib/aws-iam"));
42
42
  class WebFunctionGrants {
43
43
  endpointArns;
44
44
  webFunction;
45
- static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.WebFunctionGrants", version: "0.1.10" };
45
+ static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.WebFunctionGrants", version: "0.1.11" };
46
46
  /**
47
47
  * @internal
48
48
  */
@@ -54,7 +54,7 @@ const OPT_IN_REGIONS = [
54
54
  * and only your distribution may call the endpoint. `new WebFunctionOrigin(endpoint)` is for a public (`NONE`) endpoint.
55
55
  */
56
56
  class WebFunctionOrigin extends cloudfront.OriginBase {
57
- static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.WebFunctionOrigin", version: "0.1.10" };
57
+ static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.WebFunctionOrigin", version: "0.1.11" };
58
58
  /**
59
59
  * An origin for an `AWS_IAM` endpoint, with origin access control: CloudFront signs every request to the endpoint
60
60
  * (`always-amz-auth`, which keeps the viewer's `Authorization` header for your application), and the function's
@@ -11,7 +11,7 @@ const constructs_1 = require("constructs");
11
11
  * only revisions within `revisionRetention`, or that an endpoint routes to, are kept.
12
12
  */
13
13
  class WebFunctionRevision extends constructs_1.Construct {
14
- static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.WebFunctionRevision", version: "0.1.10" };
14
+ static [JSII_RTTI_SYMBOL_1] = { fqn: "@ashishpandeyone/cdk-lambda-web-function.WebFunctionRevision", version: "0.1.11" };
15
15
  /**
16
16
  * References an existing revision of `webFunction`, e.g. to pin an endpoint to it or split traffic with it.
17
17
  */
@@ -1,6 +1,7 @@
1
1
  import { Duration, type IResource, RemovalPolicy, Resource } from 'aws-cdk-lib';
2
2
  import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';
3
3
  import * as iam from 'aws-cdk-lib/aws-iam';
4
+ import * as kms from 'aws-cdk-lib/aws-kms';
4
5
  import * as lambda from 'aws-cdk-lib/aws-lambda';
5
6
  import * as logs from 'aws-cdk-lib/aws-logs';
6
7
  import { Construct } from 'constructs';
@@ -56,6 +57,20 @@ export interface WebFunctionOptions {
56
57
  * @default - a role trusting `lambda.amazonaws.com` with `AWSLambdaBasicExecutionRole`
57
58
  */
58
59
  readonly role?: iam.IRole;
60
+ /**
61
+ * A customer managed KMS key for the function's revisions: their code and environment variables.
62
+ *
63
+ * A `PER_REGION` or `MULTI_REGION` endpoint needs a **multi-Region key** with a replica in every region it serves
64
+ * from, and each replica's policy must allow Lambda to decrypt (see `encryptionKeyPolicyStatement()`). A key defined
65
+ * in this app gets that statement added to its own policy.
66
+ *
67
+ * Changing the key creates a new revision. Earlier revisions, including the ones kept as rollback targets, still
68
+ * need their key.
69
+ * [disable-awslint:prefer-ref-interface]
70
+ *
71
+ * @default - an AWS owned key
72
+ */
73
+ readonly encryptionKey?: kms.IKey;
59
74
  /**
60
75
  * Environment variables. Names starting with `AWS_` are reserved.
61
76
  *
@@ -325,6 +340,8 @@ export declare class WebFunction extends WebFunctionBase implements iam.IGrantab
325
340
  readonly grants: WebFunctionGrants;
326
341
  /** The execution role. */
327
342
  readonly role: iam.IRole;
343
+ /** The customer managed key of the function's revisions, if any. */
344
+ readonly encryptionKey?: kms.IKey;
328
345
  /** The principal to grant permissions to (the execution role). */
329
346
  readonly grantPrincipal: iam.IPrincipal;
330
347
  /**
@@ -368,6 +385,16 @@ export declare class WebFunction extends WebFunctionBase implements iam.IGrantab
368
385
  * @param id the statement ID (`Sid`): letters and digits, unique within the function
369
386
  */
370
387
  addPermission(id: string, permission: WebFunctionPermission): void;
388
+ /**
389
+ * The key-policy statement Lambda needs to start this function's environments with `encryptionKey`: `kms:Decrypt` for
390
+ * `lambda.amazonaws.com`, limited to this function's revisions (`aws:SourceArn` and the encryption context Lambda sets).
391
+ *
392
+ * It's added to `encryptionKey` when the key is defined in this app. Add it to every replica of a multi-Region key
393
+ * yourself: replicas don't share their primary's policy.
394
+ */
395
+ encryptionKeyPolicyStatement(): iam.PolicyStatement;
396
+ /** Regional and multi-region endpoints need a multi-Region key: otherwise their other regions fail to activate. */
397
+ private validateEncryptionKey;
371
398
  private createEndpoint;
372
399
  /**
373
400
  * The default execution role: write to the function's own log groups only (the home region's and every region's