PHP Lovers Meetup vol.0 ~ はじまりは
AWS Lambda in production with BrefPHP Lovers Meetup vol.0~ 2023.7.10@seike4601
View Slide
@seike460-- @seike460- Fusic- /- /-- PHP 2018 2022- PHP 2017 2019- PHP 2019 2022-- PHP 2023- Serverless Days Fukuoka2019Co-Chair- JAWS Festa2023in Kyushu2
Agenda1.2.AWS3.Bref4.3
1
AWS Dev Day2 022AWS Dev Day2 02 2 Amazon S3Selectで バ https://speakerdeck.com/seike460/serverless-high-load-site-realized-with-amazon-s3-select5
Amazon S3Select + AWS LambdaAmazon S3Select x AWS lambda ⾒ APICloudFront x S36
7
8 AWS Fargate API---
9 AWS
2AWS
JSON11 Amazon RDS JSONAWS IAM Role Assume Role JSON S3 JSON
AWS12- AWS Lambda- FaaS AWS Lambda PHP
AWS13- AWS Lambda- FaaS AWS Lambda PHP- API Gateway- AWS Lambda http
AWS14- AWS Lambda- FaaS AWS Lambda PHP- API Gateway- AWS Lambda http- AWS S3Select- CSV JSON Apache Parquet
AWS15- AWS Lambda- FaaS AWS Lambda PHP- API Gateway- AWS Lambda http- AWS S3Select- CSV JSON Apache Parquet - CloudFront- AWS CDN
AWS16- AWS Lambda- FaaS AWS Lambda PHP- API Gateway- AWS Lambda http- AWS S3Select- CSV JSON Apache Parquet - CloudFront- AWS CDN - AWS S3Hosting- https Nginx Apache
OSS17- Laravel- PHP Web Framework AWS ⾒ - Svelte- Javascript AWS S3Hosting -> CloudFront SSG- Bref- @matthieunapoli PHP Serverless
Laravel Bref18Laravel brefPHP Bref Production Deploy Svelte2022バ ド ジ がSvelte + Viteド https://speakerdeck.com/seike460/svelte-vite-front-end-construction-by-back-end-engineers
3Bref
Developer CommunityAWS Lambda PHPPHP Deploy PHPer Bref20service: appprovider:name: awsruntime: provided.al2plugins:- ./vendor/bref/breffunctions:app:handler: index.phpruntime: php-81-fpmevents:- httpApi: '*'$ composer require bref/bref$ vendor/bin/bref init
x Laravel21service: laravelprovider:name: aws# The AWS region in which to deploy (us-east-1is the default)region: us-east-1# Environment variablesenvironment:APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stagepackage:# Files and directories to exclude from deploymentpatterns:- '!node_modules/**'- '!public/storage'- '!resources/assets/**'- '!storage/**'- '!tests/**'functions:# This function runs the Laravel website/APIweb:handler: public/index.phpruntime: php-81-fpmtimeout:28# in seconds (API Gateway has a timeout of29seconds)events:- httpApi: '*'# This function lets us run artisan commands in Lambdaartisan:handler: artisanruntime: php-81-consoletimeout:720# in seconds# Uncomment to also run the scheduler every minute#events:# - schedule:# rate: rate(1minute)# input: '"schedule:run"'plugins:# We need to include the Bref plugin- ./vendor/bref/brefLaravel public/index.php Laravel Serverless Framework $ composer require bref/bref bref/laravel-bridge update-with-dependencies$ php artisan vendor:publish --tag=serverless-config
x Laravel22service: laravelprovider:name: aws# The AWS region in which to deploy (us-east-1is the default)region: us-east-1# Environment variablesenvironment:APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stagepackage:# Files and directories to exclude from deploymentpatterns:- '!node_modules/**'- '!public/storage'- '!resources/assets/**'- '!storage/**'- '!tests/**'functions:# This function runs the Laravel website/APIweb:handler: public/index.phpruntime: php-81-fpmtimeout:2 8# in seconds (API Gateway has a timeout of29seconds)events:- httpApi: '*'# This function lets us run artisan commands in Lambdaartisan:handler: artisanruntime: php-81-consoletimeout:7 20# in seconds# Uncomment to also run the scheduler every minute#events:# - schedule:# rate: rate(1minute)# input: '"schedule:run"'plugins:# We need to include the Bref plugin- ./vendor/bref/brefAWS IAM RoleServerless Framework
x Laravel23service: laravelprovider:name: aws# The AWS region in which to deploy (us-east-1is the default)region: us-east-1# Environment variablesenvironment:APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stagepackage:# Files and directories to exclude from deploymentpatterns:- '!node_modules/**'- '!public/storage'- '!resources/assets/**'- '!storage/**'- '!tests/**'functions:# This function runs the Laravel website/APIweb:handler: public/index.phpruntime: php-81-fpmtimeout:2 8# in seconds (API Gateway has a timeout of29seconds)events:- httpApi: '*'# This function lets us run artisan commands in Lambdaartisan:handler: artisanruntime: php-81-consoletimeout:7 20# in seconds# Uncomment to also run the scheduler every minute#events:# - schedule:# rate: rate(1minute)# input: '"schedule:run"'plugins:# We need to include the Bref plugin- ./vendor/bref/brefExclude node_modules tests ⾒
x Laravel24service: laravelprovider:name: aws# The AWS region in which to deploy (us-east-1is the default)region: us-east-1# Environment variablesenvironment:APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stagepackage:# Files and directories to exclude from deploymentpatterns:- '!node_modules/**'- '!public/storage'- '!resources/assets/**'- '!storage/**'- '!tests/**'functions:# This function runs the Laravel website/APIweb:handler: public/index.phpruntime: php-81-fpmtimeout:2 8# in seconds (API Gateway has a timeout of29seconds)events:- httpApi: '*'# This function lets us run artisan commands in Lambdaartisan:handler: artisanruntime: php-81-consoletimeout:7 20# in seconds# Uncomment to also run the scheduler every minute#events:# - schedule:# rate: rate(1minute)# input: '"schedule:run"'plugins:# We need to include the Bref plugin- ./vendor/bref/brefHttp LaravelAPI Gateway AWS Lambda Laravel
x Laravel25service: laravelprovider:name: aws# The AWS region in which to deploy (us-east-1is the default)region: us-east-1# Environment variablesenvironment:APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stagepackage:# Files and directories to exclude from deploymentpatterns:- '!node_modules/**'- '!public/storage'- '!resources/assets/**'- '!storage/**'- '!tests/**'functions:# This function runs the Laravel website/APIweb:handler: public/index.phpruntime: php-81-fpmtimeout:2 8# in seconds (API Gateway has a timeout of29seconds)events:- httpApi: '*'# This function lets us run artisan commands in Lambdaartisan:handler: artisanruntime: php-81-consoletimeout:7 20# in seconds# Uncomment to also run the scheduler every minute#events:# - schedule:# rate: rate(1minute)# input: '"schedule:run"'plugins:# We need to include the Bref plugin- ./vendor/bref/brefartisan Lambda
x Laravel26service: laravelprovider:name: aws# The AWS region in which to deploy (us-east-1is the default)region: us-east-1# Environment variablesenvironment:APP_ENV: production # Or use ${sls:stage} if you want the environment to match the stagepackage:# Files and directories to exclude from deploymentpatterns:- '!node_modules/**'- '!public/storage'- '!resources/assets/**'- '!storage/**'- '!tests/**'functions:# This function runs the Laravel website/APIweb:handler: public/index.phpruntime: php-81-fpmtimeout:2 8# in seconds (API Gateway has a timeout of29seconds)events:- httpApi: '*'# This function lets us run artisan commands in Lambdaartisan:handler: artisanruntime: php-81-consoletimeout:7 20# in seconds# Uncomment to also run the scheduler every minute#events:# - schedule:# rate: rate(1minute)# input: '"schedule:run"'plugins:# We need to include the Bref plugin- ./vendor/bref/brefServerless Framework bref
Bref27Laravel AWS Lambda ⾒ Bref
Coverage by Bref28 AWS
Documents29AWS ⾒Documents Let me thank you again.Thank you @matthieunapoli & bref Community.
php.ini30php/conf.d ScanPHP_INI_SCAN_DIR ⾒
Extensions31Extensions Load OKextension=intlextension=apcuextension=pdo_pgsql
Custom Extensions32Extension
Laravel AWS33PHPLaravel Laravel AWS Bref PHPer Cloud Native
34 - AWS Lambda- AWS S3Select
S3Select35S3Select-> S3Select Model RDBMS Laravel ModelS3Select Model
S3Select36RDBMSS3Select- Web-- JSON- JSON-- PHP Json Join Json
37-- S3Select LIKE- AND OR- S3Select AND OR-- Json
Lambda38- Lambda 6MB-- - UI Field- S3Slect
S3Select39 S3Select Offset SQLLimit Offset PHP
4
Ver UP 41
-> CI/CD42-> ⾒
っAWS IAM FargateっBranch ⾒ env Push Staging Production GitHub ActionsむAWS LambdaServerless Framework Backend API BrefむAWS CLISvelte Build Amazon S3CloudFront43
44
AWS ⾒ AMIAWS Lambda45
46
Amazon CloudWatch 500 1000 req/sec 47
48
BrefSaaS Stripe ⾒49
Stripe DBDB 50
PHP x Bref x LaravelBref PHPerEverything will be Serverless51
Thank YouWe are Hiring !https://recruit.fusic.co.jp/