Slide 1

Slide 1 text

RUNNING YOUR PHP PROJECT ON AWS LAMBDA

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

WE ARE HIRING!

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

RUNNING YOUR PHP PROJECT ON AWS LAMBDA

Slide 8

Slide 8 text

(coupling yourself to AWS for fun & profit) COUPLING YOURSELF TO AWS

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

WHY?

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

EC2

Slide 14

Slide 14 text

EC2 Data Store

Slide 15

Slide 15 text

EC2 Data Store

Slide 16

Slide 16 text

EC2 Data Store Load Balancer

Slide 17

Slide 17 text

WTF?

Slide 18

Slide 18 text

EC2 Data Store Load Balancer

Slide 19

Slide 19 text

EC2 Data Store Load Balancer EC2 EC2

Slide 20

Slide 20 text

EC2 Data Store Load Balancer EC2 EC2

Slide 21

Slide 21 text

EC2 Data Store Load Balancer EC2 EC2

Slide 22

Slide 22 text

SAY HELLO TO FaaS

Slide 23

Slide 23 text

Think of FaaS as a server that doesn’t exist…

Slide 24

Slide 24 text

…until you need it…

Slide 25

Slide 25 text

…and goes away again once the job is done

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Container

Slide 28

Slide 28 text

Container Bootstrap Code

Slide 29

Slide 29 text

Container Bootstrap Code

Slide 30

Slide 30 text

Container Bootstrap Code Application Code

Slide 31

Slide 31 text

Container Bootstrap Code Application Code

Slide 32

Slide 32 text

Container Bootstrap Code Application Code

Slide 33

Slide 33 text

WAS A PITA RUNNING PHP ON LAMBDA

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Lambda function

Slide 36

Slide 36 text

Lambda function JS Handler

Slide 37

Slide 37 text

Lambda function JS Handler PHP Binary

Slide 38

Slide 38 text

Lambda function JS Handler PHP Binary

Slide 39

Slide 39 text

Lambda function JS Handler PHP Binary

Slide 40

Slide 40 text

LAYERS

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

• You can use up to 5 different layers in a Lambda function • The total unzipped size of code & layers must be < 250 MB • 1,000 concurrent invocations per region

Slide 44

Slide 44 text

Lambda function JS Handler PHP Binary

Slide 45

Slide 45 text

Lambda function Bootstrap PHP Layer Handler

Slide 46

Slide 46 text

Lambda function Handler PHP Layer Bootstrap

Slide 47

Slide 47 text

Lambda function Handler PHP Layer Bootstrap

Slide 48

Slide 48 text

Lambda function Handler PHP Layer Bootstrap

Slide 49

Slide 49 text

Lambda function Handler PHP Layer Bootstrap

Slide 50

Slide 50 text

IS STILL A PITA RUNNING PHP ON LAMBDA

Slide 51

Slide 51 text

https://bref.sh

Slide 52

Slide 52 text

BREF AIMS TO MAKE RUNNING PHP APPS SIMPLE

Slide 53

Slide 53 text

SIMPLIFY PROBLEMS BY REMOVING CHOICES

Slide 54

Slide 54 text

PROVIDE SIMPLE AND FAMILIAR SOLUTIONS

Slide 55

Slide 55 text

EMPOWER BY SHARING KNOWLEDGE

Slide 56

Slide 56 text

WHAT DOES BREF ACTUALLY DO?

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

SAM DEALS WITH DEPLOYING

Slide 61

Slide 61 text

Lambda function Handler PHP Layer Bootstrap

Slide 62

Slide 62 text

Lambda function Handler PHP Layer Bootstrap

Slide 63

Slide 63 text

API Gateway Lambda function Handler PHP Layer Bootstrap

Slide 64

Slide 64 text

API Gateway Lambda function Handler PHP Layer Bootstrap

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Hello, World!'; phpinfo(); hello-world.php

Slide 68

Slide 68 text

$ composer require mnapoli/bref

Slide 69

Slide 69 text

Hello, World!'; phpinfo(); hello-world.php

Slide 70

Slide 70 text

$ php vendor/bin/bref init

Slide 71

