$30 off During Our Annual Pro Sale. View Details »

AWS Lambda in production with Bref

AWS Lambda in production with Bref

PHP Lovers Meetup vol.0 ~ はじまりは

shiro seike
PRO

July 10, 2023
Tweet

More Decks by shiro seike

Other Decks in Programming

Transcript

  1. AWS Lambda in production with Bref
    PHP Lovers Meetup vol.
    0
    ~ 2
    0
    23
    .
    7
    .
    10



    @seike
    4
    60
    1

    View Slide

  2. @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

    View Slide

  3. Agenda
    1
    .


    2
    .AWS


    3
    .Bref


    4
    .
    3

    View Slide

  4. 1

    View Slide

  5. 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

    View Slide

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

    View Slide

  7. 7

    View Slide

  8. 8


    AWS Fargate API




    -


    -


    -




    View Slide

  9. 9






    AWS


    View Slide

  10. 2
    AWS

    View Slide

  11. JSON
    11 

    Amazon RDS JSON


    AWS IAM Role Assume Role


    JSON S
    3 

    JSON

    View Slide

  12. AWS
    12
    - AWS Lambda


    - FaaS

    AWS Lambda PHP

    View Slide

  13. AWS
    13
    - AWS Lambda


    - FaaS

    AWS Lambda PHP


    - API Gateway


    - AWS Lambda http


    View Slide

  14. AWS
    14
    - AWS Lambda


    - FaaS

    AWS Lambda PHP


    - API Gateway


    - AWS Lambda http


    - AWS S
    3
    Select


    - CSV JSON Apache Parquet
    
 



    View Slide

  15. AWS
    15
    - AWS Lambda


    - FaaS

    AWS Lambda PHP


    - API Gateway


    - AWS Lambda http


    - AWS S
    3
    Select


    - CSV JSON Apache Parquet
    
 



    - CloudFront


    - AWS CDN

    View Slide

  16. 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

    View Slide

  17. OSS
    17
    - Laravel


    - PHP Web Framework

    AWS ⾒


    - Svelte


    - Javascript

    AWS S
    3
    Hosting -> CloudFront

    SSG


    - Bref


    - @matthieunapoli

    PHP Serverless

    View Slide

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

    View Slide

  19. 3
    Bref

    View Slide



  20. 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

    View Slide

  21. 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

    View Slide

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

    View Slide

  23. 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


    View Slide

  24. 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

    View Slide

  25. 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

    View Slide

  26. 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

    View Slide

  27. Bref
    27
    Laravel



    AWS Lambda
    
 


    ⾒ Bref

    View Slide

  28. Coverage by Bref
    28

    AWS




    View Slide

  29. Documents
    29
    AWS




    Documents


    Let me thank you again.


    Thank you @matthieunapoli &

    bref Community.

    View Slide

  30. php.ini
    30
    php/conf.d

    Scan


    PHP_INI_SCAN_DIR




    View Slide

  31. Extensions
    31
    Extensions

    Load OK


    extension=intl


    extension=apcu


    extension=pdo_pgsql

    View Slide

  32. Custom Extensions
    32
    Extension


    
 


    View Slide

  33. Laravel AWS
    33
    PHP




    Laravel

    Laravel AWS


    Bref

    PHPer Cloud Native

    View Slide

  34. 34 

    - AWS Lambda


    - AWS S
    3
    Select


    View Slide

  35. S
    3
    Select
    35
    S
    3
    Select


    -> S
    3
    Select Model


    RDBMS Laravel Model

    S
    3
    Select Model


    View Slide

  36. S
    3
    Select
    36
    RDBMS

    S
    3
    Select


    - Web


    -


    - JSON


    - JSON


    -


    - PHP


    Json Join

    Json


    View Slide

  37. 37
    -


    - S
    3
    Select LIKE


    - AND OR


    - S
    3
    Select AND OR


    -


    - Json



    View Slide

  38. Lambda
    38
    - Lambda 6MB


    -


    -


    - UI Field


    - S
    3
    Slect

    View Slide

  39. S
    3
    Select
    39
    S
    3
    Select Offset SQL


    Limit Offset PHP

    View Slide

  40. 4

    View Slide








  41. Ver UP

    41

    View Slide

  42. -> CI/CD
    42
    -> ⾒


    View Slide




  43. 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

    View Slide





  44. 44

    View Slide

  45. AWS ⾒



    AMI


    AWS Lambda


    45

    View Slide









  46. 
 

    46

    View Slide


  47. Amazon CloudWatch 500 1000 req/sec



    47

    View Slide




  48. 48

    View Slide

  49. Bref


    SaaS Stripe ⾒


    49

    View Slide

  50. Stripe DB


    DB



    50

    View Slide



  51. PHP x Bref x Laravel


    Bref PHPer
    Everything will be Serverless
    51

    View Slide

  52. Thank You
    We are Hiring !


    https://recruit.fusic.co.jp/

    View Slide