Download the PHP package xp-forge/lambda without Composer
On this page you can find all versions of the php package xp-forge/lambda. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xp-forge/lambda
More information about xp-forge/lambda
Files in xp-forge/lambda
Package lambda
Short Description AWS Lambda for the XP Framework
License BSD-3-Clause
Homepage http://xp-framework.net/
Informations about the package lambda
AWS Lambda for the XP Framework
Serverless infrastructure.
Example
Put this code in a file called Greet.class.php:
The two parameters passed are $event (a value depending on where the lambda was invoked from) and $context (a Context instance, see below).
Initialization
If you need to run any initialization code, you can do so before returning the lambda from target(). This code is only run once during the init phase:
The lambda's environment accessible via $this->environment is an Environment instance, see below.
Logging
To write output to the lambda's log stream, use trace():
Any non-string arguments passed will be converted to string using util.Objects::stringOf()
. To integrate with XP logging, pass the environment's writer to the console appender, e.g. by using $cat= Logging::all()->toConsole($this->environment->writer)
.
Response streaming
This library supports AWS Lambda response streaming as announced by AWS in April 2023. To use the stream, return a function(var, Stream, Context)
from the handler's target() method instead of a function(var, Context)
:
Invoking this lambda will yield the following:
The Stream interface is defined as follows:
Development
To run your lambda locally, use the following:
This does not provide a complete lambda environment, and does not have any execution limits imposed on it! To detect this programmatically, use $this->environment->local()
, which will return true.
Integration testing
To test your lambda inside a local containerized lambda environment, use the test command.
This functionality is provided by the AWS Lambda base images for custom runtimes. Although this also runs on your machine, $this->environment->local()
will return false.
Setup
The first step is to create and publish the runtime layer:
...and create a role:
After ensuring your dependencies are up-to-date using composer, create the function:
Invocation
To invoke the function:
Deploying changes
After having initially created your lambda, you can update its code as follows:
Upgrading the runtime
To upgrade an existing runtime layer, build the new runtime and publish a new version by calling the following to create a new version:
Now, switch the function over to use this new layer:
Using other AWS services
In order to programmatically use other AWS services use the ServiceEndpoint class:
To test this locally, pass the necessary environment variables via -e on the command line:
Context
The context object passed to the target lambda is defined as follows:
Environment
The runtime environment is defined as follows:
Interfaces
Instead of functions, a handler's target() method may also return instances implementing the Lambda or Streaming interfaces:
See also
- What is AWS Lambda?
- AWS Lambda Webservices for the XP Framework
- AWS Core for the XP Framework
- Lambda runtimes
- AWS Lambda Custom Runtime for PHP: A Practical Example
- AWS SDK for PHP
- The Serverless LAMP stack - Community Resources
- Configuring a Lambda function to stream responses
- Implementing response streaming in a custom runtime
All versions of lambda with dependencies
xp-framework/http Version ^10.0 | ^9.0
xp-framework/zip Version ^11.0 | ^10.0 | ^9.0
xp-forge/aws Version ^2.0 | ^1.0
xp-forge/json Version ^5.0 | ^4.0
php Version >=7.0.0