Upgrade to Pro — share decks privately, control downloads, hide ads and more …

アンチパターンに踏み込む -作って理解するサーバーレスPHPフレームワーク / Stepping into anti-patterns -Serverless PHP frameworks to build and understand -.

アンチパターンに踏み込む -作って理解するサーバーレスPHPフレームワーク / Stepping into anti-patterns -Serverless PHP frameworks to build and understand -.

shiro seike

October 07, 2023
Tweet

More Decks by shiro seike

Other Decks in Programming

Transcript

  1. PHP Conference Japan
    2 0
    23
    2
    0
    23
    .
    10
    .
    8
    @seike
    4
    60
    1
    - PHP -

    View full-size slide

  2. 自己
    @seike
    46
    0
    -
    - @seike
    46
    0
    - AWS Community Builder Serverless
    - Fusic
    - /

    - /
    -
    - PHP
    - PHP
    - PHP
    -
    - Fukuoka.php
    - PHP 2023
    行 長
    2

    View full-size slide

  3. Agenda
    1
    .AWS Lambda
    2
    .Web AWS Lambda
    3
    .

    4
    .
    自 用
    5
    .
    小 方 用
    6
    .
    3

    View full-size slide

  4. 01
    AWS Lambda

    View full-size slide

  5. AWS Lambda
    AWS


    用 支
    5

    View full-size slide

  6. AWS Lambda

    Lambda

    行 生
    小 小
    行 小
    Lambda
    行 長 行
    VPC
    力 用
    ⾒ Lambda VPC

    VPC Lambda
    行 生

    Lambda SecretManager

    AWS CloudWatch Logs CloudWatch Metrics

    Lambda
    6

    View full-size slide

  7. 02
    Web AWS Lambda

    View full-size slide

  8. Bref
    Bref PHP OSS

    AWS Lambda PHP
    AWS Lambda PHP
    PHP

    PHP

    Bref PHP
    PHP
     
    AWS Lambda

    Developer Community
     
    Laravel Symfony

    PHP
     
    CLI
    8

    View full-size slide

  9. Developer Community
    AWS Lambda
    PHP

    PHP
    PHPer

    Bref
    Serverless Framework

    9
    service: app-php-serverless
    provider:
    name: aws
    region: ap-northeast-
    1
    plugins:
    - ./vendor/bref/bref
    functions:
    api:
    handler: index.php
    description: ''
    runtime: php-
    8
    2
    -fpm
    timeout:
    28
    events:
    - httpApi: '*'
    # Exclude files from deployment
    package:
    patterns:
    - '!node_modules/**'
    - '!tests/**'
    $ composer require bref/bref
    $ vendor/bin/bref init
    $ serverless deploy

    View full-size slide

  10. 10
    Bref AWS Lambda API Gateway

    Bref API Gateway AWS Lambda
    Bref Laravel Bridge Laravel
    Bref Lambda

    View full-size slide

  11. AWS Lambda PHP Bref by
    11

    View full-size slide

  12. Laravel Bref
    12
    Laravel Bref PHP

    AWS Lambda PHP

    AWS Lambda
    AWS Lambda Laravel
    PHPer

    View full-size slide

  13. AWS Lambda
    14 小
    Lambda

    行 生 大
    小 小   入
    行 小
    Lambda
    行 長 行
    PHP

    VPC
    力 用
    ⾒ Lambda VPC

    VPC Lambda
    行 生

    Lambda SecretManager

    AWS CloudWatch Logs CloudWatch Metrics

    Lambda

    View full-size slide

  14. Lambda
    Amazon Web Services Operating Lambda:

    Part
    3
    -Lambda
    -
    -
    小 用
    -
    -
    -
    -

    -
    15
    URL:https://aws.amazon.com/jp/blogs/news/compute-operating-lambda-anti-patterns-in-event-driven-architectures-part-
    3
    /
    Operating Lambda:

    Part
    3

    View full-size slide

  15. Point
    目 入

    View full-size slide


  16. Laravel

    言 用 力
    生 行 生
    力 生 高

    Laravel

    文 文
    Laravel Web
    言 文 非 文
    20

    View full-size slide

  17. PHP AWS Lambda
    PHP

    2018
    PHP Conference
    201
    9
    AWS Lambda PHP
    21

    View full-size slide

  18. 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
    22

    View full-size slide

  19. AWS Lambda x Bref x Laravel
    23 用 大

    - AWS Lambda
    - AWS S
    3
    Select
    - S
    3
    JSON SQL

    大 行
    PHP AWS Lambda
    行 一

    Laravel

    View full-size slide

  20. AWS Lambda x Bref x Laravel

    24
    Web
    AWS Lambda Bref Laravel ⾒

    0
    Laravel Laravel


    Laravel

    AWS ⾒

    View full-size slide

  21. Point
    AWS Lambda

    View full-size slide


  22.   用
    26

    View full-size slide

  23. 用 立

    27 用

    View full-size slide

  24. AWS ⾒
    AWS Lambda

    28

    View full-size slide


  25. 心 用
    非 大
    29

    View full-size slide

  26. Laravel
    30
    Web
    非 高
    AWS Lambda
      用
      文 入
    Laravel

    View full-size slide

  27. Web AWS Lambda
    一見 二
     
    AWS Lambda
     
     
     
      用 一
    31

    View full-size slide

  28. ChatGPT

    ORM
    ・ ・ ・
    API

    RESTful API
    GraphQL
    HTTP
    34
    CI/CD ⾒
    API ⾒
    Webhook
    OAuth
    (RBAC)
    API
    (XSS)
    (CSRF)
    SQL
    (CSP)
    HTTPS/SSL
    (SSO)

    View full-size slide

  29. @o
    0
    h_
    36
    URL https://speakerdeck.com/o
    0
    h/phperkaigi-
    20 23

    View full-size slide

  30. Request GET POST URL
    Router URL
    Response
    DbManager DBRepository
    DbRepository
    Controller

    View

    Session
    Application
    ClassLoader

    PHP P.
    202
    38

    View full-size slide

  31. Request
    Router
    Response
    DbManager
    DbRepository
    Controller
    View
    Session
    Application
    ClassLoader
    PHP P.
    202
    39

    View full-size slide

  32. API Gateway
    40
    - Client Cognito ID
    - Client ID API Gateway Request
    - API Gateway Authorizer Cognito
    - API

    API Gateway
    CORS

    View full-size slide

  33. DB
    Request
    Router
    Response
    Controller
    Application
    ClassLoader
    41

    View full-size slide

  34. Model

    42
    URL https://speakerdeck.com/seike
    4 6
    0
    /aws-lambda-in-production-with-bref

    View full-size slide

  35. Model

    43
    URL https://speakerdeck.com/seike
    4 6
    0
    /aws-lambda-in-production-with-bref

    View full-size slide

  36. DynamoDB

    44
    URL https://github.com/baopham/laravel-dynamodb

    View full-size slide

  37. 46
    ├ ─ ─
    ThinApiApplication.php
    ├ ─ ─
    bootstrap.php
    ├ ─ ─
    composer.json
    ├ ─ ─
    composer.lock
    ├ ─ ─
    controllers
    │ └ ─ ─
    ApiController.php
    ├ ─ ─
    core
    │ ├ ─ ─
    Application.php
    │ ├ ─ ─
    ClassLoader.php
    │ ├ ─ ─
    Controller.php
    │ ├ ─ ─
    HttpNotFoundException.php
    │ ├ ─ ─
    Request.php
    │ ├ ─ ─
    Response.php
    │ └ ─ ─
    Router.php
    ├ ─ ─
    serverless.yml
    └ ─ ─
    web
    └ ─ ─
    index.php
    API ThinApiApplication
    比 行

    非 小

    View full-size slide

  38. web/index.php
    47
    serverless.yml
    handler web/index.php

    View full-size slide

  39. bootstrap.php
    48
    bootstrap
    Model
    core registerDir
    ClassLoader

    View full-size slide

  40. core/ClassLoader.php
    49
    ClassLoader
    spl_autoload_register

    View full-size slide

  41. web/index.php
    50
    ThinApiApplication
    Application
    Core

    Application
    ThinApiApplication->run();

    View full-size slide

  42. ThinApiApplication.php
    51
    ThinApiApplication
    Routing
    Application run
    DB


    configure

    View full-size slide

  43. Application
    52
    run Router

    runAction

    response

    View full-size slide

  44. Application
    53
    run Router

    runAction

    response

    View full-size slide

  45. Response
    54
    Response
    Response send
    Client
    Core

    Application

    View full-size slide

  46. ApiController
    55
    ApiController

    API
    ThinApi

    View full-size slide

  47. deploy

    56
    Deploying app-bref-thin to stage dev (ap-northeast-1)
    ✔ Service deployed to stack app-bref-thin-dev (28s)
    endpoint: ANY - https://zzzzzzzzzz.execute-api.ap-northeast-1.amazonaws.com
    functions:
    api: app-bref-thin-dev-api (275 kB)
    Want a better experience than the AWS console? Try out https://dashboard.bref.sh
    28
    27 5
    kB

    View full-size slide

  48. deploy Laravel
    57
    Deploying bref-laravel to stage dev (ap-northeast-1)
    ✔ Service deployed to stack bref-laravel-dev (52s)
    endpoint: ANY - https://yyyyyyyyyy.execute-api.ap-northeast-1.amazonaws.com
    functions:
    web: bref-laravel-dev-web (32 MB)
    artisan: bref-laravel-dev-artisan (32 MB)
    Want a better experience than the AWS console? Try out https://dashboard.bref.sh
    28 -> 52
    275kB ->
    3 2
    M
    Laravel



    View full-size slide

  49. [#/sec]

    58
    Requests per second: 285.36 [#/sec] (mean)
    Requests per second: 347.26 [#/sec] (mean)
    Requests per second: 328.23 [#/sec] (mean)
    EC
    2
    Apache Bench
    347
    .
    26
    [#/sec]
    Response index.php 351.97[#/sec]
    3

    View full-size slide

  50. [#/sec] Laravel
    59
    $ ab -n 20000 -c 10 https://yyyyyyyyyy.execute-api.ap-northeast-1.amazonaws.com/
    ~
    Requests per second: 295.31 [#/sec] (mean)
    Requests per second: 303.91 [#/sec] (mean)
    Requests per second: 307.67 [#/sec] (mean)
    ~
    EC
    2
    Apache Bench
    347
    .
    26
    [#/sec] ->
    307
    .
    67
    [#/sec]
    Laravel

    3

    View full-size slide

  51. Web


     手
    Laravel
    Web
     
      用 一
     
    60

    View full-size slide

  52. Point
    Monolith First Serverless Development

    View full-size slide

  53. Monolith First Serverless Development
    62
    URL : https://speakerdeck.com/_kensh/monolith-first-serverless-development?slide=
    55
    @_kensh
    Monolith First Serverless Development

    View full-size slide


  54. Role
    APIGateway ⾒

    63
    functions:
    web:
    handler: public/index.php
    runtime: php-
    82
    -fpm
    timeout:
    28
    events:
    - httpApi: '*'
    admin-web:
    handler: public/index.php
    runtime: php-
    82
    -fpm
    timeout:
    28
    role: api-admin-role
    events:
    - httpApi:
    method: '*'
    path: /admin
    $ serverless deploy function --function admin-web
    Deploying function admin-web to stage dev (ap-northeast-
    1
    )
    ✔ Function code deployed (
    42
    s)
    Function configuration did not change, and the update was skipped. If you made changes to the service configuration and expected them to be
    deployed, it most likely means that they can only be applied with a full service deployment. (
    42
    s)

    View full-size slide

  55. Lambda Web Adapter
    Bref ⾒
    Lambda Web Adapter
    Parse
    HTTP
    HTTP
    64

    View full-size slide

  56. Lambda Web Adapter
    65

    View full-size slide

  57. Amazon Web Services - Labs OSS
    Amazon Web Services Labs
    OSS

    OSS
    自 用

    Runtime
    Bref

    66

    View full-size slide

  58. 05
    小 方 用

    View full-size slide



  59.  
    :

     
    :
      用
    :
     
    :

     
    : AWS
    68

    View full-size slide



  60.  
    :

     
    :
      用
    :
     
    :

     
    : AWS
    69

    View full-size slide



  61.  
    :

     
    :
      用
    :
     
    :

     
    : AWS
    70

    View full-size slide

  62. Web

    Laravel
    71

    View full-size slide

  63. 72 入 目 用
    Point
    1 力
    Point
    2
    Monolith First Serverless Development

    Laravel
    Point
    3
    方 小
    Laravel
    Point
    4

    View full-size slide

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

    View full-size slide