Slide 1

Slide 1 text

AWS Lambda in production with Bref PHP Lovers Meetup vol. 0 ~

Slide 2

Slide 2 text

@seike 460 - - @seike 46 0 - Fusic - / - / - - PHP 2018 2022 - PHP 2017 2019 - PHP 2019 2022 - - PHP 2023 - Serverless Days Fukuoka 2019 Co-Chair - JAWS Festa 2023 in Kyushu 2

Slide 3

Slide 3 text

Agenda 1 . 2 .AWS 3 .Bref 4 . 3

Slide 4

Slide 4 text

1

Slide 5

Slide 5 text

AWS Dev Day 2 022 AWS Dev Day 2 02 2 Amazon S 3 Select で バ https://speakerdeck.com/seike 460 /serverless-high-load-site-realized-with-amazon-s 3 -select 5

Slide 6

Slide 6 text

Amazon S 3 Select + AWS Lambda Amazon S 3 Select x AWS lambda ⾒ API CloudFront x S 3 6

Slide 7

Slide 7 text

7

Slide 8

Slide 8 text

8 AWS Fargate API - - - 


Slide 9

Slide 9 text

9 
 
 
 AWS 
 


Slide 10

Slide 10 text

2 AWS

Slide 11

Slide 11 text

JSON 11 
 Amazon RDS JSON AWS IAM Role Assume Role 
 JSON S 3 
 JSON

Slide 12

Slide 12 text

AWS 12 - AWS Lambda - FaaS 
 AWS Lambda PHP

Slide 13

Slide 13 text

AWS 13 - AWS Lambda - FaaS 
 AWS Lambda PHP - API Gateway - AWS Lambda http

Slide 14

Slide 14 text

AWS 14 - AWS Lambda - FaaS 
 AWS Lambda PHP - API Gateway - AWS Lambda http - AWS S 3 Select - CSV JSON Apache Parquet 
 


Slide 15

Slide 15 text

AWS 15 - AWS Lambda - FaaS 
 AWS Lambda PHP - API Gateway - AWS Lambda http - AWS S 3 Select - CSV JSON Apache Parquet 
 
 - CloudFront - AWS CDN 


Slide 16

Slide 16 text

AWS 16 - AWS Lambda - FaaS 
 AWS Lambda PHP - API Gateway - AWS Lambda http - AWS S 3 Select - CSV JSON Apache Parquet 
 
 - CloudFront - AWS CDN 
 - AWS S 3 Hosting - https 
 
 Nginx Apache

Slide 17

Slide 17 text

OSS 17 - Laravel - PHP Web Framework 
 AWS ⾒ 
 - Svelte - Javascript 
 AWS S 3 Hosting -> CloudFront 
 SSG - Bref - @matthieunapoli 
 PHP Serverless

Slide 18

Slide 18 text

Laravel Bref 18 Laravel bref PHP 
 Bref 
 Production Deploy 
 Svelte 2022 バ ド ジ が Svelte + Vite ド https://speakerdeck.com/seike 46 0 /svelte-vite-front-end-construction-by-back-end-engineers

Slide 19

Slide 19 text

3 Bref

Slide 20

Slide 20 text


 
 Developer Community AWS Lambda 
 PHP PHP Deploy 
 PHPer 
 Bref 20 service: app provider: name: aws runtime: provided.al 2 plugins: - ./vendor/bref/bref functions: app: handler: index.php runtime: php- 81 -fpm events: - httpApi: '*' $ composer require bref/bref $ vendor/bin/bref init

Slide 21

Slide 21 text