Slide 71 text

What kind of lambda do you want to create? [0] PHP function [1] HTTP application [2] Console application >

Slide 72

Slide 72 text

What kind of lambda do you want to create? [0] PHP function [1] HTTP application [2] Console application > 1

Slide 73

Slide 73 text

Hello, World!'; phpinfo(); hello-world.php index.php template.yaml

Slide 74

Slide 74 text

AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: '' Resources: MyFunction: Type: AWS::Serverless::Function Properties: FunctionName: 'my-function' Description: '' CodeUri: . Handler: index.php Timeout: 30 # in seconds (API Gateway has a timeout of 30 se Runtime: provided Layers: - 'arn:aws:lambda:us-east-1:209497400698:layer:php-73-fp Events: # The function will match all HTTP URLs HttpRoot: Type: Api Properties: Path: / Method: ANY HttpSubPaths: Type: Api Properties: Path: /{proxy+} hello-world.php template.yaml

Slide 75

Slide 75 text

# ... Resources: MyFunction: Type: AWS::Serverless::Function Properties: FunctionName: 'my-function' Description: '' CodeUri: . Handler: index.php Timeout: 30 # in seconds Runtime: provided hello-world.php template.yaml

Slide 76

Slide 76 text

# ... Resources: MyFunction: Type: AWS::Serverless::Function Properties: FunctionName: 'bref-hello-world' Description: '' CodeUri: . Handler: hello-world.php Timeout: 30 # in seconds Runtime: provided hello-world.php template.yaml

Slide 77

Slide 77 text

# ... Layers: - 'arn:aws:lambda:us-east-1:209497400698:layer:php-73-fpm:1' Events: # The function will match all HTTP URLs HttpRoot: Type: Api Properties: Path: / Method: ANY HttpSubPaths: Type: Api Properties: Path: /{proxy+} Method: ANY # ... hello-world.php template.yaml

Slide 78

Slide 78 text

# ... Layers: - 'arn:aws:lambda:eu-west-1:209497400698:layer:php-73-fpm:1' Events: # The function will match all HTTP URLs HttpRoot: Type: Api Properties: Path: / Method: ANY HttpSubPaths: Type: Api Properties: Path: /{proxy+} Method: ANY # ... hello-world.php template.yaml

Slide 79

Slide 79 text

# ... Layers: - 'arn:aws:lambda:eu-west-1:209497400698:layer:php-73-fpm:1' Events: # The function will match all HTTP URLs HttpRoot: Type: Api Properties: Path: / Method: ANY HttpSubPaths: Type: Api Properties: Path: /{proxy+} Method: ANY # ... hello-world.php template.yaml

Slide 80

Slide 80 text

# ... Layers: - 'arn:aws:lambda:eu-west-1:209497400698:layer:php-73-fpm:1' Events: # The function will match all HTTP URLs HttpRoot: Type: Api Properties: Path: / Method: ANY HttpSubPaths: Type: Api Properties: Path: /{proxy+} Method: ANY # ... hello-world.php template.yaml

Slide 81

Slide 81 text

TESTING
 LOCALLY

Slide 82

Slide 82 text

$ brew upgrade && brew update $ brew tap aws/tap $ brew install aws-sam-cli

Slide 83

Slide 83 text

$ sam local start-api

Slide 84

Slide 84 text

Error: Running AWS SAM projects locally requires Docker. Have you got it installed?

Slide 85

Slide 85 text

$ sam local start-api

Slide 86

Slide 86 text

* Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

Invalid Layer name: arn:aws:lambda:eu-west-1:209497400698:layer:php-73-fpm

Slide 89

Slide 89 text

$ sam local start-api --region=eu-west-1

Slide 90

Slide 90 text

