{"id":18550277,"url":"https://github.com/xp-forge/lambda-ws","last_synced_at":"2026-02-14T22:11:44.721Z","repository":{"id":42128799,"uuid":"400881589","full_name":"xp-forge/lambda-ws","owner":"xp-forge","description":"AWS Lambda Webservices for the XP Framework","archived":false,"fork":false,"pushed_at":"2025-05-05T12:11:05.000Z","size":97,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-20T00:27:39.700Z","etag":null,"topics":["api-gateway","aws","aws-lambda","aws-lambda-php","http","lambda-streams","php7","php8","serverless","xp-framework"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xp-forge.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-08-28T20:11:05.000Z","updated_at":"2025-05-05T12:09:02.000Z","dependencies_parsed_at":"2024-05-20T11:42:25.194Z","dependency_job_id":"b7ac4d0e-4185-41d9-b447-ba708092072d","html_url":"https://github.com/xp-forge/lambda-ws","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/xp-forge/lambda-ws","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Flambda-ws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Flambda-ws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Flambda-ws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Flambda-ws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xp-forge","download_url":"https://codeload.github.com/xp-forge/lambda-ws/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Flambda-ws/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29458104,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T21:29:27.764Z","status":"ssl_error","status_checked_at":"2026-02-14T21:28:11.111Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-gateway","aws","aws-lambda","aws-lambda-php","http","lambda-streams","php7","php8","serverless","xp-framework"],"created_at":"2024-11-06T21:04:04.517Z","updated_at":"2026-02-14T22:11:44.716Z","avatar_url":"https://github.com/xp-forge.png","language":"PHP","readme":"AWS Lambda Webservices for the XP Framework\n========================================================================\n\n[![Build status on GitHub](https://github.com/xp-forge/lambda-ws/workflows/Tests/badge.svg)](https://github.com/xp-forge/lambda-ws/actions)\n[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)\n[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)\n[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)\n[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)\n[![Latest Stable Version](https://poser.pugx.org/xp-forge/lambda-ws/version.svg)](https://packagist.org/packages/xp-forge/lambda-ws)\n\nRun [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.\n\nExample\n-------\nPut this code in a file called *Greet.class.php*:\n\n```php\nuse com\\amazon\\aws\\lambda\\HttpIntegration;\n\nclass Greet extends HttpIntegration {\n\n  /**\n   * Returns routes\n   *\n   * @param  web.Environment $env\n   * @return web.Application|web.Routing|[:var]\n   */\n  public function routes($env) {\n    return ['/' =\u003e function($req, $res) {\n      $greeting= sprintf(\n        'Hello %s from PHP %s on stage %s @ %s',\n        $req-\u003eparam('name') ?? $req-\u003eheader('User-Agent') ?? 'Guest',\n        PHP_VERSION,\n        $req-\u003evalue('request')-\u003estage,\n        $req-\u003evalue('context')-\u003eregion\n      );\n\n      $res-\u003eanswer(200);\n      $res-\u003esend($greeting, 'text/plain');\n    }];\n  }\n}\n```\n\nThe 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*.\n\nTo run existing web applications, return an instance of your `web.Application` subclass from the *routes()* method. \n\nDevelopment \u0026 testing\n---------------------\nTo run the HTTP APIs locally, this library integrates with [xp-forge/web](https://github.com/xp-forge/web) via a wrapper:\n\n```bash\n$ xp web lambda Greet\n@xp.web.srv.Standalone(HTTP @ peer.ServerSocket(Resource id #124 -\u003e tcp://127.0.0.1:8080))\nServing prod:Lambda\u003cGreet\u003e[] \u003e web.logging.ToConsole\n════════════════════════════════════════════════════════════════════════\n\u003e Server started: http://localhost:8080 in 0.057 seconds\n  Sat, 18 Nov 2023 12:19:32 +0100 - PID 18668; press Ctrl+C to exit\n\n# ...\n```\n\nBy adding `-m develop`, these can be run in the development webserver.\n\nSetup and deployment\n--------------------\nFollow 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:\n\n```bash\n$ aws lambda create-function-url-config \\\n  --function-name greet \\\n  --auth-type NONE \\\n  --invoke-mode RESPONSE_STREAM\n```\n\nThe URL will be returned by this command.\n\nInvocation\n----------\nYou can either open the HTTP endpoint in your browser or by using *curl*:\n\n```bash\n$ curl -i https://XXXXXXXXXX.lambda-url.eu-central-1.on.aws/?name=$USER\nDate: Sun, 18 Jun 2023 20:00:55 GMT\nContent-Type: text/plain\nTransfer-Encoding: chunked\nConnection: keep-alive\nx-amzn-RequestId: 3505bbff-e39e-42d3-98d7-9827fb3eb093\nx-amzn-Remapped-content-length: 59\nSet-Cookie: visited=1687118455; SameSite=Lax; HttpOnly\nX-Amzn-Trace-Id: root=1-648f6276-672c96fe6230795d23453441;sampled=0;lineage=83e616e2:0\n\nHello timmf from PHP 8.2.7 on stage $default @ eu-central-1\n```\n\nDeploying changes\n-----------------\nAfter having initially created your lambda, you can update its code as follows:\n\n```bash\n$ xp lambda package Greet.class.php\n$ aws lambda update-function-code \\\n  --function-name greet \\\n  --zip-file fileb://./function.zip \\\n  --publish\n```\n\nStreaming\n---------\nThis 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*.\n\nInherit from the *HttpStreaming* base class instead of *HttpApi*:\n\n```php\nuse com\\amazon\\aws\\lambda\\HttpStreaming;\n\nclass Greet extends HttpStreaming {\n\n  public function routes($env) {\n    /* Shortened for brevity */\n  }\n}\n```\n\nNext, deploy the change, then update the function configuration:\n\n```bash\n$ aws lambda update-function-url-config --function-name greet --invoke-mode RESPONSE_STREAM\n```\n\nRequest context\n---------------\nThe request context passed via the *request* value is defined as follows:\n\n```php\npublic class com.amazon.aws.lambda.RequestContext implements lang.Value {\n  public string $accountId\n  public string $apiId\n  public string $domainName\n  public string $domainPrefix\n  public string $requestId\n  public string $routeKey\n  public string $stage\n  public util.Date $time\n  public [:string] $http\n\n  public function __construct(array $context)\n\n  public function toString(): string\n  public function hashCode(): string\n  public function compareTo(var $value): int\n}\n```\n\nSee also\n--------\n* [Developing an HTTP API in API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop.html)\n* [Matthieu Napoli :: A journey toward serverless on a ship called PHP](https://www.youtube.com/watch?v=VfoNUUJggIA)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-forge%2Flambda-ws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxp-forge%2Flambda-ws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-forge%2Flambda-ws/lists"}