x Laravel 21 service: laravel provider: name: aws # The AWS region in which to deploy (us-east- 1 is the default) region: us-east- 1 # Environment variables environment: APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stage package: # Files and directories to exclude from deployment patterns: - '!node_modules/**' - '!public/storage' - '!resources/assets/**' - '!storage/**' - '!tests/**' functions: # This function runs the Laravel website/API web: handler: public/index.php runtime: php- 8 1 -fpm timeout: 28 # in seconds (API Gateway has a timeout of 2 9 seconds) events: - httpApi: '*' # This function lets us run artisan commands in Lambda artisan: handler: artisan runtime: php- 8 1 -console timeout: 720 # in seconds # Uncomment to also run the scheduler every minute #events: # - schedule: # rate: rate( 1 minute) # input: '"schedule:run"' plugins: # We need to include the Bref plugin - ./vendor/bref/bref Laravel public/index.php 
 Laravel Serverless Framework 
 $ composer require bref/bref bref/laravel-bridge update-with-dependencies $ php artisan vendor:publish --tag=serverless-config

Slide 22

Slide 22 text

x Laravel 22 service: laravel provider: name: aws # The AWS region in which to deploy (us-east- 1 is the default) region: us-east- 1 # Environment variables environment: APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stage package: # Files and directories to exclude from deployment patterns: - '!node_modules/**' - '!public/storage' - '!resources/assets/**' - '!storage/**' - '!tests/**' functions: # This function runs the Laravel website/API web: handler: public/index.php runtime: php- 81 -fpm timeout: 2 8 # in seconds (API Gateway has a timeout of 29 seconds) events: - httpApi: '*' # This function lets us run artisan commands in Lambda artisan: handler: artisan runtime: php- 81 -console timeout: 7 20 # in seconds # Uncomment to also run the scheduler every minute #events: # - schedule: # rate: rate( 1 minute) # input: '"schedule:run"' plugins: # We need to include the Bref plugin - ./vendor/bref/bref AWS 
 IAM Role Serverless Framework

Slide 23

Slide 23 text

x Laravel 23 service: laravel provider: name: aws # The AWS region in which to deploy (us-east- 1 is the default) region: us-east- 1 # Environment variables environment: APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stage package: # Files and directories to exclude from deployment patterns: - '!node_modules/**' - '!public/storage' - '!resources/assets/**' - '!storage/**' - '!tests/**' functions: # This function runs the Laravel website/API web: handler: public/index.php runtime: php- 81 -fpm timeout: 2 8 # in seconds (API Gateway has a timeout of 29 seconds) events: - httpApi: '*' # This function lets us run artisan commands in Lambda artisan: handler: artisan runtime: php- 81 -console timeout: 7 20 # in seconds # Uncomment to also run the scheduler every minute #events: # - schedule: # rate: rate( 1 minute) # input: '"schedule:run"' plugins: # We need to include the Bref plugin - ./vendor/bref/bref Exclude 
 node_modules tests 
 ⾒

Slide 24

Slide 24 text

x Laravel 24 service: laravel provider: name: aws # The AWS region in which to deploy (us-east- 1 is the default) region: us-east- 1 # Environment variables environment: APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stage package: # Files and directories to exclude from deployment patterns: - '!node_modules/**' - '!public/storage' - '!resources/assets/**' - '!storage/**' - '!tests/**' functions: # This function runs the Laravel website/API web: handler: public/index.php runtime: php- 81 -fpm timeout: 2 8 # in seconds (API Gateway has a timeout of 29 seconds) events: - httpApi: '*' # This function lets us run artisan commands in Lambda artisan: handler: artisan runtime: php- 81 -console timeout: 7 20 # in seconds # Uncomment to also run the scheduler every minute #events: # - schedule: # rate: rate( 1 minute) # input: '"schedule:run"' plugins: # We need to include the Bref plugin - ./vendor/bref/bref Http Laravel API Gateway AWS Lambda 
 Laravel

Slide 25

Slide 25 text

x Laravel 25 service: laravel provider: name: aws # The AWS region in which to deploy (us-east- 1 is the default) region: us-east- 1 # Environment variables environment: APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stage package: # Files and directories to exclude from deployment patterns: - '!node_modules/**' - '!public/storage' - '!resources/assets/**' - '!storage/**' - '!tests/**' functions: # This function runs the Laravel website/API web: handler: public/index.php runtime: php- 81 -fpm timeout: 2 8 # in seconds (API Gateway has a timeout of 29 seconds) events: - httpApi: '*' # This function lets us run artisan commands in Lambda artisan: handler: artisan runtime: php- 81 -console timeout: 7 20 # in seconds # Uncomment to also run the scheduler every minute #events: # - schedule: # rate: rate( 1 minute) # input: '"schedule:run"' plugins: # We need to include the Bref plugin - ./vendor/bref/bref artisan 
 
 Lambda 