Downloading arn:aws:lambda:eu- west-1:209497400698:layer:php-73-fpm [####################################] 32842625/32842625 Building image...

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

DEPLOYING

Slide 93

Slide 93 text

$ aws s3 mb s3://bref-hello-world

Slide 94

Slide 94 text

make_bucket: bref-hello-world

Slide 95

Slide 95 text

$ sam package \ --output-template-file .stack.yaml \ --s3-bucket

Slide 96

Slide 96 text

$ sam package \ --output-template-file .stack.yaml \ --s3-bucket bref-hello-world

Slide 97

Slide 97 text

Uploading to cf39403efc50314711b61effd4f5c948 2841371 / 2841371.0 (100.00%) Successfully packaged artifacts and wrote output template to file .stack.yaml.

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

Execute the following command to deploy the packaged template aws cloudformation deploy --template-file / Users/neal/www/hello-world/.stack.yaml --stack- name

Slide 100

Slide 100 text

$ aws cloudformation deploy --template-file / Users/neal/www/hello-world/.stack.yaml --stack- name

Slide 101

Slide 101 text

$ aws cloudformation deploy --template-file / Users/neal/www/hello-world/.stack.yaml --stack- name bref-hello-world

Slide 102

Slide 102 text

Waiter encountered a terminal failure state Status: FAILED. Reason: Requires capabilities : [CAPABILITY_IAM]

Slide 103

Slide 103 text

$ sam deploy \ --template-file .stack.yaml \ --capabilities CAPABILITY_IAM \ --stack-name

Slide 104

Slide 104 text

$ sam deploy \ --template-file .stack.yaml \ --capabilities CAPABILITY_IAM \ --stack-name bref-hello-world

Slide 105

Slide 105 text

Failed to create/update the stack. Run the following command to fetch the list of events leading up to the failure aws cloudformation describe-stack-events -- stack-name bref-hello-world

Slide 106

Slide 106 text

No content

Slide 107

Slide 107 text

Error occurred while GetObject. S3 Error Code: PermanentRedirect. S3 Error Message: The bucket is in this region: eu-west-2.

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

$ aws s3 mb s3://bref-hello-world --region eu-west-1

Slide 110

Slide 110 text

$ sam package \ --output-template-file .stack.yaml \ --s3-bucket bref-hello-world

Slide 111

Slide 111 text

$ sam deploy \ --template-file .stack.yaml \ --capabilities CAPABILITY_IAM \ --stack-name bref-hello-world

Slide 112

Slide 112 text

Successfully created/updated stack - bref-hello-world

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

API Gateway Lambda function Handler PHP Layer Bootstrap

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

CLOUDWATCH HAS YOUR LOGS

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

BRINGING YOUR OWN DOMAIN NAME

Slide 125

Slide 125 text

https://o6zwsmm0uk.execute-api.eu-west-1.amazonaws.com/Prod/

Slide 126

Slide 126 text

https://o6zwsmm0uk.execute-api.eu-west-1.amazonaws.com/Prod/

Slide 127

Slide 127 text

No content

Slide 128

Slide 128 text

No content

Slide 129

Slide 129 text

No content

Slide 130

Slide 130 text

No content

Slide 131

Slide 131 text

No content

Slide 132

Slide 132 text

No content

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

No content

Slide 135

Slide 135 text

No content

Slide 136

Slide 136 text

RECAP

Slide 137

Slide 137 text

• Looked at how FaaS could simplify our architecture & save us money • Installed AWS CLI • Added Bref to a project • Explored the template.yaml file • Used SAM Local to test • Created a deployment bucket • Packaged and deployed our application • Explored the stack • Tested the application on Lambda • Seen the logs in Cloudwatch • Added a custom domain name

Slide 138

Slide 138 text

REFACTORING A FULLY FEATURED WEBSITE

Slide 139

Slide 139 text

No content

Slide 140

Slide 140 text

No content

Slide 141

Slide 141 text

No content

Slide 142

Slide 142 text

No content

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

REMEMBER

Slide 145

Slide 145 text

• Only /tmp is writeable • The total unzipped size of code & layers must be < 250 MB

Slide 146

Slide 146 text

$ composer require mnapoli/bref

Slide 147

Slide 147 text

$ php vendor/bin/bref init

Slide 148

Slide 148 text

What kind of lambda do you want to create? [0] PHP function [1] HTTP application [2] Console application > 1

Slide 149

Slide 149 text

# ... Resources: MyFunction: Type: AWS::Serverless::Function Properties: FunctionName: 'bref-kittyquotes' Description: '' CodeUri: . Handler: public/index.php Timeout: 30 # in seconds Runtime: provided MemorySize: 1024 template.yaml bin public src templates config

Slide 150

Slide 150 text

# ... Resources: WebApplication: Type: AWS::Serverless::Function Properties: FunctionName: 'bref-kittyquotes' Description: '' CodeUri: . Handler: public/index.php Timeout: 30 # in seconds Runtime: provided template.yaml bin public src templates config

Slide 151

Slide 151 text

$ sam local start-api

Slide 152

Slide 152 text

No content

Slide 153

Slide 153 text

bin public src templates config template.yaml environment; } return $this->getProjectDir().'/var/cache' . $this->environment; } Kernel.php

