The document discusses serverless computing and how to run PHP applications on AWS Lambda. It introduces serverless concepts and key AWS Lambda services. It then demonstrates how to deploy a PHP application to AWS Lambda using the Bref framework, which compiles PHP into a Lambda layer. Examples are provided for simple PHP Lambda functions and for deploying a Symfony app. The document shows how to package and deploy the PHP code to Lambda using the AWS Serverless Application Model (SAM).
2. Globalcode – Open4education
gitlab.com/pvgomes
Paulo Victor Gomes - pvgomes
Tech Lead at Z-Tech - AB
Inbev/AmBev
@_pvgomes
former CTO at Mundo Verde and Natue, former software
engineering at Dafiti, Kanui, Tricae and Rocket Internet
github.com/pvgomes
pvgomes
3. Globalcode – Open4education
What is Serverless?
Serverless Computing still uses servers, but
you no longer have to worry about managing
them
7. Globalcode – Open4education
Key Features and Benefits
● No Server Management
● Easy & Efficient Scaling
● Built in High Availability and Fault Tolerance
8. Globalcode – Open4education
Key Features and Benefits
● No Server Management
● Easy & Efficient Scaling
● Built in High Availability and Fault Tolerance
● Service Integration
9. Globalcode – Open4education
Key Features and Benefits
● No Server Management
● Easy & Efficient Scaling
● Built in High Availability and Fault Tolerance
● Service Integration
● Pay as you Go
42. Globalcode – Open4education
Create your functions
Install using composer
Init a sample function
<?php
function handler($event)
{
return "Hello, {$event['name']}!";
}
49. Globalcode – Open4education
Bref Installation
Install using composer
Init a sample function
Install Bref
composer require bref/bref:0.4.1
Init a sample function
vendor/bin/bref init
52. Globalcode – Open4education
template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: ''
Resources:
TdcFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: 'tdc-function'
Description: ''
CodeUri: .
Handler: index.php
Timeout: 30 # in seconds (API Gateway has a timeout of 30 seconds)
MemorySize: 1024 # The memory size is related to the pricing and CPU power
Runtime: provided
Layers:
- 'arn:aws:lambda:us-east-1:209497400698:layer:php-73-fpm:7'
53. Globalcode – Open4education
template.yaml - events
...
Events:
# The function will match all HTTP URLs
HttpRoot:
Type: Api
Properties:
Path: /
Method: ANY
HttpSubPaths:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
76. Globalcode – Open4education
Bref new features - 0.5.0
Bref now recommends Serverless instead of SAM
Changes: https://github.com/brefphp/bref/releases/tag/0.5.0