Slide 26

Slide 26 text

x Laravel 26 service: laravel provider: name: aws # The AWS region in which to deploy (us-east- 1 is the default) region: us-east- 1 # Environment variables environment: APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stage package: # Files and directories to exclude from deployment patterns: - '!node_modules/**' - '!public/storage' - '!resources/assets/**' - '!storage/**' - '!tests/**' functions: # This function runs the Laravel website/API web: handler: public/index.php runtime: php- 81 -fpm timeout: 2 8 # in seconds (API Gateway has a timeout of 29 seconds) events: - httpApi: '*' # This function lets us run artisan commands in Lambda artisan: handler: artisan runtime: php- 81 -console timeout: 7 20 # in seconds # Uncomment to also run the scheduler every minute #events: # - schedule: # rate: rate( 1 minute) # input: '"schedule:run"' plugins: # We need to include the Bref plugin - ./vendor/bref/bref Serverless Framework 
 
 bref

Slide 27

Slide 27 text

Bref 27 Laravel 
 AWS Lambda 
 
 ⾒ Bref

Slide 28

Slide 28 text

Coverage by Bref 28 AWS 
 


Slide 29

Slide 29 text

Documents 29 AWS 
 ⾒ Documents 
 
 Let me thank you again. Thank you @matthieunapoli & 
 bref Community.

Slide 30

Slide 30 text

php.ini 30 php/conf.d 
 Scan PHP_INI_SCAN_DIR 
 
 ⾒ 


Slide 31

Slide 31 text

Extensions 31 Extensions 
 Load OK extension=intl extension=apcu extension=pdo_pgsql

Slide 32

Slide 32 text

Custom Extensions 32 Extension 
 


Slide 33

Slide 33 text

Laravel AWS 33 PHP Laravel 
 Laravel AWS 
 
 Bref 
 PHPer Cloud Native 


Slide 34

Slide 34 text

34 
 - AWS Lambda - AWS S 3 Select 


Slide 35

Slide 35 text

S 3 Select 35 S 3 Select -> S 3 Select Model 
 
 RDBMS Laravel Model S 3 Select Model

Slide 36

Slide 36 text

S 3 Select 36 RDBMS S 3 Select - Web - - JSON - JSON - - PHP 
 
 Json Join 
 Json

Slide 37

Slide 37 text

37 - - S 3 Select LIKE - AND OR - S 3 Select AND OR - - Json 


Slide 38

Slide 38 text

Lambda 38 - Lambda 6MB - - 
 - UI Field - S 3 Slect

Slide 39

Slide 39 text

S 3 Select 39 S 3 Select Offset SQL Limit Offset PHP 


Slide 40

Slide 40 text

4

Slide 41

Slide 41 text


 
 Ver UP 
 41

Slide 42

Slide 42 text

-> CI/CD 42 -> ⾒

Slide 43

Slide 43 text

っ AWS IAM Fargate っ Branch ⾒ env Push 
 Staging Production GitHub Actions むAWS Lambda Serverless Framework Backend API Bref むAWS CLI Svelte Build Amazon S 3 CloudFront 43

Slide 44

Slide 44 text

44

Slide 45

Slide 45 text

AWS ⾒ 
 AMI AWS Lambda 45

Slide 46

Slide 46 text


 
 
 46

Slide 47

Slide 47 text


 Amazon CloudWatch 500 1000 req/sec 
 47

Slide 48

Slide 48 text


 
 48

Slide 49

Slide 49 text

Bref SaaS Stripe ⾒ 49

Slide 50

Slide 50 text

Stripe DB DB 50

Slide 51

Slide 51 text

PHP x Bref x Laravel Bref PHPer Everything will be Serverless 51

Slide 52

Slide 52 text

Thank You We are Hiring ! https://recruit.fusic.co.jp/