PHPackages                             xp-forge/lambda-ws - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. xp-forge/lambda-ws

ActiveLibrary

xp-forge/lambda-ws
==================

AWS Lambda Webservices for the XP Framework

v4.0.0(3mo ago)11.3k[1 issues](https://github.com/xp-forge/lambda-ws/issues)[1 PRs](https://github.com/xp-forge/lambda-ws/pulls)BSD-3-ClausePHPPHP &gt;=7.4.0CI passing

Since Aug 28Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/xp-forge/lambda-ws)[ Packagist](https://packagist.org/packages/xp-forge/lambda-ws)[ Docs](http://xp-framework.net/)[ RSS](/packages/xp-forge-lambda-ws/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (4)Versions (27)Used By (0)

AWS Lambda Webservices for the XP Framework
===========================================

[](#aws-lambda-webservices-for-the-xp-framework)

[![Build status on GitHub](https://github.com/xp-forge/lambda-ws/workflows/Tests/badge.svg)](https://github.com/xp-forge/lambda-ws/actions)[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)[![Latest Stable Version](https://camo.githubusercontent.com/59e700a5b7e26b3494aca24e0c557bf12f5931669814a098f52e9d02c59e21ef/68747470733a2f2f706f7365722e707567782e6f72672f78702d666f7267652f6c616d6264612d77732f76657273696f6e2e737667)](https://packagist.org/packages/xp-forge/lambda-ws)

Run [XP web applications](https://github.com/xp-forge/web) on AWS lambda using [API Gateway](https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html) or [Lambda Function URLs](https://aws.amazon.com/de/blogs/aws/announcing-aws-lambda-function-urls-built-in-https-endpoints-for-single-function-microservices/). Unlike other implementations, this library does not spawn PHP-FPM but runs requests directly, resulting in an overhead of less than 1ms.

Example
-------

[](#example)

Put this code in a file called *Greet.class.php*:

```
use com\amazon\aws\lambda\HttpIntegration;

class Greet extends HttpIntegration {

  /**
   * Returns routes
   *
   * @param  web.Environment $env
   * @return web.Application|web.Routing|[:var]
   */
  public function routes($env) {
    return ['/' => function($req, $res) {
      $greeting= sprintf(
        'Hello %s from PHP %s on stage %s @ %s',
        $req->param('name') ?? $req->header('User-Agent') ?? 'Guest',
        PHP_VERSION,
        $req->value('request')->stage,
        $req->value('context')->region
      );

      $res->answer(200);
      $res->send($greeting, 'text/plain');
    }];
  }
}
```

The request context is passed into a request value named *request* and contains a [RequestContext instance](https://github.com/xp-forge/lambda-ws#request-context). The [lambda context](https://github.com/xp-forge/lambda#context) is passed in *context*.

To run existing web applications, return an instance of your `web.Application` subclass from the *routes()* method.

Development &amp; testing
-------------------------

[](#development--testing)

To run the HTTP APIs locally, this library integrates with [xp-forge/web](https://github.com/xp-forge/web) via a wrapper:

```
$ xp web lambda Greet
@xp.web.srv.Standalone(HTTP @ peer.ServerSocket(Resource id #124 -> tcp://127.0.0.1:8080))
Serving prod:Lambda[] > web.logging.ToConsole
════════════════════════════════════════════════════════════════════════
> Server started: http://localhost:8080 in 0.057 seconds
  Sat, 18 Nov 2023 12:19:32 +0100 - PID 18668; press Ctrl+C to exit

# ...
```

By adding `-m develop`, these can be run in the development webserver.

Setup and deployment
--------------------

[](#setup-and-deployment)

Follow the steps shown on the [xp-forge/lambda README](https://github.com/xp-forge/lambda) to create the runtime layer, the service role and the lambda function itself. Next, create the function URL as follows:

```
$ aws lambda create-function-url-config \
  --function-name greet \
  --auth-type NONE \
  --invoke-mode RESPONSE_STREAM
```

The URL will be returned by this command.

Invocation
----------

[](#invocation)

You can either open the HTTP endpoint in your browser or by using *curl*:

```
$ curl -i https://XXXXXXXXXX.lambda-url.eu-central-1.on.aws/?name=$USER
Date: Sun, 18 Jun 2023 20:00:55 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
x-amzn-RequestId: 3505bbff-e39e-42d3-98d7-9827fb3eb093
x-amzn-Remapped-content-length: 59
Set-Cookie: visited=1687118455; SameSite=Lax; HttpOnly
X-Amzn-Trace-Id: root=1-648f6276-672c96fe6230795d23453441;sampled=0;lineage=83e616e2:0

Hello timmf from PHP 8.2.7 on stage $default @ eu-central-1
```

Deploying changes
-----------------

[](#deploying-changes)

After having initially created your lambda, you can update its code as follows:

```
$ xp lambda package Greet.class.php
$ aws lambda update-function-code \
  --function-name greet \
  --zip-file fileb://./function.zip \
  --publish
```

Streaming
---------

[](#streaming)

This library implements HTTP response streaming as [announced by AWS in April 2023](https://aws.amazon.com/de/blogs/compute/introducing-aws-lambda-response-streaming/), improving TTFB and memory consumption of web applications. Response streaming is available for lambda function URLs which have their invoke mode set to *RESPONSE\_STREAM*.

Inherit from the *HttpStreaming* base class instead of *HttpApi*:

```
use com\amazon\aws\lambda\HttpStreaming;

class Greet extends HttpStreaming {

  public function routes($env) {
    /* Shortened for brevity */
  }
}
```

Next, deploy the change, then update the function configuration:

```
$ aws lambda update-function-url-config --function-name greet --invoke-mode RESPONSE_STREAM
```

Request context
---------------

[](#request-context)

The request context passed via the *request* value is defined as follows:

```
public class com.amazon.aws.lambda.RequestContext implements lang.Value {
  public string $accountId
  public string $apiId
  public string $domainName
  public string $domainPrefix
  public string $requestId
  public string $routeKey
  public string $stage
  public util.Date $time
  public [:string] $http

  public function __construct(array $context)

  public function toString(): string
  public function hashCode(): string
  public function compareTo(var $value): int
}
```

See also
--------

[](#see-also)

- [Developing an HTTP API in API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop.html)
- [Matthieu Napoli :: A journey toward serverless on a ship called PHP](https://www.youtube.com/watch?v=VfoNUUJggIA)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance62

Regular maintenance activity

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~68 days

Recently: every ~186 days

Total

25

Last Release

93d ago

Major Versions

v0.7.0 → v1.0.02021-08-29

v1.3.0 → v2.0.02023-11-20

v2.3.0 → v3.0.02025-05-05

v3.0.0 → v4.0.02026-02-14

PHP version history (2 changes)v0.1.0PHP &gt;=7.0.0

v3.0.0PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/07d18d882c8b4aaf3466432f64018214f2771eda333202175431ee7233795376?d=identicon)[thekid](/maintainers/thekid)

---

Top Contributors

[![thekid](https://avatars.githubusercontent.com/u/696742?v=4)](https://github.com/thekid "thekid (109 commits)")

---

Tags

api-gatewayawsaws-lambdaaws-lambda-phphttplambda-streamsphp7php8serverlessxp-frameworkmodulexp

### Embed Badge

![Health badge](/badges/xp-forge-lambda-ws/health.svg)

```
[![Health](https://phpackages.com/badges/xp-forge-lambda-ws/health.svg)](https://phpackages.com/packages/xp-forge-lambda-ws)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
