Milan Felix Šulc
📦 Package maker • 👷 Architect ModernTV • 🐘 PHP enthusiast • 💿 Multimedia engineer • 👨👩👧👦 Father • ☕️ Coffee-based
Deep Dive Into Serverless
@xf3l1x
f3l1x.io
01.10.2021
Server
🌴🌲🎄🌲🏝
AWS Lambda
run code without managing servers
lambda allocates execution power
run code with zero administration
exports.handler = function(event, context) {
return {
statusCode: 200,
body: "Hello PHPlive!"
}
}
exports.handler = function(event, context) {
return {
statusCode: 200,
body: "Hello PHPlive!"
}
}
$ zip function.zip index.js
$ aws lambda \
update-function-code \
--function-name my-function \
--zip-file fileb://function.zip
exports.handler = function(event, context) {
return {
statusCode: 200,
body: "Hello PHPlive!"
}
}
AWS CONSOLE
AWS CLI
AWS API GATEWAY
AWS PERMISSIONS
exports.handler = function(event, context) {
return {
statusCode: 200,
body: "Hello PHPlive!"
}
}
$ serverless deploy
exports.handler = function(event, context) {
return {
statusCode: 200,
body: "Hello PHPlive!"
}
}
service: serverless-http-api
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs12.x
lambdaHashingVersion: '20201221'
functions:
hello:
handler: handler.hello
events:
- httpApi:
path: /
method: get
$ magic
<?php declare(strict_types = 1);
echo "Hello PHPlive!";
USER
PHP LAMBDA
😱
$ vercel
<?php declare(strict_types = 1);
echo "Hello PHPlive!";
<?php declare(strict_types = 1);
echo "Hello PHPlive!";
CUSTOM DOMAINS
INTEGRATIONS
GIT (HUB/LAB)
PREVIEW URL
HTTPS
CDN
MULTILANG
FREE TIER
DX / UX
$ vercel
vercel-php
interface Runtime {
version: number;
build: (options: BuildOptions) => Promise<BuildResult>;
analyze?: (options: AnalyzeOptions) => Promise<string>;
prepareCache?: (options: PrepareCacheOptions) => Promise<CacheOutputs>;
shouldServe?: (options: ShouldServeOptions) => Promise<boolean>;
startDevServer?: (
options: StartDevServerOptions
) => Promise<StartDevServerResult>;
}
{ CODE }
{ CODE }
▲ RUNTIME
▲ BUILD
site
├── index.html
├── index.php
├── package.json
└── vercel.json
{
"builds": [{
"src": "index.php",
"use": "vercel-php"
}]
}
$ vercel
builder1.build(ctx)
index.html dist/main.css dist/app.js
/api/users /api/comments
STATIC FILES
LAMBDAS
builderN.build(ctx)
VERCEL SIDE
VERCEL
VERCEL-PHP
build
COMPOSER
INSTALL
COMPOSER
SCRIPTS
CUSTOM
PHP.INI
test
test
test
SETUP
USER FILES
PHP FILES
LAUNCHER
test
test
COLLECT
LAMBDA
LAUNCHER
ENV
test
test
CREATE
CACHE
VERCEL
VERCEL-PHP
build
COMPOSER
INSTALL
COMPOSER
SCRIPTS
CUSTOM
PHP.INI
test
test
test
SETUP
USER FILES
PHP FILES
LAUNCHER
test
test
COLLECT
LAMBDA
LAUNCHER
ENV
test
test
CREATE
CACHE
VERCEL
VERCEL-PHP
build
COMPOSER
INSTALL
COMPOSER
SCRIPTS
CUSTOM
PHP.INI
test
test
test
SETUP
USER FILES
PHP FILES
LAUNCHER
test
test
COLLECT
LAMBDA
LAUNCHER
ENV
test
test
CREATE
CACHE
VERCEL
VERCEL-PHP
build
COMPOSER
INSTALL
COMPOSER
SCRIPTS
CUSTOM
PHP.INI
test
test
test
SETUP
USER FILES
PHP FILES
LAUNCHER
test
test
COLLECT
LAMBDA
LAUNCHER
ENV
test
test
CREATE
CACHE
VERCEL
VERCEL-PHP
build
AWS SIDE
CLIENT
VERCEL-PHP
request
AWS
LAMBDA
LAUNCHER
PHP SERVER
start
response
request
request
response
CLIENT
VERCEL-PHP
request
dag:
endpoints:
/api/v1/users:
generator: alice
data:
schema:
stdClass:
"user{1..10}":
name: "<firstName()>"
surname: "<lastName()>"
email: "<email()>"
role: "<jobTitle()>"
createdAt: "<date_create()>"
lastLoggedAt: "<date_create()>"
{
"user1": {
"name": "Adah",
"surname": "Reichel",
"email": "sstroman@hotmail.com",
"role": "Skin Care Specialist",
"createdAt": {
"date": "2021-09-29 13:33:11.962499",
"timezone_type": 3,
"timezone": "UTC"
},
"lastLoggedAt": {
"date": "2021-09-29 13:33:11.962513",
"timezone_type": 3,
"timezone": "UTC"
}
}
}
USE CASES
database, SMTP, websockets, 3rd party webservices, ...
new stuff
challenge
learn sth
have fun
@xf3l1x
f3l1x.io
By Milan Felix Šulc
📦 Package maker • 👷 Architect ModernTV • 🐘 PHP enthusiast • 💿 Multimedia engineer • 👨👩👧👦 Father • ☕️ Coffee-based