Slide 154

Slide 154 text

bin public src templates config template.yaml getProjectDir().'/var/log'; } Kernel.php

Slide 155

Slide 155 text

PDOException > PDOException > DriverException An exception occurred in driver: could not find driver

Slide 156

Slide 156 text

No content

Slide 157

Slide 157 text

No content

Slide 158

Slide 158 text

bin public php templates config template.yaml extension=pdo_mysql src conf.d php.ini

Slide 159

Slide 159 text

CONNECTING THE DATABASE

Slide 160

Slide 160 text

API Gateway Lambda function Handler PHP Layer Bootstrap

Slide 161

Slide 161 text

API Gateway Lambda function Handler PHP Layer Bootstrap

Slide 162

Slide 162 text

API Gateway Lambda function Handler PHP Layer Bootstrap API Gateway Data Store

Slide 163

Slide 163 text

API Gateway VPC Lambda function Handler PHP Layer Bootstrap API Gateway Data Store

Slide 164

Slide 164 text

# ... Resources: WebApplication: Type: AWS::Serverless::Function Properties: Environment: Variables: APP_ENV: prod DATABASE_URL: ‘mysql://db_user:db_pass@...’ # ... template.yaml bin public src templates config

Slide 165

Slide 165 text

No content

Slide 166

Slide 166 text

No content

Slide 167

Slide 167 text

No content

Slide 168

Slide 168 text

$ aws s3 mb s3://bref-kitty-quotes-bucket

Slide 169

Slide 169 text

$ sam package \ --output-template-file .stack.yaml \ --s3-bucket bref-kitty-quotes-bucket

Slide 170

Slide 170 text

$ sam deploy \ --template-file .stack.yaml \ --capabilities CAPABILITY_IAM \ --stack-name bref-kitty-quotes-app

Slide 171

Slide 171 text

Failed to create/update the stack. Run the following command to fetch the list of events leading up to the failure aws cloudformation describe-stack-events --stack-name bref-kitty-quotes-app

Slide 172

Slide 172 text

Unzipped size must be smaller than 155850286 bytes

Slide 173

Slide 173 text

$ composer install --optimize-autoloader --no-dev $ rm -rf node_modules

Slide 174

Slide 174 text

