Home
Slides
Blog
slide.seike460.com
Home
Slides
Blog
Home
Slides
CakeFest 2019
CakeFest 2019
CakeFest 2019
2019年10月7日
PHP
CakePHP
PHP
Framework
Keyboard Shortcuts
←
→
Navigate slides
Space
Next slide
F
Fullscreen
ESC
Exit fullscreen
Home
First slide
End
Last slide
B
.
Pause
S
Speaker notes
?
Reveal.js help
Close
## bref PHP CakeFest 2019 Shiro Seike(@seike460)
# Who? ###### Fusic Co., Ltd.  ###### Shiro Seike ([@seike460](https://twitter.com/seike460))  ###### Backend (CakePHP、Go)
# Today's Talk - PHP on AWS Lambda - bref
## PHP on AWS Lambda
# PHP on AWS Lambda - PHP is not standard supported by AWS Lambda. - Use a custom runtime - Custom runtime runs in standard Lambda execution environment - Overlap PHP Runtime
- Let's try it!
# stackery/php-lambda-layer [stackery/php-lambda-layer](https://github.com/stackery/php-lambda-layer) Thanks for sharing the deployment method!
# bootstrap function entry point. [bootstrap](https://raw.githubusercontent.com/stackery/php-lambda-layer/master/bootstrap)
# build.sh PHP Layers Build ```bash #!/bin/bash yum install -y php71-mbstring.x86_64 zip php71-pgsql php71-mysqli mkdir /tmp/layer cd /tmp/layer cp /opt/layer/bootstrap . sed "s/PHP_MINOR_VERSION/1/g" /opt/layer/php.ini >php.ini mkdir bin cp /usr/bin/php bin/ mkdir lib for lib in libncurses.so.5 libtinfo.so.5 libpcre.so.0; do cp "/lib64/${lib}" lib/ done cp /usr/lib64/libedit.so.0 lib/ cp /usr/lib64/libpq.so.5 lib/ cp -a /usr/lib64/php lib/ zip -r /opt/layer/php71.zip . ```
# Upload custom layer to S3 ```bash $ docker run --rm -v $(ROOT_DIR):/opt/layer lambci/lambda:build-nodejs10.x /opt/layer/build.sh $ aws --region $region s3 cp ${LAYER}.zip "s3://${bucket_name}/${S3KEY}" ```
# Deploy ###### CloudFormation ```yaml AWSTemplateFormatVersion: 2010-09-09 Description: My PHP Application Transform: AWS::Serverless-2016-10-31 Resources: phpserver: Type: AWS::Serverless::Function Properties: FunctionName: !Sub ${AWS::StackName}-phpserver Description: PHP Webserver CodeUri: src/php Runtime: provided Handler: index.php MemorySize: 3008 Timeout: 30 Tracing: Active Layers: - !Sub arn:aws:lambda:${AWS::Region}:887080169480:layer:php73:3 Events: api: Type: Api Properties: Path: /{proxy+} Method: ANY ```
# Deploy ###### Use Serverless Application Model ```bash $ sam package \ --template-file template.yaml \ --output-template-file serverless-output.yaml \ --s3-bucket
$ sam deploy \ --template-file serverless-output.yaml \ --stack-name my-first-serverless-php-service \ --capabilities CAPABILITY_IAM ```
# I Did it! #### But I want to deploy a little more easily.
## bref + Serverless Framework
## bref
# bref Tools for running PHP applications on AWS Lambda. Provided as a Composer package, - OSS that has released bootstrap and custom layers [bootstrap](https://github.com/brefphp/bref/tree/master/runtime/layers) We only need to write a function. How can I deploy?
## Serverless Framework
# Serverless Framework Tools that can manage serverless cloud resources such as Lambda and Dynamodb Other cloud vendors can be used in addition to AWS Published as npm package ``` $ npm install -g serverless ```
# Let's try it! Use the template file of Serverless Framework published by Bref. And composer install in the created directory. ``` $ serverless create --template-url https://github.com/brefphp/bref/tree/master/template/http --path seike460 $ cd seike460 $ composer require bref/bref ```
# serverless.yml The definition files necessary for Serverless Framework have already been released. ``` service: seike460 provider: name: aws region: ap-northeast-1 runtime: provided plugins: - ./vendor/bref/bref functions: api: handler: index.php description: '' timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds) layers: - ${bref:layer.php-73-fpm} events: - http: 'ANY /' - http: 'ANY /{proxy+}' ```
# Deploy ``` $ serverless deploy Serverless: Packaging service... Serverless: Excluding development dependencies... Serverless: Uploading CloudFormation file to S3... Serverless: Uploading artifacts... Serverless: Uploading service seike460.zip file to S3 (3.4 MB)... Serverless: Validating template... Serverless: Updating Stack... Serverless: Checking Stack update progress... .............. Serverless: Stack update finished... Service Information service: seike460 stage: dev region: ap-northeast-1 stack: seike460-dev resources: 11 api keys: None endpoints: ANY - https://c1gfde1mkl.execute-api.ap-northeast-1.amazonaws.com/dev ANY - https://c1gfde1mkl.execute-api.ap-northeast-1.amazonaws.com/dev/{proxy+} functions: api: seike460-dev-api layers: None Serverless: Run the "serverless" command to setup monitoring, troubleshooting and testing. ```
###### I Dit it! ``` https://c1gfde1mkl.execute-api.ap-northeast-1.amazonaws.com/dev/ ```
# Sumally - Managing the Lambda Layer (once you make it ...) is much easier than managing the server - You can use bref if you absolutely don't want to manage layers - Maybe CakePHP works too! Please try it!
There is no official support!
# Announcement! PHP Conference Fukuoka 2020 PHP Conference Fukuoka 2020 will be held next July 11th! Please join us!
# Announcement! ServerlessDays Fukuoka! ServerlessDays Fukuoka will be held on December 14th. Please join us!
Thank you! We are Hiring!  https://fusic.github.io
Swipe to navigate
Previous
Next
Related Slides
PHPで作るWebSocketサーバー
2024/6/1
View
PHPを書く理由、PHPを書いていて良い理由
2024/1/1
View
有効な使い方を正しく理解して実装する PHP8.3の最新機能の「ウラ側」
2023/11/1
View