Download the PHP package netolabs/php-lambda-runtime without Composer

On this page you can find all versions of the php package netolabs/php-lambda-runtime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-lambda-runtime

PHP Lambda Runtime library

Requirements

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.

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.

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). The Zip file can then be uploaded via the AWS console or your favourite IaC tool.

Using Middleware

This library uses 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

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

Anonymous function

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

<?php
$app = \Neto\Lambda\Application\AppFactory::create();
$app->addCallable(function() {
    return 'hello world';
});
$app->run();

Anonymous function using Response object

You can also return a Response object if you'd like to manipulate the headers, status code, etc. This example has a header of foo: bar and a response body of baz.

<?php
$app = \Neto\Lambda\Application\AppFactory::create();
$app->addCallable(function() {
    return new \GuzzleHttp\Psr7\Response(200, [ 'foo' => 'bar' ], 'baz');
});
$app->run();

Adding middleware

This example uses the provided HelloWorld middleware to return a response with modified headers and body.

<?php
$app = \Neto\Lambda\Application\AppFactory::create();
$app->addMiddleware(new \Neto\Lambda\Middleware\HelloWorld())
    ->run();

If invoked from the command-line, you would expect to see the following

Status code 200

Headers
hello: world

Response body
{"success":true,"message":"Hello world!"}

Duration: 0.006911039352417ms

Testing locally

Invoking from the command line

To run your lambda from the command line, you can simply run vendor/bin/invoke. There are two optional parameters, handler name (-h) and request body data (-d).

Running a local server

You can also use PHPs built-in web server to test and send requests to your lambda. Simply start the server by running vendor/bin/start_server handler.name [hostname] [port]. You can then send requests to your function via curl, eg: curl --data '{"foo":"bar"}' localhost

License

The MIT License (MIT). Please see the License File for more information.


All versions of php-lambda-runtime with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
ext-json Version *
psr/http-message Version 1.0.*
psr/http-server-handler Version 1.0.*
psr/http-server-middleware Version 1.0.*
psr/container Version ^1.0
guzzlehttp/guzzle Version 6.3.*
ulrichsg/getopt-php Version ^3.2
netolabs/simple-container Version ^0.2.0
php-di/invoker Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package netolabs/php-lambda-runtime contains the following files

Loading the files please wait ....