PHPackages                             popcorn/lambda - 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. popcorn/lambda

ActiveLibrary

popcorn/lambda
==============

A tool to create PHP lambda's

v1.0.7(6y ago)013[2 PRs](https://github.com/mmcgrathRSD/php-lambda-creator/pulls)MITPHP

Since Jan 2Pushed 3y agoCompare

[ Source](https://github.com/mmcgrathRSD/php-lambda-creator)[ Packagist](https://packagist.org/packages/popcorn/lambda)[ RSS](/packages/popcorn-lambda/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (11)Used By (0)

Getting Started
===============

[](#getting-started)

This composer library assists in the creation, configuration, and testing of an AWS Lambda function. It utilizes the AWS Lambda custom runtime API in order to achieve executing PHP (which is not natively supported by lambda), inside of the lambda environment. This repo contains a pre-compiled PHP 7.3 binary in order to assist you in getting up and running quickly. If you have a need to compile your own binary, for example, to enable different PHP extensions, I have written a tutorial on medium, which can be found [here](https://mike-48770.medium.com/aws-lambda-php-via-run-time-api-69a65c516c3e)

If you have any feedback, suggestions, or would like to help improve this tool, I welcome PR's, or suggestions in the form of opening issues. I created this tool to try an make Lambda more approachable for my fellow PHP developers, and would be more than happy to assist you should you have any trouble getting up and running.

In order to use this tool, you will need the following:

1. Knowledge of AWS, and an AWS Developer account, with the ability to create IAM api users.
2. Intermediate to advanced level understanding of PHP.
3. aws cli version 1 or 2.
4. Curiosity about lamba!

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

[](#installation)

Downloading the tool can be achieved by simply cloning the repo, or fetching this repo via composer.

```
$ composer require popcorn/lambda
```

If you go the composer route, take careful note of any of the below steps that contain instructions pertaining to directory structure/naming.

Configuration
-------------

[](#configuration)

In the root directory of where you have installed this tool, copy the example configuration file to a new file named .env

```
$ cp vendor/popcorn/lambda/.env.example .env
```

In order to create the two "layers" we'll need in order to actually execute our PHP code, we will use the aws cli. Download and install the aws CLI (both version 1 and version 2 will work for the purposes of this libary).

During installation of the aws cli, you will need to create an API IAM user for the cli to authenticate with. in general, the aws cli user is highly privledged, so ensure these credentials do not make it into version control. Copy/Paste the key and secret into the .env file as the values for the following keys, AWS\_ACCESS\_KEY\_ID and AWS\_SECRET\_ACCESS\_KEY.

After the aws cli is installed, go back into the AWS web console, and create an IAM role (not user) with the following privledges:

1. AWSLambdaFullAccess
2. AmazonS3FullAccess

This role will be used by the AWS PHP SDK to create the lambda functions. Once you have created this role, make a note of the ARN, and paste it into the environment file as the value for AWS\_LAMBDA\_IAM\_ARN.

All lamba functions (as of December 2019), must live in the us-east-1 one availability zone, so set that value in the .env file as well.

AWS\_REGION=us-east-1

Finally, set the AWS\_LAMBDA\_VERSION in the .env file to 'latest'.

Background Information.
-----------------------

[](#background-information)

If you aren't familiar with how lambda works, I will take a moment to explain some of the terminology. If you feel comfortable using lambda, please feel free to jump to the [next section](#building-the-layers).

AWS lambda is a service AWS exposes to allow developers to ship code as small units. While a lambda function does not have to consist of single function, as developers, it is often most effective to shift our thinking to this type of arcitecture. When lambda first came out back in 2014, it supported a few langauges, and PHP was not one of them. While it was techincally still possible to execute PHP via process bridge with node, it was very complicated, and the developer experience was, well, shit.

In 2017, AWS announced general avaiabllity of something called the custom runtime API, which allowed developers to execute any programming laugage that was capable of being boostraped within the confinded of the greater lambda rules.

At its core, the lambda service is nothing more than on demand docker container, capable of being spun up with nothing more then an web request being sent to it. These containers are short lived, which means they are not running when they are not executing your program. The pricing model of something like this is whats drawn alot of business's curiosity and eventual adoption of this type of arcitecture.

In addition to this custom runtime api iteself, lambda gives us something called "layers". These layers sit below our actual function code, and allow us, for example, to build up a container in which the php binary is accessible.

Building The Layers
-------------------

[](#building-the-layers)

All of the code necessary to build the runtime and vendor layers exists in the "build" directory. This directory contains the following files:

```
| - bin/
|   - php
| - vendor/
| - bootstrap
| - build.bash
| - composer.json

```

1. `bin/php` - Contains the php 7.3 executable.
2. `bootstrap` - This file is the brain of our program. It handles instructing lambda on how our code should be executed, and is responsible for handling requests from the runtime API to our lambda code. If you would like a more in depth explanation of how (and why) this code works, check out my medium article [here](https://medium.com/@mike_48770/php-and-the-aws-lambda-custom-runtime-part-1-8ad94c622701#c179).
3. `build.bash` - This is a helper script I created to assist zipping up our layer files, and sending them lambda via the aws cli. You are free to alter this script to your needs, or simply run them in a terminal. If you execute the file directly, ensure you have made the file executable - `chmod +x bootstrap`
4. `composer.json` contains the required libraries for our layers. In this case, I have opted to use guzzle instead of native curl, so we have a single library. Note - Do not confuse this composer.json for the composer.json in the root. The composer.json in the build directory is for depencies of the runtime layer only. If you need other libraries for your actual function code, we will define those inside of the `function` directory.

Creating a lambda function
--------------------------

[](#creating-a-lambda-function)

In the root directory of your project, create an index file that we can execute.

```
$ touch index.php && chmod +x index.php
```

Paste the following example code into the newly created index.php file.

```

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 55.6% 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 ~0 days

Total

8

Last Release

2327d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/39c6c5f6028c5cf32766db646290c8b2298292c98fced2dccc2dbd1020970a91?d=identicon)[mmcgrathRSD](/maintainers/mmcgrathRSD)

---

Top Contributors

[![mokeseven7](https://avatars.githubusercontent.com/u/17180620?v=4)](https://github.com/mokeseven7 "mokeseven7 (5 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")

### Embed Badge

![Health badge](/badges/popcorn-lambda/health.svg)

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

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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