Skip to content

[4.x] Add Lambda Web Functions support with a top-level webFunctions key - #509

Merged
GrahamCampbell merged 2 commits into
4.xfrom
web-functions
Nov 13, 2026
Merged

GrahamCampbell merged 2 commits into
4.xfrom
web-functions

Conversation

@GrahamCampbell

@GrahamCampbell GrahamCampbell commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Lambda Web Functions run a plain Node.js HTTP server behind an HTTPS endpoint that Lambda provides, and osls has no way to deploy one today (#467). This adds a top-level webFunctions key next to functions and layers, with its own closed schema that rejects settings that only make sense for event functions. Keeping web functions out of functions spares every consumer of functions, in core and in plugins, from learning that an entry may not be a Lambda function. New properties use AWS's names (entryPoint, maxConcurrencyPerEnvironment, an endpoint block), properties shared with functions keep their osls names, and the code ships as it is, with nothing added to the zip. A web function cannot reuse the key of a function, so --function is never ambiguous.

Each web function compiles to an AWS::Lambda::WebFunction, an AWS::Lambda::WebFunctionRevision and an AWS::Lambda::WebFunctionEndpoint in the service stack, with its two log groups and a URL output. CloudFormation has no auto-deploy mode for endpoints, so the endpoint always routes all traffic to the stack's revision, and a change to the code or to a setting of the revision replaces it behind the same URL. The endpoint block sets IAM auth, the scaling and rate limits and the endpoint type, and its name lets a new endpoint replace one whose type or Regions change, which Lambda cannot update in place. The default role may write the .local log group in every Region, without which replica Regions silently drop their logs. Custom domains through CloudFront and VPC access through a network connector stay documented recipes under resources.

Lambda keeps referring to the exact S3 object version of a revision's zip for as long as the revision exists, so the deployment bucket has to be versioned and has to let Lambda read it. When osls creates the bucket, provider.deploymentBucket.versioning: true is required, and the bucket policy gets a statement that lets Lambda read on behalf of the account's web functions, naming none so that a rename cannot take the access away from a revision that still serves. Before the upload osls checks versioning, enabling it directly on its own bucket when the stack has not done so yet, and checks the policy of a bucket the user names. Each zip is stored once under a key derived from its content, outside the per-deployment directories, so a revision is replaced only when its own zip or settings change, and cleanup of old deployments never removes code a revision still references. Express mode with rollback disabled is rejected for package, deploy and a rollback to a deployment with web functions, because CloudFormation refuses the revision replacements that most changes make and leaves the stack in UPDATE_FAILED. info lists the URLs, logs --function accepts a web function, and deploy function, rollback function, invoke, invoke local and metrics --function explain that they do not apply.

@mnapoli

mnapoli commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

I much prefer this one to #510 (e.g. for the logs command, much more natural).

If that's not the case already, could we enforce uniqueness between functions,i.e. we can't have:

functions:
    api:
        # ...

webFunctions:
    api:
        # ...

(that would be an error)

?

That way osls logs --function=api has no ambiguity.

@GrahamCampbell

Copy link
Copy Markdown
Contributor Author

@mnapoli Already enforced: a web function can't use the key of a function in the same service. It's checked in the initialize hook, so every command gets the error, not just package/deploy, and --function is never ambiguous.

@GrahamCampbell
GrahamCampbell marked this pull request as ready for review November 13, 2026 22:09

@mnapoli mnapoli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 🔥

@GrahamCampbell
GrahamCampbell merged commit bfd105c into 4.x Nov 13, 2026
8 checks passed
@GrahamCampbell
GrahamCampbell deleted the web-functions branch November 13, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants