@ashishpandeyone/cdk-lambda-web-function 0.1.11 → 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/.jsii +125 -62
- package/.jsii.tabl.json +1 -1
- package/API.md +129 -0
- package/README.md +29 -0
- package/assets/web-function-provider/index.js +19 -19
- package/lib/nodejs-web-function.js +1 -1
- package/lib/private/log-group.d.ts +2 -0
- package/lib/private/log-group.js +11 -2
- package/lib/private/provider-protocol.d.ts +2 -0
- package/lib/private/provider-protocol.js +1 -1
- package/lib/web-function-deployment.js +1 -1
- package/lib/web-function-endpoint.js +1 -1
- package/lib/web-function-grants.js +1 -1
- package/lib/web-function-origin.js +1 -1
- package/lib/web-function-revision.js +1 -1
- package/lib/web-function.d.ts +29 -0
- package/lib/web-function.js +55 -4
- package/package.json +1 -1
package/.jsii
CHANGED
|
@@ -9745,7 +9745,7 @@
|
|
|
9745
9745
|
},
|
|
9746
9746
|
"name": "@ashishpandeyone/cdk-lambda-web-function",
|
|
9747
9747
|
"readme": {
|
|
9748
|
-
"markdown": "# CDK constructs for AWS Lambda Web Functions\n\n<!--BEGIN STABILITY BANNER-->\n\n---\n\n\n\n> The APIs of higher level constructs in this module are experimental and under active development.\n> They are subject to non-backward compatible changes or removal in any future version. These are\n> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be\n> announced in the release notes. This means that while you may use them, you may need to update\n> your source code when upgrading to a newer version of this package.\n\n---\n\n<!--END STABILITY BANNER-->\n\n[AWS Lambda Web Functions](https://docs.aws.amazon.com/lambda/latest/dg/web-functions.html) run an ordinary Node.js HTTP server (Express, Fastify, Hono, `node:http`) on Lambda and give it an HTTPS endpoint, optionally served from several regions. `WebFunction` deploys one, following the conventions of `aws-cdk-lib/aws-lambda` where the two services overlap.\n\n```ts fixture=bare\nimport * as lambda from 'aws-cdk-lib/aws-lambda';\nimport { WebFunction, WebFunctionAuthType, WebFunctionEndpointType } from '@ashishpandeyone/cdk-lambda-web-function';\n\nconst fn = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.AWS_IAM,\n endpoint: {\n endpointType: WebFunctionEndpointType.MULTI_REGION,\n regions: ['us-east-1', 'eu-west-1'],\n },\n});\n\nnew CfnOutput(this, 'Url', { value: fn.endpoint.url }); // https://<id>.lambda-web.global.on.aws\n```\n\nThe stack's region is the function's **home region**. Multi-region endpoints need a stack with an explicit `env.region`.\n\n## Installation\n\n```bash\nnpm install @ashishpandeyone/cdk-lambda-web-function\n```\n\nIt needs `aws-cdk-lib` 2.273.0 or later and `constructs` 10.5.1 or later (peer dependencies), and Node.js 22 or later. The package is published for TypeScript and JavaScript only.\n\n## Writing the server\n\n1. Listen on the host and port in **`AWS_LAMBDA_HTTP_ENDPOINT`** (`0.0.0.0:3000` today). `PORT` is not set.\n2. Start listening within **10 seconds**, or initialisation fails with `Application.TimeoutListenError`.\n3. Put the entry file at the root of your bundle as **`index.js`**, or set `entrypoint`.\n4. The runtime has **no AWS SDK**: bundle the clients you import.\n5. Code runs on **arm64**.\n\n```js\nconst express = require('express');\n\nconst app = express();\napp.get('/', (req, res) => res.json({ hello: 'world', region: process.env.AWS_REGION }));\n\nconst [host, port] = process.env.AWS_LAMBDA_HTTP_ENDPOINT.split(':');\napp.listen(Number(port), host);\n```\n\nRequests carry `lambda-web-request-id` and `lambda-web-endpoint-name` headers.\n\n## Regions and endpoints\n\nEach `WebFunction` has a default endpoint, `fn.endpoint`, configured with the `endpoint` property. [Add more](#more-endpoints) with `fn.addEndpoint()`.\n\n| `endpointType` | URL | Routing |\n|---|---|---|\n| `HOME_REGION` (default) | `https://<id>.<cell>.lambda-web.<home>.on.aws` | home region only |\n| `MULTI_REGION` | one global `https://<id>.lambda-web.global.on.aws` | nearest region |\n| `PER_REGION` | one URL per region, from `fn.endpoint.regionalUrl(region)` | the region in the hostname |\n\n```ts\nconst perRegion = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.AWS_IAM,\n endpoint: {\n endpointType: WebFunctionEndpointType.PER_REGION,\n regions: ['us-east-1', 'eu-west-1'],\n },\n});\n\nnew CfnOutput(this, 'UsEast1Url', { value: perRegion.endpoint.regionalUrl('us-east-1') });\n// perRegion.endpoint.regions is ['<home region>', 'eu-west-1', 'us-east-1']\n```\n\n- `MULTI_REGION` and `PER_REGION` need at least one region besides the home region; `HOME_REGION` takes none.\n- A MultiRegion endpoint takes about a minute to create.\n- Lambda routes a `MULTI_REGION` endpoint by latency, not by health: it doesn't fail over when a region has problems.\n\n### More endpoints\n\nA function can have up to 10 endpoints, each with its own URL, authentication, regions and limits. For example, a public endpoint next to an IAM-only global one:\n\n```ts\nconst api = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.NONE, // the default endpoint is public\n endpoint: { rateLimit: 1000 }, // requests per second\n});\n\nconst internal = api.addEndpoint('Internal', {\n authType: WebFunctionAuthType.AWS_IAM,\n endpointType: WebFunctionEndpointType.MULTI_REGION,\n regions: ['us-east-1', 'eu-west-1'],\n description: 'Service-to-service traffic',\n maxEnvironments: 50,\n});\ninternal.grantInvoke(consumerRole);\nnew CfnOutput(this, 'InternalUrl', { value: internal.url });\n```\n\n- `rateLimit` takes 0 (blocks all traffic), 100–1,000 in steps of 100, or 2,000–10,000 in steps of 1,000; excess requests get HTTP 429. `maxEnvironments` takes 2–10,000.\n- **Both limits apply separately in each region** an endpoint serves from: a 3-region endpoint with `rateLimit: 1000` accepts up to 1,000 requests per second in each region.\n- Endpoints can serve the same regions. The construct owns one `.local` log group per region, whichever endpoints serve it.\n\n### Changing regions or the endpoint type\n\nAn endpoint's type and regions can't change in place: a change creates a **new endpoint with a new URL**, and the old one is deleted once the new one is live. Two endpoints of one function can't share a name, so:\n\n| `endpointName` | Physical name | Changing `regions` or `endpointType` |\n|---|---|---|\n| omitted (recommended) | `default-<hash>` for `fn.endpoint`, `<id>-<hash>` for added endpoints; the hash covers the type and regions | works: new endpoint, new URL |\n| set, e.g. `'live'` | `live` | also change the name in the same deployment, or it fails with *The endpoint live already exists* (the stack rolls back and the old endpoint keeps serving) |\n\nThe construct warns at synth time when `endpointName` is set.\n\n## Authentication and invoking\n\n| `authType` | Meaning |\n|---|---|\n| `AWS_IAM` | Callers sign requests (SigV4 or SigV4a, signing name `lambda`) and need `lambda:InvokeWebFunctionEndpoint` |\n| `NONE` | **Public**: Lambda does no authentication; your application does (JWT, sessions). The `Authorization` header reaches your application untouched. The construct warns at synth time |\n\n```ts\nfn.grants.invoke(consumerRole); // or fn.grantInvoke(consumerRole), as on lambda.Function\n```\n\nThe grant is on the endpoint's home-region ARN, which IAM evaluates in every region the endpoint serves from, including the global URL. `fn.grants` covers the default endpoint only; grant other endpoints with their own `grantInvoke()` or `grants.invoke()`.\n\n| Endpoint | How to sign |\n|---|---|\n| `HOME_REGION` | SigV4 for the home region |\n| `PER_REGION` | SigV4 for the hostname's region, or SigV4a |\n| `MULTI_REGION` | **SigV4a with region set `*`**: you can't know which region will serve the request |\n\n```js\nimport { SignatureV4a } from '@smithy/signature-v4a';\nimport { Sha256 } from '@aws-crypto/sha256-js';\nimport { fromNodeProviderChain } from '@aws-sdk/credential-providers';\n\nconst host = new URL(url).hostname; // url: the endpoint's URL\nconst signer = new SignatureV4a({ service: 'lambda', region: '*', sha256: Sha256, credentials: fromNodeProviderChain() });\nconst signed = await signer.sign(\n { method: 'GET', protocol: 'https:', hostname: host, path: '/', headers: { host } },\n { signingRegion: '*' },\n);\nconst response = await fetch(`https://${host}/`, { headers: signed.headers });\n```\n\n### Other accounts and AWS services\n\nA caller in another account needs permission twice: in its own IAM policy, and in the function's **resource policy**. `grantInvoke` handles the function's side: a role in the function's account only gets an IAM policy statement, while a principal in another account or an AWS service also gets a statement in the resource policy.\n\n```ts\nfn.grantInvoke(iam.Role.fromRoleArn(this, 'Partner', 'arn:aws:iam::444455556666:role/caller'));\n```\n\nFor principals you can't grant to (a whole account, an organization, an AWS service with conditions), use `addPermission`. The `id` becomes the statement's `Sid`:\n\n```ts\nfn.addPermission('PartnerAccount', { principal: new iam.AccountPrincipal('444455556666') });\nfn.addPermission('MyOrg', { principal: new iam.OrganizationPrincipal('o-a1b2c3d4e5'), endpoint: fn.endpoint });\nfn.addPermission('Cdn', {\n principal: new iam.ServicePrincipal('cloudfront.amazonaws.com'),\n sourceArn: `arn:aws:cloudfront::${this.account}:distribution/EDFDVBD6EXAMPLE`,\n});\n```\n\n`addPermission` allows calling every endpoint unless you pass `endpoint`. For other actions, such as letting another account create revisions, use `fn.addToResourcePolicy(statement)`. Statements use the endpoint ARN for invoking and the function ARN for actions on the function.\n\n- **Each stack writes only its own statements.** A Web Function has a single resource policy, and Web Functions have no `AddPermission`. So each stack that adds statements gets a custom resource (`Custom::LambdaWebResourcePolicyStatements`). It reads the policy, replaces the statements that stack wrote before, and writes the policy back, retrying if another writer changed it in the meantime. Statements from other stacks, and ones added outside CloudFormation, are kept. Writers include the function's stack, a stack with a CloudFront distribution, and a stack that imports the function in the same account.\n- **Sids are unique in the policy.** `addPermission`'s `id` becomes the statement's `Sid`, and other statements get a generated one (`Cdk<hash><n>`). If another stack or tool already uses that `Sid` for different content, the deployment fails with the `Sid`.\n- **Don't also attach an `AWS::Lambda::ResourcePolicy` yourself.** That resource replaces the whole document on every update, dropping every other writer's statements.\n- **Public policies are rejected.** Lambda refuses a policy that lets anyone call the function, and the construct fails synthesis first. A `*` principal is only accepted with a condition that pins the caller, such as `aws:PrincipalOrgID` (`iam.OrganizationPrincipal`) or `aws:SourceAccount`. For a public endpoint, use `authType: NONE`.\n- **Scope AWS services to your resource.** Lambda accepts a service principal with no condition, which would let that service call the endpoint on behalf of any account. The construct warns unless you give `sourceArn` or `sourceAccount` (or an `aws:SourceArn`, `aws:SourceAccount`, `aws:SourceOrgID` or `aws:SourceOrgPaths` condition).\n- Lambda copies the policy to every region the function's endpoints serve from. The copy is eventually consistent, and in tests changes applied in every region within seconds.\n\n### CloudFront\n\nPut a CloudFront distribution (`aws-cdk-lib/aws-cloudfront`) in front of an `AWS_IAM` endpoint to serve the public with a custom domain, caching and AWS WAF. Viewers don't sign anything, and only your distribution may call the endpoint:\n\n```ts\nnew cloudfront.Distribution(this, 'Cdn', {\n defaultBehavior: {\n origin: WebFunctionOrigin.withOriginAccessControl(fn.endpoint),\n viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,\n allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,\n cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,\n originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,\n },\n});\n```\n\n`withOriginAccessControl` adds:\n- an origin access control (origin type `lambda`, signing behavior `always-amz-auth`, the only one CloudFront accepts for Web Function origins), one per stack and signing protocol: SigV4 for a regional domain, SigV4a for a `MULTI_REGION` endpoint's global domain;\n- a statement in the function's resource policy that allows `cloudfront.amazonaws.com` to call this endpoint on behalf of this distribution only (`aws:SourceArn`).\n\nSome things to know:\n- **Forward everything except `Host`.** The endpoint answers 404 when `Host` is the distribution's domain, so use `ALL_VIEWER_EXCEPT_HOST_HEADER` (not `ALL_VIEWER`), or a policy of your own without `Host`.\n- **Your application can still authenticate viewers.** CloudFront signs in its own headers and passes the viewer's `Authorization` header (a JWT, for example) through unchanged, but only when `Authorization` is in the cache policy. CloudFront drops it from `GET` and `HEAD` requests otherwise:\n\n ```ts\n const forwardAuthorization = new cloudfront.CachePolicy(this, 'ForwardAuthorization', {\n headerBehavior: cloudfront.CacheHeaderBehavior.allowList('Authorization'),\n minTtl: Duration.seconds(0),\n defaultTtl: Duration.seconds(0),\n maxTtl: Duration.seconds(1), // a cache key with headers needs caching enabled; 0/0/1 keeps it off in practice\n });\n ```\n- Request bodies work without clients sending `x-amz-content-sha256`: CloudFront signs `POST`, `PUT` and `PATCH` requests with an unsigned payload.\n- A `PER_REGION` endpoint's origin calls one region: the home region, or the one you pass as `region`. Use one origin per region, for example in an origin group.\n- A `MULTI_REGION` endpoint can't include opt-in regions (such as `me-central-1`), because CloudFront can't sign for them. The construct fails synthesis.\n- The distribution can be in another stack, in the function's account. Its stack writes the CloudFront statement into the function's resource policy, so the function's stack doesn't depend on it.\n- That stack can also be in another region, for example us-east-1 for an ACM certificate. CDK then passes the endpoint's domain and ARN with its cross-region references: SSM parameters plus custom resources of its own.\n- **Those references are strong by default.** A change that replaces the endpoint gives it a new domain and ARN. That includes a new endpoint type or region set, or a renamed function. The function's stack can't update a value while the distribution's stack still uses the old one, the same as with `Fn::ImportValue` in one region. Deploy such a change in two steps, or use weak references: CDK's synth warning `@aws-cdk/core:crossStackReferencesDefaultStrong` explains how.\n- Lambda@Edge origin-request and origin-response triggers aren't supported on behaviors with this origin.\n- The endpoint stays reachable at its own domain for signed requests your policies allow. Until a new distribution finishes deploying, requests through it can get a transient 403.\n- `new WebFunctionOrigin(endpoint)` is for a public (`NONE`) endpoint, for example behind AWS WAF. Lambda doesn't authenticate those requests, so the endpoint's own domain stays public too.\n\n### Functions defined elsewhere\n\nImport a Web Function defined in another stack or app to grant access to it, read its metrics, or reference its revisions:\n\n```ts\nconst orders = WebFunction.fromWebFunctionArn(this, 'Orders', 'arn:aws:lambda:us-east-1:111122223333:web-function/orders');\norders.grantInvoke(consumerRole); // every endpoint of the function\n\nconst live = WebFunction.fromWebFunctionAttributes(this, 'Live', {\n webFunctionName: 'orders', // in this stack's account and region\n endpointName: 'live', // grantInvoke allows this endpoint only\n});\nlive.metricConcurrentRequests().createAlarm(this, 'Busy', { threshold: 60, evaluationPeriods: 3 });\n```\n\nAn imported function's metrics default to its own region. Its endpoints, revisions and log groups stay with the stack that defines it.\n\nAn imported function works like a `WebFunction` here. `grantInvoke` and `addToResourcePolicy` write the importing stack's statements into the function's resource policy, in the function's region. This works only when the function is in the stack's account. For a function in another account, `grantInvoke` adds to the caller's IAM policy only, and `addToResourcePolicy` adds nothing and warns, so ask that account to allow the caller.\n\n## Configuration\n\n```ts\nconst api = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('build'),\n authType: WebFunctionAuthType.AWS_IAM,\n entrypoint: 'server.js', // default index.js\n webFunctionName: 'orders-api', // default: generated from the construct path\n description: 'Orders HTTP API',\n environment: { TABLE_NAME: table.tableName },\n timeout: Duration.seconds(60), // per request: 3 seconds to 15 minutes, default 30 seconds\n maxConcurrencyPerEnvironment: 32, // requests per environment at once: 1-128, default 64\n});\n\napi.addEnvironment('FEATURE_FLAG', 'on');\ntable.grantReadWriteData(api); // the default role trusts lambda.amazonaws.com\n```\n\n- **Each execution environment has 2 vCPUs and 2 GB of memory.** There's no memory setting as on Lambda functions; scale with `maxConcurrencyPerEnvironment` and more environments instead.\n- Requests handled by one environment share module-level state, so keep handlers concurrency-safe.\n- Environment variable names starting with `AWS_` are reserved.\n- **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.\n- **Renaming the function replaces it and changes its URL.** A generated name depends on the construct path, so moving the construct renames it too.\n\n### Encryption\n\nLambda encrypts each revision's code and environment variables with an AWS owned key. To use your own key, pass `encryptionKey`:\n\n```ts\ndeclare const keyStack: Stack; // deploys first\ndeclare const replicaStack: Stack; // in us-east-1, deploys before this stack\n\nconst key = new kms.Key(keyStack, 'Key', { multiRegion: true });\nconst api = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('build'),\n authType: WebFunctionAuthType.AWS_IAM,\n endpoint: { endpointType: WebFunctionEndpointType.PER_REGION, regions: ['us-east-1'] },\n encryptionKey: key,\n});\n\n// One replica per region the endpoint serves from, with Lambda's statement in its own policy.\nnew kms.CfnReplicaKey(replicaStack, 'KeyReplica', {\n primaryKeyArn: key.keyArn,\n keyPolicy: new iam.PolicyDocument({\n statements: [\n new iam.PolicyStatement({ principals: [new iam.AccountRootPrincipal()], actions: ['kms:*'], resources: ['*'] }),\n api.encryptionKeyPolicyStatement(),\n ],\n }),\n});\n```\n\n- **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.\n- **`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-`.\n- **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.\n- **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.\n- **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.\n\n### Defaults for every function (property injection)\n\nTo 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:\n\n```ts\nclass TeamDefaults implements IPropertyInjector {\n public readonly constructUniqueId = WebFunction.PROPERTY_INJECTION_ID;\n public inject(originalProps: WebFunctionProps): WebFunctionProps {\n // The team's defaults, with explicit props winning.\n return Object.assign({ logRetention: logs.RetentionDays.ONE_MONTH }, originalProps);\n }\n}\nPropertyInjectors.of(this).add(new TeamDefaults()); // or on the app, for every stack\n```\n\n- An injector applies to functions created under the scope it's added to. The nearest one wins.\n- `NodejsWebFunction` has its own ID (`NodejsWebFunction.PROPERTY_INJECTION_ID`). Its injector runs first, then `WebFunction`'s, as with aws-cdk-lib's `NodejsFunction` and `Function`.\n\n### Bundling TypeScript with `NodejsWebFunction`\n\n`NodejsWebFunction` is a `WebFunction` that bundles your server from a TypeScript or JavaScript entry file with esbuild, like `NodejsFunction` does for Lambda functions:\n\n```ts\nnew NodejsWebFunction(this, 'Api', {\n entry: 'src/server.ts',\n authType: WebFunctionAuthType.AWS_IAM,\n bundling: {\n minify: true, // default true\n sourceMap: true, // default true\n format: lambdaNodejs.OutputFormat.ESM, // default ESM (index.mjs); CJS gives index.js\n externalModules: [], // default: bundle everything you import\n },\n});\n```\n\n- **Defaults:** `runtime` is `NODEJS_24_X`, and the esbuild target follows the runtime (`node24`). The project root is the directory of the nearest lock file above `entry` (override it with `depsLockFilePath` or `projectRoot`).\n- **It also sets what a `lambda.Code` can't:** the entry point that matches the bundle, and `NODE_OPTIONS=--enable-source-maps` when source maps are on, appended to any `NODE_OPTIONS` you set, so stack traces point at your `.ts` files (e.g. `/var/task/src/server.ts:22:12`). Source map paths are relative to the project root, so no build-machine paths are deployed.\n- **ESM bundles include a `require` shim**, so CommonJS dependencies that load Node.js built-ins (Express, for example) work.\n- **The AWS SDK is bundled like any other dependency**, since the runtime has none. Only the clients you import are included.\n- **Bundling runs locally** when esbuild is installed in your project, and otherwise in Docker (an arm64 AWS SAM build image; set `forceDockerBundling` to always use Docker).\n- **Not yet supported:** installing native modules next to the bundle (`nodeModules`) and command hooks. For native dependencies, use `WebFunction` with `Code.fromAsset(..., { bundling: { image, command } })`.\n\n### Code\n\n`code` takes any `lambda.Code` that produces a zip in S3: `fromAsset`, `fromBucket`/`fromBucketV2`, `fromCustomCommand`, `fromDockerBuild`. Inline code and container images fail at synth time.\n\nLambda Web Functions download code as the `lambda.amazonaws.com` service principal, from a **versioned** bucket, and the CDK bootstrap bucket allows neither. So each stack gets a small code bucket, and the code is copied into it on deploy. The bucket is emptied and deleted with the stack.\n\nCopying code, managing the function's log groups in every region, looking up regional URLs, cleaning up old revisions, creating rollback alarms in other regions and emptying the code bucket all run in one custom resource Lambda per stack. Its logs go to a log group the stack owns, kept for a month and deleted with the stack.\n\n## Revisions\n\nAny change to code or configuration creates a new **revision** (`fn.currentRevision`), and endpoints switch to it once it's ready. A failed deployment rolls back to the previous revision. If nothing changed, nothing is deployed.\n\nEarlier revisions are kept, so you can roll back or route traffic to them. After each deployment, the construct deletes the oldest beyond `revisionRetention` (default 20, up to 50). It never deletes a revision an endpoint routes to, or one the previous deployment used, which a rollback returns to.\n\n```ts\nnew WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.AWS_IAM,\n revisionRetention: 5,\n});\n```\n\n### Routing to earlier revisions\n\nReference an earlier revision by its ID (for example from a `CfnOutput` of `fn.currentRevision.revisionId`, or `aws lambda-web list-web-function-revisions`). Then pin an endpoint to it, or split traffic between two revisions:\n\n```ts\nconst previous = WebFunctionRevision.fromRevisionAttributes(this, 'Previous', {\n webFunction: fn,\n revisionId: 'rev-a1b2c',\n});\n\n// Keep the default endpoint on the previous revision, and send 10% to the new one:\nfn.endpoint.routeTraffic(previous, [{ revision: fn.currentRevision, weight: 0.1 }]);\n\n// Or a second endpoint that stays on the previous revision while fn.endpoint moves on:\nfn.addEndpoint('Stable', { authType: WebFunctionAuthType.AWS_IAM, revision: previous });\n```\n\n- An endpoint routes to at most two revisions. The additional revision's `weight` is a whole percentage, from 0.01 to 0.99.\n- To promote, remove `routeTraffic` (or `revision`) and deploy: the endpoint serves the current revision again.\n- Lambda Web Function metrics have no revision dimension. To compare a split's revisions, log a version you control (for example an environment variable) from your application.\n\n### Canary and linear deployments\n\nBy default an endpoint moves all its traffic to a new revision at once. With `deployment`, it moves in steps instead, watching CloudWatch alarms: if one goes into ALARM, the endpoint goes back to the revision it served before and the deployment fails, so CloudFormation rolls the stack back.\n\n```ts\nconst api = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.AWS_IAM,\n endpoint: {\n // 10% of the traffic for 10 minutes, then all of it; back if more than 2% of requests get a 5XX.\n deployment: WebFunctionDeployment.canary({ percent: 10, bake: Duration.minutes(10), rollbackOn: { serverErrorRate: 2 } }),\n },\n});\n\n// 25% more every 5 minutes, watching an alarm of your own. Each endpoint has its own deployment.\n// errorRate: any cloudwatch.IAlarm, e.g. on a metric your application publishes.\napi.addEndpoint('Public', {\n authType: WebFunctionAuthType.NONE,\n deployment: WebFunctionDeployment.linear({ percent: 25, interval: Duration.minutes(5), alarms: [errorRate] }),\n});\n```\n\n| | Steps | Limits |\n|---|---|---|\n| `allAtOnce()` (default) | 100% | |\n| `canary({ percent, bake })` | `percent`, then 100% after `bake` | `percent` 1–99, `bake` 1–45 minutes |\n| `linear({ percent, interval })` | `percent` more every `interval` | `percent` 5–50, `interval` from 1 minute, at most 45 minutes in all |\n\nHow it works:\n\n- Each deployment that creates a revision (code or configuration) moves the traffic from the revision the endpoint serves at that moment, which is also what it goes back to. If someone switched the endpoint outside CloudFormation, the deployment starts from there.\n- Each step waits until every region of a `MULTI_REGION` or `PER_REGION` endpoint has applied it (usually about 15 seconds), and if a region fails to update, the endpoint goes back as for an alarm. The bake or interval counts from the start of the step.\n- Alarms are checked before the first step (an alarm already in ALARM stops the deployment before any traffic moves), throughout every step, and once the new revision has all the traffic. They can be in any region, and composite alarms work. `INSUFFICIENT_DATA` doesn't stop a deployment.\n- A rollback of the stack, for any reason, moves the traffic back at once, without waiting or checking alarms.\n- A stack's first deployment, and a new endpoint (including one renamed by a region change), serve the revision at once: there's nothing to move from.\n- A deployment can take up to an hour: CloudFormation waits for it before it updates the endpoint. Deployments of different endpoints run in parallel.\n- A canary or linear endpoint always moves to the current revision, so it can't also use `revision`, `additionalRevisions` or `routeTraffic()`. Use `allAtOnce()` to deploy a fix immediately, for example while an alarm is in ALARM.\n\n#### Rollback alarms\n\n`rollbackOn` makes the endpoint create alarms on its own error rates, and the deployment watches them alongside any `alarms` you pass:\n\n| `rollbackOn` | Default | |\n|---|---|---|\n| `serverErrorRate` | none | roll back when more than this % of requests get a 5XX |\n| `clientErrorRate` | none | the same for 4XX (including 429s from `rateLimit` and `maxEnvironments`) |\n| `minimumRequests` | 10 | periods with fewer requests don't count, so one failed request out of two doesn't roll back |\n| `period`, `evaluationPeriods` | 1 minute, 2 | consecutive periods over the threshold before rolling back |\n\n- **One alarm per threshold in every region the endpoint serves from.** Metrics are published in the region that served the request, and an alarm can only watch metrics in its own region. The home region's alarm is a normal CloudFormation alarm; the others are created and deleted with the endpoint by a custom resource, and named `LambdaWeb-<function>-<endpoint>-5xx-rate` (or `-4xx-rate`). `endpoint.rollbackAlarms` lists them all, e.g. to add notifications to the home region's.\n- **The alarms see the whole endpoint.** Lambda Web Function metrics have no revision dimension, so at 10% a new revision's errors are about a tenth of the endpoint's: set the threshold low enough to notice that, or alarm on metrics your application publishes with its version.\n- **5XX includes the platform's 503s** while the endpoint scales up for a sudden burst, not only your application's errors.\n- **A step should outlast the alarm.** CloudWatch needs `period` × `evaluationPeriods`, plus a couple of minutes of delay, to fire; the construct warns when a canary's bake or a linear interval is shorter.\n\nThe deployment runs in a few resources per stack, created on first use: two Lambda functions, a Step Functions state machine that calls them every 15 seconds, and a log group.\n\n## Metrics\n\nEndpoints and functions have helpers for their CloudWatch metrics (namespace `AWS/Lambda/Web`), like `lambda.Function`'s:\n\n```ts\nfn.endpoint.metricServerErrorRate().createAlarm(this, 'ErrorRate', { threshold: 1, evaluationPeriods: 3 });\nfn.endpoint.metricRequestThrottles().createAlarm(this, 'Throttled', { threshold: 10, evaluationPeriods: 3 });\nfn.metricConcurrentRequests().createAlarm(this, 'Saturated', { threshold: 60, evaluationPeriods: 3 });\n```\n\n| Endpoint | Metric |\n|---|---|\n| `metricRequests()` | `ExecutedRequests` (there's no separate 2XX count) |\n| `metricClientErrors()`, `metricServerErrors()` | `HTTPResponseStatusClass4XX`, `HTTPResponseStatusClass5XX` |\n| `metricClientErrorRate()`, `metricServerErrorRate()` | 4XX or 5XX as a % of requests (math expression) |\n| `metricActiveEnvironments()` | `EndpointActiveEnvironments`, to compare with `maxEnvironments` |\n| `metricRequestThrottles()`, `metricEnvironmentThrottles()` | 429s from `rateLimit` and from `maxEnvironments` |\n\n| Function | Metric |\n|---|---|\n| `metricConcurrentRequests()` | `EnvironmentConcurrentRequests` (maximum), to compare with `maxConcurrencyPerEnvironment` |\n| `metricMaxMemoryUsage()` | `EnvironmentMaxMemoryUsage` (maximum) |\n| `metricActiveTime()`, `metricCpuTime()`, `metricResponseBytes()` | `EnvironmentActiveTime`, `EnvironmentCPUTime`, `ResponseBytes` |\n\n- **Metrics stay in the region that served the request**; unlike logs, they aren't copied to the home region. Every helper takes `region`. Dashboards can show any region, but an alarm can only use metrics from its own stack's region.\n- 4XX, 5XX and the throttle metrics only exist once they're non-zero: alarm on them with `treatMissingData: NOT_BREACHING`. The rate helpers count missing errors as 0.\n- There's no latency metric. Publish one from your application (e.g. with the CloudWatch embedded metric format).\n\n## Logs in every region\n\nWeb Functions log in two tiers:\n\n```text\n every serving region home region\n ┌──────────────────┐ ┌──────────────────────────────────────────┐\n │ <group>.local │── copied ───►│ <group> every region's logs │\n │ (that region's │ (seconds) │ streams …[rev]<instance>-<acct>-<region> │\n │ environments) │ │ <group>.local (home-region traffic) │\n └──────────────────┘ └──────────────────────────────────────────┘\n```\n\n**Query `fn.logGroup`**, the home-region group that receives every region's logs. The service would create missing groups without retention and never delete them, so the construct creates and owns all of them: both home-region groups, and `<group>.local` in every other region any of its endpoints serves from.\n\n```ts\nnew WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.AWS_IAM,\n logRetention: logs.RetentionDays.THREE_MONTHS, // default ONE_MONTH, every group in every region\n logRemovalPolicy: RemovalPolicy.DESTROY, // default RETAIN\n applicationLogLevelV2: lambda.ApplicationLogLevel.WARN,\n systemLogLevelV2: lambda.SystemLogLevel.INFO, // DEBUG, INFO or WARN\n});\n```\n\n- The default group is `/aws/lambda/web/<function name>`. Log lines are JSON; application lines carry `requestId`, `endpointName` and `region`.\n- Every event is stored twice (`.local` plus the home-region copy), so expect about double log ingestion, plus cross-region transfer.\n- With `DESTROY`, deletion waits about a minute after the function is gone, because environments flush their last lines late.\n- Subscribe only to `fn.logGroup`: subscribing to the `.local` groups as well delivers every event twice.\n\n## cdk-nag\n\nThe library acknowledges the [cdk-nag](https://github.com/cdklabs/cdk-nag) AwsSolutions findings on the resources it creates, each with a reason, so they don't show up in your reports:\n\n| Finding | Resource | Reason |\n|---|---|---|\n| IAM5 (wildcards) | the default execution role | log streams of the function's own log groups, in every region it serves from |\n| IAM5 | the deployment handlers' role (canary and linear deployments) | their own log group, `cloudwatch:DescribeAlarms` (composite alarms need `*`), and the revisions and endpoints of the functions they deploy |\n| IAM4, IAM5, SF1, SF2 | the CDK Provider framework behind deployments | CDK's own functions and waiter state machine |\n| S1 (access logs) | the stack's code bucket | it only holds copies of the stack's code assets |\n\n- **This works with both cdk-nag versions**, without depending on cdk-nag. cdk-nag 3 reads CDK's `Validations.of(...).acknowledge()`, one ID per finding. cdk-nag 2 reads `cdk_nag` metadata in the template.\n- **Your own statements and resources are still checked.** That includes statements you add to the function's role (`addToRolePolicy`, grants) and your CloudFront distribution's settings.\n- Only the AwsSolutions pack is covered; findings from the HIPAA, NIST and PCI packs aren't acknowledged.\n\n## Upgrading\n\n### From 0.1.5 to 0.1.7, with a resource policy\n\nVersions 0.1.5 to 0.1.7 wrote the function's resource policy with an `AWS::Lambda::ResourcePolicy`. Later versions don't (0.1.7 has the same code as 0.1.6). When an update removes that resource, CloudFormation deletes the function's **whole** resource policy at the end of the update, including the statements the new version just wrote. Callers that rely on the policy then get 403: other accounts, AWS services, and CloudFront.\n\nIf your function has a resource policy (from `addPermission`, a grant to another account or an AWS service, or `WebFunctionOrigin`), first deploy once on the version you have, with the old resource retained:\n\n```ts\n(fn.node.findChild('ResourcePolicy') as CfnResource).applyRemovalPolicy(RemovalPolicy.RETAIN);\n```\n\nThen upgrade, without changing your statements in the same deployment. The new version takes over the statements it writes itself. A statement you removed in the same deployment would stay in the policy.\n\n## Limitations\n\n- Not yet supported: VPC access (network connectors), KMS encryption, and tracing.\n- **Hotswap skips Web Functions without a warning.** `cdk deploy --hotswap` and `cdk watch`, which hotswaps by default, report `(no changes)` for a code or configuration change and the endpoint keeps serving the old revision. Use `cdk watch --hotswap-fallback` (or `cdk deploy --hotswap-fallback`): it deploys Web Function changes through CloudFormation, in about 40 seconds for a home-region endpoint.\n- Fixed limits: 512 MB of code (unzipped) and 32 KB of environment variables per revision, 512 MB of `/tmp` per execution environment, and 128 KiB of headers per request.\n- Quotas: 10 endpoints and about 50 revisions per function (Lambda cleans up older revisions automatically), and 10,000 requests per second per endpoint. Per account and region: 100,000 requests per second and 2,000 Arm64 vCPUs (each execution environment uses 2). The account quotas are adjustable, and new accounts start lower. See [Lambda quotas](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html).\n\n## Development\n\nTooling is pinned in `mise.toml` (Node 24, AWS CDK CLI). Personal settings, such as the AWS profile for the live end-to-end tests, go in a git-ignored `mise.local.toml`.\n\n```bash\nmise install\nnpx projen build # compile, unit tests, lint, API docs\nnpx projen e2e # deploy, verify and destroy real stacks in three regions (needs AWS credentials)\n```\n"
|
|
9748
|
+
"markdown": "# CDK constructs for AWS Lambda Web Functions\n\n<!--BEGIN STABILITY BANNER-->\n\n---\n\n\n\n> The APIs of higher level constructs in this module are experimental and under active development.\n> They are subject to non-backward compatible changes or removal in any future version. These are\n> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be\n> announced in the release notes. This means that while you may use them, you may need to update\n> your source code when upgrading to a newer version of this package.\n\n---\n\n<!--END STABILITY BANNER-->\n\n[AWS Lambda Web Functions](https://docs.aws.amazon.com/lambda/latest/dg/web-functions.html) run an ordinary Node.js HTTP server (Express, Fastify, Hono, `node:http`) on Lambda and give it an HTTPS endpoint, optionally served from several regions. `WebFunction` deploys one, following the conventions of `aws-cdk-lib/aws-lambda` where the two services overlap.\n\n```ts fixture=bare\nimport * as lambda from 'aws-cdk-lib/aws-lambda';\nimport { WebFunction, WebFunctionAuthType, WebFunctionEndpointType } from '@ashishpandeyone/cdk-lambda-web-function';\n\nconst fn = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.AWS_IAM,\n endpoint: {\n endpointType: WebFunctionEndpointType.MULTI_REGION,\n regions: ['us-east-1', 'eu-west-1'],\n },\n});\n\nnew CfnOutput(this, 'Url', { value: fn.endpoint.url }); // https://<id>.lambda-web.global.on.aws\n```\n\nThe stack's region is the function's **home region**. Multi-region endpoints need a stack with an explicit `env.region`.\n\n## Installation\n\n```bash\nnpm install @ashishpandeyone/cdk-lambda-web-function\n```\n\nIt needs `aws-cdk-lib` 2.273.0 or later and `constructs` 10.5.1 or later (peer dependencies), and Node.js 22 or later. The package is published for TypeScript and JavaScript only.\n\n## Writing the server\n\n1. Listen on the host and port in **`AWS_LAMBDA_HTTP_ENDPOINT`** (`0.0.0.0:3000` today). `PORT` is not set.\n2. Start listening within **10 seconds**, or initialisation fails with `Application.TimeoutListenError`.\n3. Put the entry file at the root of your bundle as **`index.js`**, or set `entrypoint`.\n4. The runtime has **no AWS SDK**: bundle the clients you import.\n5. Code runs on **arm64**.\n\n```js\nconst express = require('express');\n\nconst app = express();\napp.get('/', (req, res) => res.json({ hello: 'world', region: process.env.AWS_REGION }));\n\nconst [host, port] = process.env.AWS_LAMBDA_HTTP_ENDPOINT.split(':');\napp.listen(Number(port), host);\n```\n\nRequests carry `lambda-web-request-id` and `lambda-web-endpoint-name` headers.\n\n## Regions and endpoints\n\nEach `WebFunction` has a default endpoint, `fn.endpoint`, configured with the `endpoint` property. [Add more](#more-endpoints) with `fn.addEndpoint()`.\n\n| `endpointType` | URL | Routing |\n|---|---|---|\n| `HOME_REGION` (default) | `https://<id>.<cell>.lambda-web.<home>.on.aws` | home region only |\n| `MULTI_REGION` | one global `https://<id>.lambda-web.global.on.aws` | nearest region |\n| `PER_REGION` | one URL per region, from `fn.endpoint.regionalUrl(region)` | the region in the hostname |\n\n```ts\nconst perRegion = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.AWS_IAM,\n endpoint: {\n endpointType: WebFunctionEndpointType.PER_REGION,\n regions: ['us-east-1', 'eu-west-1'],\n },\n});\n\nnew CfnOutput(this, 'UsEast1Url', { value: perRegion.endpoint.regionalUrl('us-east-1') });\n// perRegion.endpoint.regions is ['<home region>', 'eu-west-1', 'us-east-1']\n```\n\n- `MULTI_REGION` and `PER_REGION` need at least one region besides the home region; `HOME_REGION` takes none.\n- A MultiRegion endpoint takes about a minute to create.\n- Lambda routes a `MULTI_REGION` endpoint by latency, not by health: it doesn't fail over when a region has problems.\n\n### More endpoints\n\nA function can have up to 10 endpoints, each with its own URL, authentication, regions and limits. For example, a public endpoint next to an IAM-only global one:\n\n```ts\nconst api = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.NONE, // the default endpoint is public\n endpoint: { rateLimit: 1000 }, // requests per second\n});\n\nconst internal = api.addEndpoint('Internal', {\n authType: WebFunctionAuthType.AWS_IAM,\n endpointType: WebFunctionEndpointType.MULTI_REGION,\n regions: ['us-east-1', 'eu-west-1'],\n description: 'Service-to-service traffic',\n maxEnvironments: 50,\n});\ninternal.grantInvoke(consumerRole);\nnew CfnOutput(this, 'InternalUrl', { value: internal.url });\n```\n\n- `rateLimit` takes 0 (blocks all traffic), 100–1,000 in steps of 100, or 2,000–10,000 in steps of 1,000; excess requests get HTTP 429. `maxEnvironments` takes 2–10,000.\n- **Both limits apply separately in each region** an endpoint serves from: a 3-region endpoint with `rateLimit: 1000` accepts up to 1,000 requests per second in each region.\n- Endpoints can serve the same regions. The construct owns one `.local` log group per region, whichever endpoints serve it.\n\n### Changing regions or the endpoint type\n\nAn endpoint's type and regions can't change in place: a change creates a **new endpoint with a new URL**, and the old one is deleted once the new one is live. Two endpoints of one function can't share a name, so:\n\n| `endpointName` | Physical name | Changing `regions` or `endpointType` |\n|---|---|---|\n| omitted (recommended) | `default-<hash>` for `fn.endpoint`, `<id>-<hash>` for added endpoints; the hash covers the type and regions | works: new endpoint, new URL |\n| set, e.g. `'live'` | `live` | also change the name in the same deployment, or it fails with *The endpoint live already exists* (the stack rolls back and the old endpoint keeps serving) |\n\nThe construct warns at synth time when `endpointName` is set.\n\n## Authentication and invoking\n\n| `authType` | Meaning |\n|---|---|\n| `AWS_IAM` | Callers sign requests (SigV4 or SigV4a, signing name `lambda`) and need `lambda:InvokeWebFunctionEndpoint` |\n| `NONE` | **Public**: Lambda does no authentication; your application does (JWT, sessions). The `Authorization` header reaches your application untouched. The construct warns at synth time |\n\n```ts\nfn.grants.invoke(consumerRole); // or fn.grantInvoke(consumerRole), as on lambda.Function\n```\n\nThe grant is on the endpoint's home-region ARN, which IAM evaluates in every region the endpoint serves from, including the global URL. `fn.grants` covers the default endpoint only; grant other endpoints with their own `grantInvoke()` or `grants.invoke()`.\n\n| Endpoint | How to sign |\n|---|---|\n| `HOME_REGION` | SigV4 for the home region |\n| `PER_REGION` | SigV4 for the hostname's region, or SigV4a |\n| `MULTI_REGION` | **SigV4a with region set `*`**: you can't know which region will serve the request |\n\n```js\nimport { SignatureV4a } from '@smithy/signature-v4a';\nimport { Sha256 } from '@aws-crypto/sha256-js';\nimport { fromNodeProviderChain } from '@aws-sdk/credential-providers';\n\nconst host = new URL(url).hostname; // url: the endpoint's URL\nconst signer = new SignatureV4a({ service: 'lambda', region: '*', sha256: Sha256, credentials: fromNodeProviderChain() });\nconst signed = await signer.sign(\n { method: 'GET', protocol: 'https:', hostname: host, path: '/', headers: { host } },\n { signingRegion: '*' },\n);\nconst response = await fetch(`https://${host}/`, { headers: signed.headers });\n```\n\n### Other accounts and AWS services\n\nA caller in another account needs permission twice: in its own IAM policy, and in the function's **resource policy**. `grantInvoke` handles the function's side: a role in the function's account only gets an IAM policy statement, while a principal in another account or an AWS service also gets a statement in the resource policy.\n\n```ts\nfn.grantInvoke(iam.Role.fromRoleArn(this, 'Partner', 'arn:aws:iam::444455556666:role/caller'));\n```\n\nFor principals you can't grant to (a whole account, an organization, an AWS service with conditions), use `addPermission`. The `id` becomes the statement's `Sid`:\n\n```ts\nfn.addPermission('PartnerAccount', { principal: new iam.AccountPrincipal('444455556666') });\nfn.addPermission('MyOrg', { principal: new iam.OrganizationPrincipal('o-a1b2c3d4e5'), endpoint: fn.endpoint });\nfn.addPermission('Cdn', {\n principal: new iam.ServicePrincipal('cloudfront.amazonaws.com'),\n sourceArn: `arn:aws:cloudfront::${this.account}:distribution/EDFDVBD6EXAMPLE`,\n});\n```\n\n`addPermission` allows calling every endpoint unless you pass `endpoint`. For other actions, such as letting another account create revisions, use `fn.addToResourcePolicy(statement)`. Statements use the endpoint ARN for invoking and the function ARN for actions on the function.\n\n- **Each stack writes only its own statements.** A Web Function has a single resource policy, and Web Functions have no `AddPermission`. So each stack that adds statements gets a custom resource (`Custom::LambdaWebResourcePolicyStatements`). It reads the policy, replaces the statements that stack wrote before, and writes the policy back, retrying if another writer changed it in the meantime. Statements from other stacks, and ones added outside CloudFormation, are kept. Writers include the function's stack, a stack with a CloudFront distribution, and a stack that imports the function in the same account.\n- **Sids are unique in the policy.** `addPermission`'s `id` becomes the statement's `Sid`, and other statements get a generated one (`Cdk<hash><n>`). If another stack or tool already uses that `Sid` for different content, the deployment fails with the `Sid`.\n- **Don't also attach an `AWS::Lambda::ResourcePolicy` yourself.** That resource replaces the whole document on every update, dropping every other writer's statements.\n- **Public policies are rejected.** Lambda refuses a policy that lets anyone call the function, and the construct fails synthesis first. A `*` principal is only accepted with a condition that pins the caller, such as `aws:PrincipalOrgID` (`iam.OrganizationPrincipal`) or `aws:SourceAccount`. For a public endpoint, use `authType: NONE`.\n- **Scope AWS services to your resource.** Lambda accepts a service principal with no condition, which would let that service call the endpoint on behalf of any account. The construct warns unless you give `sourceArn` or `sourceAccount` (or an `aws:SourceArn`, `aws:SourceAccount`, `aws:SourceOrgID` or `aws:SourceOrgPaths` condition).\n- Lambda copies the policy to every region the function's endpoints serve from. The copy is eventually consistent, and in tests changes applied in every region within seconds.\n\n### CloudFront\n\nPut a CloudFront distribution (`aws-cdk-lib/aws-cloudfront`) in front of an `AWS_IAM` endpoint to serve the public with a custom domain, caching and AWS WAF. Viewers don't sign anything, and only your distribution may call the endpoint:\n\n```ts\nnew cloudfront.Distribution(this, 'Cdn', {\n defaultBehavior: {\n origin: WebFunctionOrigin.withOriginAccessControl(fn.endpoint),\n viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,\n allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,\n cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,\n originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,\n },\n});\n```\n\n`withOriginAccessControl` adds:\n- an origin access control (origin type `lambda`, signing behavior `always-amz-auth`, the only one CloudFront accepts for Web Function origins), one per stack and signing protocol: SigV4 for a regional domain, SigV4a for a `MULTI_REGION` endpoint's global domain;\n- a statement in the function's resource policy that allows `cloudfront.amazonaws.com` to call this endpoint on behalf of this distribution only (`aws:SourceArn`).\n\nSome things to know:\n- **Forward everything except `Host`.** The endpoint answers 404 when `Host` is the distribution's domain, so use `ALL_VIEWER_EXCEPT_HOST_HEADER` (not `ALL_VIEWER`), or a policy of your own without `Host`.\n- **Your application can still authenticate viewers.** CloudFront signs in its own headers and passes the viewer's `Authorization` header (a JWT, for example) through unchanged, but only when `Authorization` is in the cache policy. CloudFront drops it from `GET` and `HEAD` requests otherwise:\n\n ```ts\n const forwardAuthorization = new cloudfront.CachePolicy(this, 'ForwardAuthorization', {\n headerBehavior: cloudfront.CacheHeaderBehavior.allowList('Authorization'),\n minTtl: Duration.seconds(0),\n defaultTtl: Duration.seconds(0),\n maxTtl: Duration.seconds(1), // a cache key with headers needs caching enabled; 0/0/1 keeps it off in practice\n });\n ```\n- Request bodies work without clients sending `x-amz-content-sha256`: CloudFront signs `POST`, `PUT` and `PATCH` requests with an unsigned payload.\n- A `PER_REGION` endpoint's origin calls one region: the home region, or the one you pass as `region`. Use one origin per region, for example in an origin group.\n- A `MULTI_REGION` endpoint can't include opt-in regions (such as `me-central-1`), because CloudFront can't sign for them. The construct fails synthesis.\n- The distribution can be in another stack, in the function's account. Its stack writes the CloudFront statement into the function's resource policy, so the function's stack doesn't depend on it.\n- That stack can also be in another region, for example us-east-1 for an ACM certificate. CDK then passes the endpoint's domain and ARN with its cross-region references: SSM parameters plus custom resources of its own.\n- **Those references are strong by default.** A change that replaces the endpoint gives it a new domain and ARN. That includes a new endpoint type or region set, or a renamed function. The function's stack can't update a value while the distribution's stack still uses the old one, the same as with `Fn::ImportValue` in one region. Deploy such a change in two steps, or use weak references: CDK's synth warning `@aws-cdk/core:crossStackReferencesDefaultStrong` explains how.\n- Lambda@Edge origin-request and origin-response triggers aren't supported on behaviors with this origin.\n- The endpoint stays reachable at its own domain for signed requests your policies allow. Until a new distribution finishes deploying, requests through it can get a transient 403.\n- `new WebFunctionOrigin(endpoint)` is for a public (`NONE`) endpoint, for example behind AWS WAF. Lambda doesn't authenticate those requests, so the endpoint's own domain stays public too.\n\n### Functions defined elsewhere\n\nImport a Web Function defined in another stack or app to grant access to it, read its metrics, or reference its revisions:\n\n```ts\nconst orders = WebFunction.fromWebFunctionArn(this, 'Orders', 'arn:aws:lambda:us-east-1:111122223333:web-function/orders');\norders.grantInvoke(consumerRole); // every endpoint of the function\n\nconst live = WebFunction.fromWebFunctionAttributes(this, 'Live', {\n webFunctionName: 'orders', // in this stack's account and region\n endpointName: 'live', // grantInvoke allows this endpoint only\n});\nlive.metricConcurrentRequests().createAlarm(this, 'Busy', { threshold: 60, evaluationPeriods: 3 });\n```\n\nAn imported function's metrics default to its own region. Its endpoints, revisions and log groups stay with the stack that defines it.\n\nAn imported function works like a `WebFunction` here. `grantInvoke` and `addToResourcePolicy` write the importing stack's statements into the function's resource policy, in the function's region. This works only when the function is in the stack's account. For a function in another account, `grantInvoke` adds to the caller's IAM policy only, and `addToResourcePolicy` adds nothing and warns, so ask that account to allow the caller.\n\n## Configuration\n\n```ts\nconst api = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('build'),\n authType: WebFunctionAuthType.AWS_IAM,\n entrypoint: 'server.js', // default index.js\n webFunctionName: 'orders-api', // default: generated from the construct path\n description: 'Orders HTTP API',\n environment: { TABLE_NAME: table.tableName },\n timeout: Duration.seconds(60), // per request: 3 seconds to 15 minutes, default 30 seconds\n maxConcurrencyPerEnvironment: 32, // requests per environment at once: 1-128, default 64\n});\n\napi.addEnvironment('FEATURE_FLAG', 'on');\ntable.grantReadWriteData(api); // the default role trusts lambda.amazonaws.com\n```\n\n- **Each execution environment has 2 vCPUs and 2 GB of memory.** There's no memory setting as on Lambda functions; scale with `maxConcurrencyPerEnvironment` and more environments instead.\n- Requests handled by one environment share module-level state, so keep handlers concurrency-safe.\n- Environment variable names starting with `AWS_` are reserved.\n- **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.\n- **Renaming the function replaces it and changes its URL.** A generated name depends on the construct path, so moving the construct renames it too.\n\n### Encryption\n\nLambda encrypts each revision's code and environment variables with an AWS owned key. To use your own key, pass `encryptionKey`:\n\n```ts\ndeclare const keyStack: Stack; // deploys first\ndeclare const replicaStack: Stack; // in us-east-1, deploys before this stack\n\nconst key = new kms.Key(keyStack, 'Key', { multiRegion: true });\nconst api = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('build'),\n authType: WebFunctionAuthType.AWS_IAM,\n endpoint: { endpointType: WebFunctionEndpointType.PER_REGION, regions: ['us-east-1'] },\n encryptionKey: key,\n});\n\n// One replica per region the endpoint serves from, with Lambda's statement in its own policy.\nnew kms.CfnReplicaKey(replicaStack, 'KeyReplica', {\n primaryKeyArn: key.keyArn,\n keyPolicy: new iam.PolicyDocument({\n statements: [\n new iam.PolicyStatement({ principals: [new iam.AccountRootPrincipal()], actions: ['kms:*'], resources: ['*'] }),\n api.encryptionKeyPolicyStatement(),\n ],\n }),\n});\n```\n\n- **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.\n- **`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-`.\n- **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.\n- **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.\n- **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.\n\nLog groups are encrypted by CloudWatch Logs. To use your own key for them too, pass `logEncryptionKey`. It can be the same key:\n\n```ts\ndeclare const key: kms.Key; // multiRegion: true, in the function's region\ndeclare const replica: kms.CfnReplicaKey; // in us-east-1\n\nconst api = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('build'),\n authType: WebFunctionAuthType.AWS_IAM,\n endpoint: { endpointType: WebFunctionEndpointType.PER_REGION, regions: ['us-east-1'] },\n logEncryptionKey: key,\n});\n\n// The replica's policy also allows CloudWatch Logs in its region, for this function's groups.\nreplica.keyPolicy = new iam.PolicyDocument({\n statements: [\n new iam.PolicyStatement({ principals: [new iam.AccountRootPrincipal()], actions: ['kms:*'], resources: ['*'] }),\n api.logEncryptionKeyPolicyStatement('us-east-1'),\n ],\n});\n```\n\n- **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.\n- **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.\n- **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.\n- **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.\n- **Retained log groups need their key to stay readable.** The default `logRemovalPolicy` is `RETAIN`, so keep the key while you keep the logs.\n\n### Defaults for every function (property injection)\n\nTo 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:\n\n```ts\nclass TeamDefaults implements IPropertyInjector {\n public readonly constructUniqueId = WebFunction.PROPERTY_INJECTION_ID;\n public inject(originalProps: WebFunctionProps): WebFunctionProps {\n // The team's defaults, with explicit props winning.\n return Object.assign({ logRetention: logs.RetentionDays.ONE_MONTH }, originalProps);\n }\n}\nPropertyInjectors.of(this).add(new TeamDefaults()); // or on the app, for every stack\n```\n\n- An injector applies to functions created under the scope it's added to. The nearest one wins.\n- `NodejsWebFunction` has its own ID (`NodejsWebFunction.PROPERTY_INJECTION_ID`). Its injector runs first, then `WebFunction`'s, as with aws-cdk-lib's `NodejsFunction` and `Function`.\n\n### Bundling TypeScript with `NodejsWebFunction`\n\n`NodejsWebFunction` is a `WebFunction` that bundles your server from a TypeScript or JavaScript entry file with esbuild, like `NodejsFunction` does for Lambda functions:\n\n```ts\nnew NodejsWebFunction(this, 'Api', {\n entry: 'src/server.ts',\n authType: WebFunctionAuthType.AWS_IAM,\n bundling: {\n minify: true, // default true\n sourceMap: true, // default true\n format: lambdaNodejs.OutputFormat.ESM, // default ESM (index.mjs); CJS gives index.js\n externalModules: [], // default: bundle everything you import\n },\n});\n```\n\n- **Defaults:** `runtime` is `NODEJS_24_X`, and the esbuild target follows the runtime (`node24`). The project root is the directory of the nearest lock file above `entry` (override it with `depsLockFilePath` or `projectRoot`).\n- **It also sets what a `lambda.Code` can't:** the entry point that matches the bundle, and `NODE_OPTIONS=--enable-source-maps` when source maps are on, appended to any `NODE_OPTIONS` you set, so stack traces point at your `.ts` files (e.g. `/var/task/src/server.ts:22:12`). Source map paths are relative to the project root, so no build-machine paths are deployed.\n- **ESM bundles include a `require` shim**, so CommonJS dependencies that load Node.js built-ins (Express, for example) work.\n- **The AWS SDK is bundled like any other dependency**, since the runtime has none. Only the clients you import are included.\n- **Bundling runs locally** when esbuild is installed in your project, and otherwise in Docker (an arm64 AWS SAM build image; set `forceDockerBundling` to always use Docker).\n- **Not yet supported:** installing native modules next to the bundle (`nodeModules`) and command hooks. For native dependencies, use `WebFunction` with `Code.fromAsset(..., { bundling: { image, command } })`.\n\n### Code\n\n`code` takes any `lambda.Code` that produces a zip in S3: `fromAsset`, `fromBucket`/`fromBucketV2`, `fromCustomCommand`, `fromDockerBuild`. Inline code and container images fail at synth time.\n\nLambda Web Functions download code as the `lambda.amazonaws.com` service principal, from a **versioned** bucket, and the CDK bootstrap bucket allows neither. So each stack gets a small code bucket, and the code is copied into it on deploy. The bucket is emptied and deleted with the stack.\n\nCopying code, managing the function's log groups in every region, looking up regional URLs, cleaning up old revisions, creating rollback alarms in other regions and emptying the code bucket all run in one custom resource Lambda per stack. Its logs go to a log group the stack owns, kept for a month and deleted with the stack.\n\n## Revisions\n\nAny change to code or configuration creates a new **revision** (`fn.currentRevision`), and endpoints switch to it once it's ready. A failed deployment rolls back to the previous revision. If nothing changed, nothing is deployed.\n\nEarlier revisions are kept, so you can roll back or route traffic to them. After each deployment, the construct deletes the oldest beyond `revisionRetention` (default 20, up to 50). It never deletes a revision an endpoint routes to, or one the previous deployment used, which a rollback returns to.\n\n```ts\nnew WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.AWS_IAM,\n revisionRetention: 5,\n});\n```\n\n### Routing to earlier revisions\n\nReference an earlier revision by its ID (for example from a `CfnOutput` of `fn.currentRevision.revisionId`, or `aws lambda-web list-web-function-revisions`). Then pin an endpoint to it, or split traffic between two revisions:\n\n```ts\nconst previous = WebFunctionRevision.fromRevisionAttributes(this, 'Previous', {\n webFunction: fn,\n revisionId: 'rev-a1b2c',\n});\n\n// Keep the default endpoint on the previous revision, and send 10% to the new one:\nfn.endpoint.routeTraffic(previous, [{ revision: fn.currentRevision, weight: 0.1 }]);\n\n// Or a second endpoint that stays on the previous revision while fn.endpoint moves on:\nfn.addEndpoint('Stable', { authType: WebFunctionAuthType.AWS_IAM, revision: previous });\n```\n\n- An endpoint routes to at most two revisions. The additional revision's `weight` is a whole percentage, from 0.01 to 0.99.\n- To promote, remove `routeTraffic` (or `revision`) and deploy: the endpoint serves the current revision again.\n- Lambda Web Function metrics have no revision dimension. To compare a split's revisions, log a version you control (for example an environment variable) from your application.\n\n### Canary and linear deployments\n\nBy default an endpoint moves all its traffic to a new revision at once. With `deployment`, it moves in steps instead, watching CloudWatch alarms: if one goes into ALARM, the endpoint goes back to the revision it served before and the deployment fails, so CloudFormation rolls the stack back.\n\n```ts\nconst api = new WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.AWS_IAM,\n endpoint: {\n // 10% of the traffic for 10 minutes, then all of it; back if more than 2% of requests get a 5XX.\n deployment: WebFunctionDeployment.canary({ percent: 10, bake: Duration.minutes(10), rollbackOn: { serverErrorRate: 2 } }),\n },\n});\n\n// 25% more every 5 minutes, watching an alarm of your own. Each endpoint has its own deployment.\n// errorRate: any cloudwatch.IAlarm, e.g. on a metric your application publishes.\napi.addEndpoint('Public', {\n authType: WebFunctionAuthType.NONE,\n deployment: WebFunctionDeployment.linear({ percent: 25, interval: Duration.minutes(5), alarms: [errorRate] }),\n});\n```\n\n| | Steps | Limits |\n|---|---|---|\n| `allAtOnce()` (default) | 100% | |\n| `canary({ percent, bake })` | `percent`, then 100% after `bake` | `percent` 1–99, `bake` 1–45 minutes |\n| `linear({ percent, interval })` | `percent` more every `interval` | `percent` 5–50, `interval` from 1 minute, at most 45 minutes in all |\n\nHow it works:\n\n- Each deployment that creates a revision (code or configuration) moves the traffic from the revision the endpoint serves at that moment, which is also what it goes back to. If someone switched the endpoint outside CloudFormation, the deployment starts from there.\n- Each step waits until every region of a `MULTI_REGION` or `PER_REGION` endpoint has applied it (usually about 15 seconds), and if a region fails to update, the endpoint goes back as for an alarm. The bake or interval counts from the start of the step.\n- Alarms are checked before the first step (an alarm already in ALARM stops the deployment before any traffic moves), throughout every step, and once the new revision has all the traffic. They can be in any region, and composite alarms work. `INSUFFICIENT_DATA` doesn't stop a deployment.\n- A rollback of the stack, for any reason, moves the traffic back at once, without waiting or checking alarms.\n- A stack's first deployment, and a new endpoint (including one renamed by a region change), serve the revision at once: there's nothing to move from.\n- A deployment can take up to an hour: CloudFormation waits for it before it updates the endpoint. Deployments of different endpoints run in parallel.\n- A canary or linear endpoint always moves to the current revision, so it can't also use `revision`, `additionalRevisions` or `routeTraffic()`. Use `allAtOnce()` to deploy a fix immediately, for example while an alarm is in ALARM.\n\n#### Rollback alarms\n\n`rollbackOn` makes the endpoint create alarms on its own error rates, and the deployment watches them alongside any `alarms` you pass:\n\n| `rollbackOn` | Default | |\n|---|---|---|\n| `serverErrorRate` | none | roll back when more than this % of requests get a 5XX |\n| `clientErrorRate` | none | the same for 4XX (including 429s from `rateLimit` and `maxEnvironments`) |\n| `minimumRequests` | 10 | periods with fewer requests don't count, so one failed request out of two doesn't roll back |\n| `period`, `evaluationPeriods` | 1 minute, 2 | consecutive periods over the threshold before rolling back |\n\n- **One alarm per threshold in every region the endpoint serves from.** Metrics are published in the region that served the request, and an alarm can only watch metrics in its own region. The home region's alarm is a normal CloudFormation alarm; the others are created and deleted with the endpoint by a custom resource, and named `LambdaWeb-<function>-<endpoint>-5xx-rate` (or `-4xx-rate`). `endpoint.rollbackAlarms` lists them all, e.g. to add notifications to the home region's.\n- **The alarms see the whole endpoint.** Lambda Web Function metrics have no revision dimension, so at 10% a new revision's errors are about a tenth of the endpoint's: set the threshold low enough to notice that, or alarm on metrics your application publishes with its version.\n- **5XX includes the platform's 503s** while the endpoint scales up for a sudden burst, not only your application's errors.\n- **A step should outlast the alarm.** CloudWatch needs `period` × `evaluationPeriods`, plus a couple of minutes of delay, to fire; the construct warns when a canary's bake or a linear interval is shorter.\n\nThe deployment runs in a few resources per stack, created on first use: two Lambda functions, a Step Functions state machine that calls them every 15 seconds, and a log group.\n\n## Metrics\n\nEndpoints and functions have helpers for their CloudWatch metrics (namespace `AWS/Lambda/Web`), like `lambda.Function`'s:\n\n```ts\nfn.endpoint.metricServerErrorRate().createAlarm(this, 'ErrorRate', { threshold: 1, evaluationPeriods: 3 });\nfn.endpoint.metricRequestThrottles().createAlarm(this, 'Throttled', { threshold: 10, evaluationPeriods: 3 });\nfn.metricConcurrentRequests().createAlarm(this, 'Saturated', { threshold: 60, evaluationPeriods: 3 });\n```\n\n| Endpoint | Metric |\n|---|---|\n| `metricRequests()` | `ExecutedRequests` (there's no separate 2XX count) |\n| `metricClientErrors()`, `metricServerErrors()` | `HTTPResponseStatusClass4XX`, `HTTPResponseStatusClass5XX` |\n| `metricClientErrorRate()`, `metricServerErrorRate()` | 4XX or 5XX as a % of requests (math expression) |\n| `metricActiveEnvironments()` | `EndpointActiveEnvironments`, to compare with `maxEnvironments` |\n| `metricRequestThrottles()`, `metricEnvironmentThrottles()` | 429s from `rateLimit` and from `maxEnvironments` |\n\n| Function | Metric |\n|---|---|\n| `metricConcurrentRequests()` | `EnvironmentConcurrentRequests` (maximum), to compare with `maxConcurrencyPerEnvironment` |\n| `metricMaxMemoryUsage()` | `EnvironmentMaxMemoryUsage` (maximum) |\n| `metricActiveTime()`, `metricCpuTime()`, `metricResponseBytes()` | `EnvironmentActiveTime`, `EnvironmentCPUTime`, `ResponseBytes` |\n\n- **Metrics stay in the region that served the request**; unlike logs, they aren't copied to the home region. Every helper takes `region`. Dashboards can show any region, but an alarm can only use metrics from its own stack's region.\n- 4XX, 5XX and the throttle metrics only exist once they're non-zero: alarm on them with `treatMissingData: NOT_BREACHING`. The rate helpers count missing errors as 0.\n- There's no latency metric. Publish one from your application (e.g. with the CloudWatch embedded metric format).\n\n## Logs in every region\n\nWeb Functions log in two tiers:\n\n```text\n every serving region home region\n ┌──────────────────┐ ┌──────────────────────────────────────────┐\n │ <group>.local │── copied ───►│ <group> every region's logs │\n │ (that region's │ (seconds) │ streams …[rev]<instance>-<acct>-<region> │\n │ environments) │ │ <group>.local (home-region traffic) │\n └──────────────────┘ └──────────────────────────────────────────┘\n```\n\n**Query `fn.logGroup`**, the home-region group that receives every region's logs. The service would create missing groups without retention and never delete them, so the construct creates and owns all of them: both home-region groups, and `<group>.local` in every other region any of its endpoints serves from.\n\n```ts\nnew WebFunction(this, 'Api', {\n runtime: lambda.Runtime.NODEJS_24_X,\n code: lambda.Code.fromAsset('dist'),\n authType: WebFunctionAuthType.AWS_IAM,\n logRetention: logs.RetentionDays.THREE_MONTHS, // default ONE_MONTH, every group in every region\n logRemovalPolicy: RemovalPolicy.DESTROY, // default RETAIN\n applicationLogLevelV2: lambda.ApplicationLogLevel.WARN,\n systemLogLevelV2: lambda.SystemLogLevel.INFO, // DEBUG, INFO or WARN\n});\n```\n\n- The default group is `/aws/lambda/web/<function name>`. Log lines are JSON; application lines carry `requestId`, `endpointName` and `region`.\n- Every event is stored twice (`.local` plus the home-region copy), so expect about double log ingestion, plus cross-region transfer.\n- With `DESTROY`, deletion waits about a minute after the function is gone, because environments flush their last lines late.\n- Subscribe only to `fn.logGroup`: subscribing to the `.local` groups as well delivers every event twice.\n\n## cdk-nag\n\nThe library acknowledges the [cdk-nag](https://github.com/cdklabs/cdk-nag) AwsSolutions findings on the resources it creates, each with a reason, so they don't show up in your reports:\n\n| Finding | Resource | Reason |\n|---|---|---|\n| IAM5 (wildcards) | the default execution role | log streams of the function's own log groups, in every region it serves from |\n| IAM5 | the deployment handlers' role (canary and linear deployments) | their own log group, `cloudwatch:DescribeAlarms` (composite alarms need `*`), and the revisions and endpoints of the functions they deploy |\n| IAM4, IAM5, SF1, SF2 | the CDK Provider framework behind deployments | CDK's own functions and waiter state machine |\n| S1 (access logs) | the stack's code bucket | it only holds copies of the stack's code assets |\n\n- **This works with both cdk-nag versions**, without depending on cdk-nag. cdk-nag 3 reads CDK's `Validations.of(...).acknowledge()`, one ID per finding. cdk-nag 2 reads `cdk_nag` metadata in the template.\n- **Your own statements and resources are still checked.** That includes statements you add to the function's role (`addToRolePolicy`, grants) and your CloudFront distribution's settings.\n- Only the AwsSolutions pack is covered; findings from the HIPAA, NIST and PCI packs aren't acknowledged.\n\n## Upgrading\n\n### From 0.1.5 to 0.1.7, with a resource policy\n\nVersions 0.1.5 to 0.1.7 wrote the function's resource policy with an `AWS::Lambda::ResourcePolicy`. Later versions don't (0.1.7 has the same code as 0.1.6). When an update removes that resource, CloudFormation deletes the function's **whole** resource policy at the end of the update, including the statements the new version just wrote. Callers that rely on the policy then get 403: other accounts, AWS services, and CloudFront.\n\nIf your function has a resource policy (from `addPermission`, a grant to another account or an AWS service, or `WebFunctionOrigin`), first deploy once on the version you have, with the old resource retained:\n\n```ts\n(fn.node.findChild('ResourcePolicy') as CfnResource).applyRemovalPolicy(RemovalPolicy.RETAIN);\n```\n\nThen upgrade, without changing your statements in the same deployment. The new version takes over the statements it writes itself. A statement you removed in the same deployment would stay in the policy.\n\n## Limitations\n\n- Not yet supported: VPC access (network connectors), KMS encryption, and tracing.\n- **Hotswap skips Web Functions without a warning.** `cdk deploy --hotswap` and `cdk watch`, which hotswaps by default, report `(no changes)` for a code or configuration change and the endpoint keeps serving the old revision. Use `cdk watch --hotswap-fallback` (or `cdk deploy --hotswap-fallback`): it deploys Web Function changes through CloudFormation, in about 40 seconds for a home-region endpoint.\n- Fixed limits: 512 MB of code (unzipped) and 32 KB of environment variables per revision, 512 MB of `/tmp` per execution environment, and 128 KiB of headers per request.\n- Quotas: 10 endpoints and about 50 revisions per function (Lambda cleans up older revisions automatically), and 10,000 requests per second per endpoint. Per account and region: 100,000 requests per second and 2,000 Arm64 vCPUs (each execution environment uses 2). The account quotas are adjustable, and new accounts start lower. See [Lambda quotas](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html).\n\n## Development\n\nTooling is pinned in `mise.toml` (Node 24, AWS CDK CLI). Personal settings, such as the AWS profile for the live end-to-end tests, go in a git-ignored `mise.local.toml`.\n\n```bash\nmise install\nnpx projen build # compile, unit tests, lint, API docs\nnpx projen e2e # deploy, verify and destroy real stacks in three regions (needs AWS credentials)\n```\n"
|
|
9749
9749
|
},
|
|
9750
9750
|
"repository": {
|
|
9751
9751
|
"type": "git",
|
|
@@ -9853,7 +9853,7 @@
|
|
|
9853
9853
|
"kind": "interface",
|
|
9854
9854
|
"locationInModule": {
|
|
9855
9855
|
"filename": "src/web-function.ts",
|
|
9856
|
-
"line":
|
|
9856
|
+
"line": 192
|
|
9857
9857
|
},
|
|
9858
9858
|
"methods": [
|
|
9859
9859
|
{
|
|
@@ -9865,7 +9865,7 @@
|
|
|
9865
9865
|
},
|
|
9866
9866
|
"locationInModule": {
|
|
9867
9867
|
"filename": "src/web-function.ts",
|
|
9868
|
-
"line":
|
|
9868
|
+
"line": 215
|
|
9869
9869
|
},
|
|
9870
9870
|
"name": "grantInvoke",
|
|
9871
9871
|
"parameters": [
|
|
@@ -9890,7 +9890,7 @@
|
|
|
9890
9890
|
},
|
|
9891
9891
|
"locationInModule": {
|
|
9892
9892
|
"filename": "src/web-function.ts",
|
|
9893
|
-
"line":
|
|
9893
|
+
"line": 220
|
|
9894
9894
|
},
|
|
9895
9895
|
"name": "metric",
|
|
9896
9896
|
"parameters": [
|
|
@@ -9922,7 +9922,7 @@
|
|
|
9922
9922
|
},
|
|
9923
9923
|
"locationInModule": {
|
|
9924
9924
|
"filename": "src/web-function.ts",
|
|
9925
|
-
"line":
|
|
9925
|
+
"line": 223
|
|
9926
9926
|
},
|
|
9927
9927
|
"name": "metricActiveTime",
|
|
9928
9928
|
"parameters": [
|
|
@@ -9948,7 +9948,7 @@
|
|
|
9948
9948
|
},
|
|
9949
9949
|
"locationInModule": {
|
|
9950
9950
|
"filename": "src/web-function.ts",
|
|
9951
|
-
"line":
|
|
9951
|
+
"line": 229
|
|
9952
9952
|
},
|
|
9953
9953
|
"name": "metricConcurrentRequests",
|
|
9954
9954
|
"parameters": [
|
|
@@ -9974,7 +9974,7 @@
|
|
|
9974
9974
|
},
|
|
9975
9975
|
"locationInModule": {
|
|
9976
9976
|
"filename": "src/web-function.ts",
|
|
9977
|
-
"line":
|
|
9977
|
+
"line": 226
|
|
9978
9978
|
},
|
|
9979
9979
|
"name": "metricCpuTime",
|
|
9980
9980
|
"parameters": [
|
|
@@ -10000,7 +10000,7 @@
|
|
|
10000
10000
|
},
|
|
10001
10001
|
"locationInModule": {
|
|
10002
10002
|
"filename": "src/web-function.ts",
|
|
10003
|
-
"line":
|
|
10003
|
+
"line": 232
|
|
10004
10004
|
},
|
|
10005
10005
|
"name": "metricMaxMemoryUsage",
|
|
10006
10006
|
"parameters": [
|
|
@@ -10026,7 +10026,7 @@
|
|
|
10026
10026
|
},
|
|
10027
10027
|
"locationInModule": {
|
|
10028
10028
|
"filename": "src/web-function.ts",
|
|
10029
|
-
"line":
|
|
10029
|
+
"line": 235
|
|
10030
10030
|
},
|
|
10031
10031
|
"name": "metricResponseBytes",
|
|
10032
10032
|
"parameters": [
|
|
@@ -10059,7 +10059,7 @@
|
|
|
10059
10059
|
"immutable": true,
|
|
10060
10060
|
"locationInModule": {
|
|
10061
10061
|
"filename": "src/web-function.ts",
|
|
10062
|
-
"line":
|
|
10062
|
+
"line": 205
|
|
10063
10063
|
},
|
|
10064
10064
|
"name": "webFunctionArn",
|
|
10065
10065
|
"type": {
|
|
@@ -10078,7 +10078,7 @@
|
|
|
10078
10078
|
"immutable": true,
|
|
10079
10079
|
"locationInModule": {
|
|
10080
10080
|
"filename": "src/web-function.ts",
|
|
10081
|
-
"line":
|
|
10081
|
+
"line": 198
|
|
10082
10082
|
},
|
|
10083
10083
|
"name": "webFunctionName",
|
|
10084
10084
|
"type": {
|
|
@@ -10675,7 +10675,7 @@
|
|
|
10675
10675
|
},
|
|
10676
10676
|
"locationInModule": {
|
|
10677
10677
|
"filename": "src/web-function.ts",
|
|
10678
|
-
"line":
|
|
10678
|
+
"line": 488
|
|
10679
10679
|
},
|
|
10680
10680
|
"parameters": [
|
|
10681
10681
|
{
|
|
@@ -10704,7 +10704,7 @@
|
|
|
10704
10704
|
"kind": "class",
|
|
10705
10705
|
"locationInModule": {
|
|
10706
10706
|
"filename": "src/web-function.ts",
|
|
10707
|
-
"line":
|
|
10707
|
+
"line": 418
|
|
10708
10708
|
},
|
|
10709
10709
|
"methods": [
|
|
10710
10710
|
{
|
|
@@ -10714,7 +10714,7 @@
|
|
|
10714
10714
|
},
|
|
10715
10715
|
"locationInModule": {
|
|
10716
10716
|
"filename": "src/web-function.ts",
|
|
10717
|
-
"line":
|
|
10717
|
+
"line": 428
|
|
10718
10718
|
},
|
|
10719
10719
|
"name": "fromWebFunctionArn",
|
|
10720
10720
|
"parameters": [
|
|
@@ -10751,7 +10751,7 @@
|
|
|
10751
10751
|
},
|
|
10752
10752
|
"locationInModule": {
|
|
10753
10753
|
"filename": "src/web-function.ts",
|
|
10754
|
-
"line":
|
|
10754
|
+
"line": 442
|
|
10755
10755
|
},
|
|
10756
10756
|
"name": "fromWebFunctionAttributes",
|
|
10757
10757
|
"parameters": [
|
|
@@ -10788,7 +10788,7 @@
|
|
|
10788
10788
|
},
|
|
10789
10789
|
"locationInModule": {
|
|
10790
10790
|
"filename": "src/web-function.ts",
|
|
10791
|
-
"line":
|
|
10791
|
+
"line": 435
|
|
10792
10792
|
},
|
|
10793
10793
|
"name": "fromWebFunctionName",
|
|
10794
10794
|
"parameters": [
|
|
@@ -10825,7 +10825,7 @@
|
|
|
10825
10825
|
},
|
|
10826
10826
|
"locationInModule": {
|
|
10827
10827
|
"filename": "src/web-function.ts",
|
|
10828
|
-
"line":
|
|
10828
|
+
"line": 602
|
|
10829
10829
|
},
|
|
10830
10830
|
"name": "addEndpoint",
|
|
10831
10831
|
"parameters": [
|
|
@@ -10859,7 +10859,7 @@
|
|
|
10859
10859
|
},
|
|
10860
10860
|
"locationInModule": {
|
|
10861
10861
|
"filename": "src/web-function.ts",
|
|
10862
|
-
"line":
|
|
10862
|
+
"line": 610
|
|
10863
10863
|
},
|
|
10864
10864
|
"name": "addEnvironment",
|
|
10865
10865
|
"parameters": [
|
|
@@ -10890,7 +10890,7 @@
|
|
|
10890
10890
|
},
|
|
10891
10891
|
"locationInModule": {
|
|
10892
10892
|
"filename": "src/web-function.ts",
|
|
10893
|
-
"line":
|
|
10893
|
+
"line": 639
|
|
10894
10894
|
},
|
|
10895
10895
|
"name": "addPermission",
|
|
10896
10896
|
"parameters": [
|
|
@@ -10918,7 +10918,7 @@
|
|
|
10918
10918
|
},
|
|
10919
10919
|
"locationInModule": {
|
|
10920
10920
|
"filename": "src/web-function.ts",
|
|
10921
|
-
"line":
|
|
10921
|
+
"line": 621
|
|
10922
10922
|
},
|
|
10923
10923
|
"name": "addToRolePolicy",
|
|
10924
10924
|
"parameters": [
|
|
@@ -10938,7 +10938,7 @@
|
|
|
10938
10938
|
},
|
|
10939
10939
|
"locationInModule": {
|
|
10940
10940
|
"filename": "src/web-function.ts",
|
|
10941
|
-
"line":
|
|
10941
|
+
"line": 669
|
|
10942
10942
|
},
|
|
10943
10943
|
"name": "encryptionKeyPolicyStatement",
|
|
10944
10944
|
"returns": {
|
|
@@ -10955,7 +10955,7 @@
|
|
|
10955
10955
|
},
|
|
10956
10956
|
"locationInModule": {
|
|
10957
10957
|
"filename": "src/web-function.ts",
|
|
10958
|
-
"line":
|
|
10958
|
+
"line": 629
|
|
10959
10959
|
},
|
|
10960
10960
|
"name": "grantInvoke",
|
|
10961
10961
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.WebFunctionBase",
|
|
@@ -10972,6 +10972,34 @@
|
|
|
10972
10972
|
"fqn": "aws-cdk-lib.aws_iam.Grant"
|
|
10973
10973
|
}
|
|
10974
10974
|
}
|
|
10975
|
+
},
|
|
10976
|
+
{
|
|
10977
|
+
"docs": {
|
|
10978
|
+
"remarks": "It's added to `logEncryptionKey` for the key's own region when the key is defined in this app. Add it to the\nreplica in every other region the function serves from yourself: replicas don't share their primary's policy.",
|
|
10979
|
+
"stability": "experimental",
|
|
10980
|
+
"summary": "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`)."
|
|
10981
|
+
},
|
|
10982
|
+
"locationInModule": {
|
|
10983
|
+
"filename": "src/web-function.ts",
|
|
10984
|
+
"line": 692
|
|
10985
|
+
},
|
|
10986
|
+
"name": "logEncryptionKeyPolicyStatement",
|
|
10987
|
+
"parameters": [
|
|
10988
|
+
{
|
|
10989
|
+
"docs": {
|
|
10990
|
+
"summary": "the region of the key or replica."
|
|
10991
|
+
},
|
|
10992
|
+
"name": "region",
|
|
10993
|
+
"type": {
|
|
10994
|
+
"primitive": "string"
|
|
10995
|
+
}
|
|
10996
|
+
}
|
|
10997
|
+
],
|
|
10998
|
+
"returns": {
|
|
10999
|
+
"type": {
|
|
11000
|
+
"fqn": "aws-cdk-lib.aws_iam.PolicyStatement"
|
|
11001
|
+
}
|
|
11002
|
+
}
|
|
10975
11003
|
}
|
|
10976
11004
|
],
|
|
10977
11005
|
"name": "WebFunction",
|
|
@@ -10985,7 +11013,7 @@
|
|
|
10985
11013
|
"immutable": true,
|
|
10986
11014
|
"locationInModule": {
|
|
10987
11015
|
"filename": "src/web-function.ts",
|
|
10988
|
-
"line":
|
|
11016
|
+
"line": 423
|
|
10989
11017
|
},
|
|
10990
11018
|
"name": "PROPERTY_INJECTION_ID",
|
|
10991
11019
|
"static": true,
|
|
@@ -11001,7 +11029,7 @@
|
|
|
11001
11029
|
"immutable": true,
|
|
11002
11030
|
"locationInModule": {
|
|
11003
11031
|
"filename": "src/web-function.ts",
|
|
11004
|
-
"line":
|
|
11032
|
+
"line": 453
|
|
11005
11033
|
},
|
|
11006
11034
|
"name": "currentRevision",
|
|
11007
11035
|
"type": {
|
|
@@ -11017,7 +11045,7 @@
|
|
|
11017
11045
|
"immutable": true,
|
|
11018
11046
|
"locationInModule": {
|
|
11019
11047
|
"filename": "src/web-function.ts",
|
|
11020
|
-
"line":
|
|
11048
|
+
"line": 456
|
|
11021
11049
|
},
|
|
11022
11050
|
"name": "endpoint",
|
|
11023
11051
|
"type": {
|
|
@@ -11032,7 +11060,7 @@
|
|
|
11032
11060
|
"immutable": true,
|
|
11033
11061
|
"locationInModule": {
|
|
11034
11062
|
"filename": "src/web-function.ts",
|
|
11035
|
-
"line":
|
|
11063
|
+
"line": 471
|
|
11036
11064
|
},
|
|
11037
11065
|
"name": "grantPrincipal",
|
|
11038
11066
|
"overrides": "aws-cdk-lib.aws_iam.IGrantable",
|
|
@@ -11048,7 +11076,7 @@
|
|
|
11048
11076
|
"immutable": true,
|
|
11049
11077
|
"locationInModule": {
|
|
11050
11078
|
"filename": "src/web-function.ts",
|
|
11051
|
-
"line":
|
|
11079
|
+
"line": 459
|
|
11052
11080
|
},
|
|
11053
11081
|
"name": "grants",
|
|
11054
11082
|
"type": {
|
|
@@ -11064,7 +11092,7 @@
|
|
|
11064
11092
|
"immutable": true,
|
|
11065
11093
|
"locationInModule": {
|
|
11066
11094
|
"filename": "src/web-function.ts",
|
|
11067
|
-
"line":
|
|
11095
|
+
"line": 477
|
|
11068
11096
|
},
|
|
11069
11097
|
"name": "logGroup",
|
|
11070
11098
|
"type": {
|
|
@@ -11080,7 +11108,7 @@
|
|
|
11080
11108
|
"immutable": true,
|
|
11081
11109
|
"locationInModule": {
|
|
11082
11110
|
"filename": "src/web-function.ts",
|
|
11083
|
-
"line":
|
|
11111
|
+
"line": 450
|
|
11084
11112
|
},
|
|
11085
11113
|
"name": "revisionId",
|
|
11086
11114
|
"type": {
|
|
@@ -11095,7 +11123,7 @@
|
|
|
11095
11123
|
"immutable": true,
|
|
11096
11124
|
"locationInModule": {
|
|
11097
11125
|
"filename": "src/web-function.ts",
|
|
11098
|
-
"line":
|
|
11126
|
+
"line": 462
|
|
11099
11127
|
},
|
|
11100
11128
|
"name": "role",
|
|
11101
11129
|
"type": {
|
|
@@ -11110,7 +11138,7 @@
|
|
|
11110
11138
|
"immutable": true,
|
|
11111
11139
|
"locationInModule": {
|
|
11112
11140
|
"filename": "src/web-function.ts",
|
|
11113
|
-
"line":
|
|
11141
|
+
"line": 447
|
|
11114
11142
|
},
|
|
11115
11143
|
"name": "webFunctionArn",
|
|
11116
11144
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.WebFunctionBase",
|
|
@@ -11126,7 +11154,7 @@
|
|
|
11126
11154
|
"immutable": true,
|
|
11127
11155
|
"locationInModule": {
|
|
11128
11156
|
"filename": "src/web-function.ts",
|
|
11129
|
-
"line":
|
|
11157
|
+
"line": 446
|
|
11130
11158
|
},
|
|
11131
11159
|
"name": "webFunctionName",
|
|
11132
11160
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.WebFunctionBase",
|
|
@@ -11142,13 +11170,29 @@
|
|
|
11142
11170
|
"immutable": true,
|
|
11143
11171
|
"locationInModule": {
|
|
11144
11172
|
"filename": "src/web-function.ts",
|
|
11145
|
-
"line":
|
|
11173
|
+
"line": 465
|
|
11146
11174
|
},
|
|
11147
11175
|
"name": "encryptionKey",
|
|
11148
11176
|
"optional": true,
|
|
11149
11177
|
"type": {
|
|
11150
11178
|
"fqn": "aws-cdk-lib.aws_kms.IKey"
|
|
11151
11179
|
}
|
|
11180
|
+
},
|
|
11181
|
+
{
|
|
11182
|
+
"docs": {
|
|
11183
|
+
"stability": "experimental",
|
|
11184
|
+
"summary": "The customer managed key of the function's log groups, if any."
|
|
11185
|
+
},
|
|
11186
|
+
"immutable": true,
|
|
11187
|
+
"locationInModule": {
|
|
11188
|
+
"filename": "src/web-function.ts",
|
|
11189
|
+
"line": 468
|
|
11190
|
+
},
|
|
11191
|
+
"name": "logEncryptionKey",
|
|
11192
|
+
"optional": true,
|
|
11193
|
+
"type": {
|
|
11194
|
+
"fqn": "aws-cdk-lib.aws_kms.IKey"
|
|
11195
|
+
}
|
|
11152
11196
|
}
|
|
11153
11197
|
],
|
|
11154
11198
|
"symbolId": "src/web-function:WebFunction"
|
|
@@ -11165,7 +11209,7 @@
|
|
|
11165
11209
|
"kind": "interface",
|
|
11166
11210
|
"locationInModule": {
|
|
11167
11211
|
"filename": "src/web-function.ts",
|
|
11168
|
-
"line":
|
|
11212
|
+
"line": 241
|
|
11169
11213
|
},
|
|
11170
11214
|
"name": "WebFunctionAttributes",
|
|
11171
11215
|
"properties": [
|
|
@@ -11179,7 +11223,7 @@
|
|
|
11179
11223
|
"immutable": true,
|
|
11180
11224
|
"locationInModule": {
|
|
11181
11225
|
"filename": "src/web-function.ts",
|
|
11182
|
-
"line":
|
|
11226
|
+
"line": 263
|
|
11183
11227
|
},
|
|
11184
11228
|
"name": "endpointName",
|
|
11185
11229
|
"optional": true,
|
|
@@ -11197,7 +11241,7 @@
|
|
|
11197
11241
|
"immutable": true,
|
|
11198
11242
|
"locationInModule": {
|
|
11199
11243
|
"filename": "src/web-function.ts",
|
|
11200
|
-
"line":
|
|
11244
|
+
"line": 249
|
|
11201
11245
|
},
|
|
11202
11246
|
"name": "webFunctionArn",
|
|
11203
11247
|
"optional": true,
|
|
@@ -11215,7 +11259,7 @@
|
|
|
11215
11259
|
"immutable": true,
|
|
11216
11260
|
"locationInModule": {
|
|
11217
11261
|
"filename": "src/web-function.ts",
|
|
11218
|
-
"line":
|
|
11262
|
+
"line": 256
|
|
11219
11263
|
},
|
|
11220
11264
|
"name": "webFunctionName",
|
|
11221
11265
|
"optional": true,
|
|
@@ -11303,7 +11347,7 @@
|
|
|
11303
11347
|
"kind": "class",
|
|
11304
11348
|
"locationInModule": {
|
|
11305
11349
|
"filename": "src/web-function.ts",
|
|
11306
|
-
"line":
|
|
11350
|
+
"line": 304
|
|
11307
11351
|
},
|
|
11308
11352
|
"methods": [
|
|
11309
11353
|
{
|
|
@@ -11314,7 +11358,7 @@
|
|
|
11314
11358
|
},
|
|
11315
11359
|
"locationInModule": {
|
|
11316
11360
|
"filename": "src/web-function.ts",
|
|
11317
|
-
"line":
|
|
11361
|
+
"line": 327
|
|
11318
11362
|
},
|
|
11319
11363
|
"name": "addToResourcePolicy",
|
|
11320
11364
|
"overrides": "aws-cdk-lib.aws_iam.IResourceWithPolicyV2",
|
|
@@ -11341,7 +11385,7 @@
|
|
|
11341
11385
|
},
|
|
11342
11386
|
"locationInModule": {
|
|
11343
11387
|
"filename": "src/web-function.ts",
|
|
11344
|
-
"line":
|
|
11388
|
+
"line": 317
|
|
11345
11389
|
},
|
|
11346
11390
|
"name": "grantInvoke",
|
|
11347
11391
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.IWebFunction",
|
|
@@ -11368,7 +11412,7 @@
|
|
|
11368
11412
|
},
|
|
11369
11413
|
"locationInModule": {
|
|
11370
11414
|
"filename": "src/web-function.ts",
|
|
11371
|
-
"line":
|
|
11415
|
+
"line": 358
|
|
11372
11416
|
},
|
|
11373
11417
|
"name": "metric",
|
|
11374
11418
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.IWebFunction",
|
|
@@ -11400,7 +11444,7 @@
|
|
|
11400
11444
|
},
|
|
11401
11445
|
"locationInModule": {
|
|
11402
11446
|
"filename": "src/web-function.ts",
|
|
11403
|
-
"line":
|
|
11447
|
+
"line": 373
|
|
11404
11448
|
},
|
|
11405
11449
|
"name": "metricActiveTime",
|
|
11406
11450
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.IWebFunction",
|
|
@@ -11427,7 +11471,7 @@
|
|
|
11427
11471
|
},
|
|
11428
11472
|
"locationInModule": {
|
|
11429
11473
|
"filename": "src/web-function.ts",
|
|
11430
|
-
"line":
|
|
11474
|
+
"line": 388
|
|
11431
11475
|
},
|
|
11432
11476
|
"name": "metricConcurrentRequests",
|
|
11433
11477
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.IWebFunction",
|
|
@@ -11453,7 +11497,7 @@
|
|
|
11453
11497
|
},
|
|
11454
11498
|
"locationInModule": {
|
|
11455
11499
|
"filename": "src/web-function.ts",
|
|
11456
|
-
"line":
|
|
11500
|
+
"line": 378
|
|
11457
11501
|
},
|
|
11458
11502
|
"name": "metricCpuTime",
|
|
11459
11503
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.IWebFunction",
|
|
@@ -11481,7 +11525,7 @@
|
|
|
11481
11525
|
},
|
|
11482
11526
|
"locationInModule": {
|
|
11483
11527
|
"filename": "src/web-function.ts",
|
|
11484
|
-
"line":
|
|
11528
|
+
"line": 397
|
|
11485
11529
|
},
|
|
11486
11530
|
"name": "metricMaxMemoryUsage",
|
|
11487
11531
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.IWebFunction",
|
|
@@ -11507,7 +11551,7 @@
|
|
|
11507
11551
|
},
|
|
11508
11552
|
"locationInModule": {
|
|
11509
11553
|
"filename": "src/web-function.ts",
|
|
11510
|
-
"line":
|
|
11554
|
+
"line": 402
|
|
11511
11555
|
},
|
|
11512
11556
|
"name": "metricResponseBytes",
|
|
11513
11557
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.IWebFunction",
|
|
@@ -11538,7 +11582,7 @@
|
|
|
11538
11582
|
"immutable": true,
|
|
11539
11583
|
"locationInModule": {
|
|
11540
11584
|
"filename": "src/web-function.ts",
|
|
11541
|
-
"line":
|
|
11585
|
+
"line": 306
|
|
11542
11586
|
},
|
|
11543
11587
|
"name": "webFunctionArn",
|
|
11544
11588
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.IWebFunction",
|
|
@@ -11555,7 +11599,7 @@
|
|
|
11555
11599
|
"immutable": true,
|
|
11556
11600
|
"locationInModule": {
|
|
11557
11601
|
"filename": "src/web-function.ts",
|
|
11558
|
-
"line":
|
|
11602
|
+
"line": 305
|
|
11559
11603
|
},
|
|
11560
11604
|
"name": "webFunctionName",
|
|
11561
11605
|
"overrides": "@ashishpandeyone/cdk-lambda-web-function.IWebFunction",
|
|
@@ -11571,7 +11615,7 @@
|
|
|
11571
11615
|
"immutable": true,
|
|
11572
11616
|
"locationInModule": {
|
|
11573
11617
|
"filename": "src/web-function.ts",
|
|
11574
|
-
"line":
|
|
11618
|
+
"line": 309
|
|
11575
11619
|
},
|
|
11576
11620
|
"name": "webFunctionRef",
|
|
11577
11621
|
"overrides": "aws-cdk-lib.interfaces.aws_lambda.IWebFunctionRef",
|
|
@@ -12663,7 +12707,7 @@
|
|
|
12663
12707
|
"immutable": true,
|
|
12664
12708
|
"locationInModule": {
|
|
12665
12709
|
"filename": "src/web-function.ts",
|
|
12666
|
-
"line":
|
|
12710
|
+
"line": 149
|
|
12667
12711
|
},
|
|
12668
12712
|
"name": "applicationLogLevelV2",
|
|
12669
12713
|
"optional": true,
|
|
@@ -12750,6 +12794,25 @@
|
|
|
12750
12794
|
}
|
|
12751
12795
|
}
|
|
12752
12796
|
},
|
|
12797
|
+
{
|
|
12798
|
+
"abstract": true,
|
|
12799
|
+
"docs": {
|
|
12800
|
+
"default": "- CloudWatch Logs' own encryption",
|
|
12801
|
+
"remarks": "CloudWatch Logs needs a key in each group's region: for regions other than the key's own, the construct uses the\nreplica of a **multi-Region key** there (the same key ID). Each key's policy must allow CloudWatch Logs in its\nregion (see `logEncryptionKeyPolicyStatement()`). A key defined in this app gets that statement for its own region.\n\nRemoving the key decrypts nothing: the groups keep their existing events encrypted with it.\n[disable-awslint:prefer-ref-interface]",
|
|
12802
|
+
"stability": "experimental",
|
|
12803
|
+
"summary": "A customer managed KMS key for the function's log groups, in every region it serves from."
|
|
12804
|
+
},
|
|
12805
|
+
"immutable": true,
|
|
12806
|
+
"locationInModule": {
|
|
12807
|
+
"filename": "src/web-function.ts",
|
|
12808
|
+
"line": 142
|
|
12809
|
+
},
|
|
12810
|
+
"name": "logEncryptionKey",
|
|
12811
|
+
"optional": true,
|
|
12812
|
+
"type": {
|
|
12813
|
+
"fqn": "aws-cdk-lib.aws_kms.IKey"
|
|
12814
|
+
}
|
|
12815
|
+
},
|
|
12753
12816
|
{
|
|
12754
12817
|
"abstract": true,
|
|
12755
12818
|
"docs": {
|
|
@@ -12854,7 +12917,7 @@
|
|
|
12854
12917
|
"immutable": true,
|
|
12855
12918
|
"locationInModule": {
|
|
12856
12919
|
"filename": "src/web-function.ts",
|
|
12857
|
-
"line":
|
|
12920
|
+
"line": 156
|
|
12858
12921
|
},
|
|
12859
12922
|
"name": "systemLogLevelV2",
|
|
12860
12923
|
"optional": true,
|
|
@@ -13142,7 +13205,7 @@
|
|
|
13142
13205
|
"kind": "interface",
|
|
13143
13206
|
"locationInModule": {
|
|
13144
13207
|
"filename": "src/web-function.ts",
|
|
13145
|
-
"line":
|
|
13208
|
+
"line": 269
|
|
13146
13209
|
},
|
|
13147
13210
|
"name": "WebFunctionPermission",
|
|
13148
13211
|
"properties": [
|
|
@@ -13156,7 +13219,7 @@
|
|
|
13156
13219
|
"immutable": true,
|
|
13157
13220
|
"locationInModule": {
|
|
13158
13221
|
"filename": "src/web-function.ts",
|
|
13159
|
-
"line":
|
|
13222
|
+
"line": 276
|
|
13160
13223
|
},
|
|
13161
13224
|
"name": "principal",
|
|
13162
13225
|
"type": {
|
|
@@ -13174,7 +13237,7 @@
|
|
|
13174
13237
|
"immutable": true,
|
|
13175
13238
|
"locationInModule": {
|
|
13176
13239
|
"filename": "src/web-function.ts",
|
|
13177
|
-
"line":
|
|
13240
|
+
"line": 283
|
|
13178
13241
|
},
|
|
13179
13242
|
"name": "endpoint",
|
|
13180
13243
|
"optional": true,
|
|
@@ -13192,7 +13255,7 @@
|
|
|
13192
13255
|
"immutable": true,
|
|
13193
13256
|
"locationInModule": {
|
|
13194
13257
|
"filename": "src/web-function.ts",
|
|
13195
|
-
"line":
|
|
13258
|
+
"line": 298
|
|
13196
13259
|
},
|
|
13197
13260
|
"name": "sourceAccount",
|
|
13198
13261
|
"optional": true,
|
|
@@ -13210,7 +13273,7 @@
|
|
|
13210
13273
|
"immutable": true,
|
|
13211
13274
|
"locationInModule": {
|
|
13212
13275
|
"filename": "src/web-function.ts",
|
|
13213
|
-
"line":
|
|
13276
|
+
"line": 291
|
|
13214
13277
|
},
|
|
13215
13278
|
"name": "sourceArn",
|
|
13216
13279
|
"optional": true,
|
|
@@ -13235,7 +13298,7 @@
|
|
|
13235
13298
|
"kind": "interface",
|
|
13236
13299
|
"locationInModule": {
|
|
13237
13300
|
"filename": "src/web-function.ts",
|
|
13238
|
-
"line":
|
|
13301
|
+
"line": 162
|
|
13239
13302
|
},
|
|
13240
13303
|
"name": "WebFunctionProps",
|
|
13241
13304
|
"properties": [
|
|
@@ -13249,7 +13312,7 @@
|
|
|
13249
13312
|
"immutable": true,
|
|
13250
13313
|
"locationInModule": {
|
|
13251
13314
|
"filename": "src/web-function.ts",
|
|
13252
|
-
"line":
|
|
13315
|
+
"line": 174
|
|
13253
13316
|
},
|
|
13254
13317
|
"name": "code",
|
|
13255
13318
|
"type": {
|
|
@@ -13265,7 +13328,7 @@
|
|
|
13265
13328
|
"immutable": true,
|
|
13266
13329
|
"locationInModule": {
|
|
13267
13330
|
"filename": "src/web-function.ts",
|
|
13268
|
-
"line":
|
|
13331
|
+
"line": 166
|
|
13269
13332
|
},
|
|
13270
13333
|
"name": "runtime",
|
|
13271
13334
|
"type": {
|
|
@@ -13282,7 +13345,7 @@
|
|
|
13282
13345
|
"immutable": true,
|
|
13283
13346
|
"locationInModule": {
|
|
13284
13347
|
"filename": "src/web-function.ts",
|
|
13285
|
-
"line":
|
|
13348
|
+
"line": 181
|
|
13286
13349
|
},
|
|
13287
13350
|
"name": "entrypoint",
|
|
13288
13351
|
"optional": true,
|
|
@@ -13614,6 +13677,6 @@
|
|
|
13614
13677
|
"symbolId": "src/web-function-deployment:WebFunctionRollbackOptions"
|
|
13615
13678
|
}
|
|
13616
13679
|
},
|
|
13617
|
-
"version": "0.1.
|
|
13618
|
-
"fingerprint": "
|
|
13680
|
+
"version": "0.1.12",
|
|
13681
|
+
"fingerprint": "eEKvgpGlRCGfraL+IN8F5JTtpuZ3CcK+GeIj4jZ3Q94="
|
|
13619
13682
|
}
|