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

AWS Lambda in production with Bref

AWS Lambda in production with Bref

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

Avatar for shiro seike

shiro seike

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 ~ <?php 2 0 23 . 7 . 10 @seike 4 60 1
  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
  3. 1

  4. 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
  5. Amazon S 3 Select + AWS Lambda Amazon S 3

    Select x AWS lambda ⾒ API CloudFront x S 3 6
  6. 7

  7. AWS 13 - AWS Lambda - FaaS 
 AWS Lambda

    PHP - API Gateway - AWS Lambda http
  8. AWS 14 - AWS Lambda - FaaS 
 AWS Lambda

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

  9. AWS 15 - AWS Lambda - FaaS 
 AWS Lambda

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

  10. 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
  11. OSS 17 - Laravel - PHP Web Framework 
 AWS

    ⾒ 
 - Svelte - Javascript 
 AWS S 3 Hosting -> CloudFront 
 SSG - Bref - @matthieunapoli 
 PHP Serverless
  12. 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
  13. 
 
 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
  14. 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
  15. 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
  16. 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 
 ⾒
  17. 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
  18. 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 

  19. 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
  20. Documents 29 AWS 
 ⾒ Documents 
 
 Let me

    thank you again. Thank you @matthieunapoli & 
 bref Community.
  21. Laravel AWS 33 PHP Laravel 
 Laravel AWS 
 


    Bref 
 PHPer Cloud Native 

  22. S 3 Select 35 S 3 Select -> S 3

    Select Model 
 
 RDBMS Laravel Model S 3 Select Model
  23. S 3 Select 36 RDBMS S 3 Select - Web

    - - JSON - JSON - - PHP 
 
 Json Join 
 Json
  24. 37 - - S 3 Select LIKE - AND OR

    - S 3 Select AND OR - - Json 

  25. 4

  26. っ 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
  27. 44