$ composer install --optimize-autoloader --no-dev $ rm -rf node_modules $ rm -rf var/cache $ rm -rf .idea/* $ rm -rf .git/*

Slide 175

Slide 175 text

cp -Rf ../bref-kitty-quotes-symfony/* . \ && rm -rf var/cache/* \ && rm -rf node_modules \ && composer install --optimize-autoloader --no-dev \ && php bin/console cache:warmup --env=prod \ && sam package --output-template-file .stack.yaml --s3-bucket bref-kitty-quotes-bucket \ && sam deploy --template-file .stack.yaml --stack-name bref-kitty-quotes-app --capabilities CAPABILITY_IAM

Slide 176

Slide 176 text

Successfully created/updated stack - bref-kitty-quotes-app

Slide 177

Slide 177 text

No content

Slide 178

Slide 178 text

No content

Slide 179

Slide 179 text

// ... if (Encore.isProduction()) { Encore.setPublicPath( 'https://s3-eu-west-1.amazonaws.com/' + ‘kittyquotes-site-assets’ ); Encore.setManifestKeyPrefix('build/'); } webpack.config.js template.yaml bin public src templates config php

Slide 180

Slide 180 text

$ yarn encore production

Slide 181

Slide 181 text

No content

Slide 182

Slide 182 text

No content

Slide 183

Slide 183 text

No content

Slide 184

Slide 184 text

bin config framework: assets: base_urls: - 'https://s3-eu-west-1.amazonaws.com/%env(ASSETS_BUCKET_NAME)%' packages assets.yaml webpack.config.js template.yaml public src templates php

Slide 185

Slide 185 text

No content

Slide 186

Slide 186 text

No content

Slide 187

Slide 187 text

API Gateway Data Store Lambda function Handler PHP Layer Bootstrap

Slide 188

Slide 188 text

Lambda function Handler PHP Layer Bootstrap API Gateway Data Store Sessions

Slide 189

Slide 189 text

API Gateway Data Store Lambda function Handler PHP Layer Bootstrap Sessions

Slide 190

Slide 190 text

API Gateway Data Store Lambda function Handler PHP Layer Bootstrap Sessions Handler PHP Layer Bootstrap Sessions

Slide 191

Slide 191 text

API Gateway Data Store Sessions Sessions Lambda function Handler PHP Layer Bootstrap Handler PHP Layer Bootstrap

Slide 192

Slide 192 text

No content

Slide 193

Slide 193 text

bin config services: # ... Symfony\Component\HttpFoundation\Session \Storage\Handler\PdoSessionHandler: arguments: - !service { class: PDO, factory: > 'database_connection:getWrappedConnection' } - { lock_mode: 1 } services.yaml webpack.config.js template.yaml public src templates php

Slide 194

Slide 194 text

bin config framework: # ... session: # ... handler_id: > Symfony\Component\HttpFoundation\Session \Storage\Handler\PdoSessionHandler packages framework.yaml webpack.config.js template.yaml public src templates php

Slide 195

Slide 195 text

No content

Slide 196

Slide 196 text

bin public src templates config final class Version20180828140534 extends AbstractMigration { public function up(Schema $schema): void { $this->addSql("CREATE TABLE `sessions` ( `sess_id` VARCHAR(128) NOT NULL PRIMARY KEY, `sess_data` BLOB NOT NULL, `sess_time` INTEGER UNSIGNED NOT NULL, `sess_lifetime` MEDIUMINT NOT NULL ) COLLATE utf8_bin, ENGINE = InnoDB;"); } public function down(Schema $schema): void { $this->addSql('DROP TABLE sessions'); } } Migrations Version2019____.php webpack.config.js template.yaml php

Slide 197

Slide 197 text

CONSOLE COMMANDS

Slide 198

Slide 198 text

Globals: Function: Environment: Variables: DATABASE_URL: ‘mysql://db_user:db_pass@...’ Resources: WebApplication: # ... Console: Type: AWS::Serverless::Function Properties: FunctionName: 'bref-kittyquotes-console' CodeUri: . Handler: bin/console # or `artisan` for Laravel Runtime: provided Layers: # PHP runtime - 'arn:aws:lambda:eu-west-1:209497400698:layer:php-73:1' # Console layer - 'arn:aws:lambda:eu-west-1:209497400698:layer:console:1' webpack.config.js template.yaml bin public src templates config php

Slide 199

Slide 199 text

Globals: Function: Environment: Variables: DATABASE_URL: ‘mysql://db_user:db_pass@...’ Resources: WebApplication: # ... Console: Type: AWS::Serverless::Function Properties: FunctionName: 'bref-kittyquotes-console' CodeUri: . Handler: bin/console # or `artisan` for Laravel Runtime: provided Layers: # PHP runtime - 'arn:aws:lambda:eu-west-1:209497400698:layer:php-73:1' # Console layer - 'arn:aws:lambda:eu-west-1:209497400698:layer:console:1' webpack.config.js template.yaml bin public src templates config php

Slide 200

Slide 200 text

Globals: Function: Environment: Variables: DATABASE_URL: ‘mysql://db_user:db_pass@...’ Resources: WebApplication: # ... Console: Type: AWS::Serverless::Function Properties: FunctionName: 'bref-kittyquotes-console' CodeUri: . Handler: bin/console # or `artisan` for Laravel Runtime: provided Layers: # PHP runtime - 'arn:aws:lambda:eu-west-1:209497400698:layer:php-73:1' # Console layer - 'arn:aws:lambda:eu-west-1:209497400698:layer:console:1' webpack.config.js template.yaml bin public src templates config php

Slide 201

Slide 201 text

$ php vendor/bin/bref cli bref-kittyquotes-console -- \ doctrine:migrations:migrate --force

Slide 202

Slide 202 text

$ php vendor/bin/bref cli bref-kittyquotes-console -- \ doctrine:migrations:migrate --force

Slide 203

Slide 203 text

$ php vendor/bin/bref cli bref-kittyquotes-console -- \ doctrine:migrations:migrate --force

Slide 204

Slide 204 text

++ 1 migrations executed ++ 1 sql queries

Slide 205

Slide 205 text

No content

Slide 206

Slide 206 text

Handler PHP Layer Bootstrap Lambda function API Gateway Data Store

Slide 207

Slide 207 text

Handler PHP Layer Bootstrap Lambda function API Gateway Data Store

Slide 208

Slide 208 text

API Gateway Data Store File Store Handler PHP Layer Bootstrap Lambda function

Slide 209

Slide 209 text

parameters: app.path.kitty_images: ‘%env(APP_UPLOADS_BUCKET_NAME)%’ bin config services.yaml webpack.config.js template.yaml public src templates php

Slide 210

Slide 210 text

# ... Resources: WebApplication: Type: AWS::Serverless::Function Properties: Environment: Variables: APP_UPLOADS_BUCKET_NAME: kittyquotes-uploads webpack.config.js template.yaml bin public src templates config php

Slide 211

Slide 211 text

No content

Slide 212

Slide 212 text

bin config twig: # ... globals: kitty_uploads_bucket: '%app.path.kitty_images%' packages twig.yaml webpack.config.js template.yaml public src templates php

Slide 213

Slide 213 text

bin public src templates config {{ quote.kitty.name }}”
>
<!-- ... -->
template.yaml
webpack.config.js
quote
quote-card.html.twig
php

Slide 214

Slide 214 text

No content

Slide 215

Slide 215 text

UPLOADING NEW IMAGES OF KITTIES

Slide 216

Slide 216 text

pre-signed URLs

Slide 217

Slide 217 text

Client Server Amazon S3

Slide 218

Slide 218 text

Client Server Amazon S3 Get Pre-Signed URL

Slide 219

Slide 219 text

Client Server Amazon S3 Get Pre-Signed URL Get Pre-Signed URL

Slide 220

Slide 220 text

Client Server Amazon S3 Get Pre-Signed URL Get Pre-Signed URL One-time use URL

Slide 221

Slide 221 text

Client Server Amazon S3 Get Pre-Signed URL Get Pre-Signed URL One-time use URL One-time use URL

Slide 222

Slide 222 text

Client Server Amazon S3 Get Pre-Signed URL Get Pre-Signed URL One-time use URL One-time use URL PUT file to One-time use URL 200 OK

Slide 223

Slide 223 text

Client Server Amazon S3 Get Pre-Signed URL Get Pre-Signed URL One-time use URL One-time use URL PUT file to One-time use URL 200 OK Update record

Slide 224

Slide 224 text

Client Server Amazon S3 Get Pre-Signed URL Get Pre-Signed URL One-time use URL One-time use URL PUT file to One-time use URL 200 OK Update record Delete previous file

Slide 225

Slide 225 text

bin public src config

Slide 226

Slide 226 text

bin public src templates config getPreSignedUrl = function (files) { file = files[0]; $.ajax({ url: '/admin/kitty/upload-image-pre-signed-url/' + file.name, type: "GET", dataType: "json", cache: false }) .done(function (data) { preSignedUrl = data.url; document.getElementById('kitty_image_image').value = data.filename; }); } function uploadFile() { $.ajax({ url: preSignedUrl, type: "PUT", data: file, contentType: file.type, processData: false }).done(function () { $("form[name='kitty_image']").submit(); }); } uploader.html.twig template.yaml webpack.config.js php

Slide 227

Slide 227 text

No content

Slide 228

Slide 228 text

$ composer remove vich/uploader-bundle

Slide 229

Slide 229 text

bin public src config Entity Kitty.php

Slide 230

Slide 230 text

imageFile = $image; if (null !== $image) { $this->updatedAt = new \DateTimeImmutable(); } } public function getImageFile(): ?File { return $this->imageFile; } } bin public src config Entity Kitty.php templates template.yaml webpack.config.js php

Slide 231

Slide 231 text

No content

Slide 232

Slide 232 text

No content

Slide 233

Slide 233 text

No content

Slide 234

Slide 234 text

RECAP

Slide 235

Slide 235 text

• Added Bref to an existing site • Fixed assets by moving them to a CDN • Moved session storage to the database • Ran console commands by adding another layer • Used pre-signed URLs for image uploading

Slide 236

Slide 236 text

No content

Slide 237

Slide 237 text

PERFORMANCE

Slide 238

Slide 238 text

No content

Slide 239

Slide 239 text

VPC Lambda function Handler PHP Layer Bootstrap API Gateway Data Store

Slide 240

Slide 240 text

source: https://medium.freecodecamp.org/lambda-vpc-cold-starts-a-latency-killer-5408323278dd

Slide 241

Slide 241 text

source: https://medium.freecodecamp.org/lambda-vpc-cold-starts-a-latency-killer-5408323278dd

Slide 242

Slide 242 text

source: https://medium.freecodecamp.org/lambda-vpc-cold-starts-a-latency-killer-5408323278dd

Slide 243

Slide 243 text

No content

Slide 244

Slide 244 text

No content

Slide 245

Slide 245 text

source: https://github.com/mnapoli/bref-benchmark JS vs PHP

Slide 246

Slide 246 text

source: https://github.com/mnapoli/bref-benchmark JS vs PHP

Slide 247

Slide 247 text

GOING FURTHER

Slide 248

Slide 248 text

MICRO SERVICES

Slide 249

Slide 249 text

What kind of lambda do you want to create? [0] PHP function [1] HTTP application [2] Console application >

Slide 250

Slide 250 text

What kind of lambda do you want to create? [0] PHP function [1] HTTP application [2] Console application > 0

Slide 251

Slide 251 text

ROLLING YOUR OWN

Slide 252

Slide 252 text

https://github.com/ stechstudio/bref-extensions

Slide 253

Slide 253 text

https://github.com/ mnapoli/bref

Slide 254

Slide 254 text

runtime ./configure \ --build=x86_64-pc-linux-gnu \ --prefix=${INSTALL_DIR} \ --enable-option-checking=fatal \ --enable-maintainer-zts \ --with-config-file-path=${INSTALL_DIR}/etc/php \ --with-config-file-scan-dir=${INSTALL_DIR}/etc/php/conf.d:/var/tas --enable-fpm \ --disable-cgi \ --enable-cli \ --disable-phpdbg \ --disable-phpdbg-webhelper \ --with-sodium \ --with-readline \ --with-openssl \ --with-zlib=${INSTALL_DIR} \ --with-zlib-dir=${INSTALL_DIR} \ --with-curl \ --enable-exif \ --enable-ftp \ --with-gettext \ --enable-mbstring \ --with-pdo-mysql=shared,mysqlnd \ --enable-pcntl \ --enable-zip \ --with-pdo-pgsql=shared,${INSTALL_DIR} \ --enable-intl=shared \ --enable-opcache-file php php.Dockerfile

Slide 255

Slide 255 text

$ make publish

Slide 256

Slide 256 text

No content

Slide 257

Slide 257 text

No content

Slide 258

Slide 258 text

No content

Slide 259

Slide 259 text

No content

Slide 260

Slide 260 text

• Documentation • Speed & stability • A recommended method of creating your own runtimes • Better framework integrations

Slide 261

Slide 261 text

JOIN US

Slide 262

Slide 262 text

No content

Slide 263

Slide 263 text

https://bref.sh

Slide 264

Slide 264 text

@nealio82 https://bref.sh