PHPackages                             netolabs/php-lambda-runtime - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. netolabs/php-lambda-runtime

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

netolabs/php-lambda-runtime
===========================

A library for running PHP code in AWS Lambda

v1.0.0(4y ago)131PHPPHP &gt;=7.3

Since Nov 3Pushed 4y ago2 watchersCompare

[ Source](https://github.com/NetoECommerce/php-lambda-runtime)[ Packagist](https://packagist.org/packages/netolabs/php-lambda-runtime)[ RSS](/packages/netolabs-php-lambda-runtime/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (11)Versions (2)Used By (0)

PHP Lambda Runtime library
==========================

[](#php-lambda-runtime-library)

Requirements
------------

[](#requirements)

- PHP 7.3+
- Composer

Installation
------------

[](#installation)

Run `composer require netolabs/php-lambda-runtime` from the root of your project.

You'll need two files in root of your project for your application to work in Lambda, `bootstrap` and `app.php`.

- `bootstrap` can be copied directly from this library (see `bin/bootstrap`) and should not require any modification.
- `app.php` is where you instantiate the App object and define the middleware your application requires. Since the `bootstrap` script sets up the autoloader, you *do not* need to do this in your `app.php`.

Also required is a PHP binary compiled to run in the AWS Lambda environment. Documentation on how to build your own can be found [here](https://aws.amazon.com/blogs/apn/aws-lambda-custom-runtime-for-php-a-practical-example/).

Deploying to AWS
----------------

[](#deploying-to-aws)

When you're ready to ship your new function you'll need to create a Zip file containing `app.php`, `bootstrap`, `src`, `vendor` and your PHP binary in `bin/php` (or use a [Lambda layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html)). The Zip file can then be uploaded via the AWS console or your favourite IaC tool.

Using Middleware
----------------

[](#using-middleware)

This library uses [PSR-15](https://www.php-fig.org/psr/psr-15/) compliant Middleware. If you want to learn more about how to write and use middleware, have a look at these resources:

-
-
-

While reusable middleware is great for application logic such as authentication, logging, exception handling and such, it's generally not advisable to put business logic in your middleware.

Examples
--------

[](#examples)

These are some basic examples of an `app.php` file.

### Anonymous function

[](#anonymous-function)

In this example we use an anonymous function to output "hello world" in the response body.

```
