 I know what you're thinking. Who is this overweight, beardy man who's replaced Rob? So let me tell you. I work for a company called My Builder. We are passionate about connecting home owners with great builders. We help great builders succeed with their businesses. We are hiring. So if you like what I'm doing today, if you like the look of me and you want to join a team that's close-knit and supportive and passionate about what they do, Come and talk to me or tweet me or whatever afterwards and we'll get talking. So un note about the code, there is going to be some code in this presentation but we're thinking more about the theory of things. You don't need to follow along, you don't need to understand things. The code examples are going to be symphony. I know some of you that might not be your bags so much, but that's the way I roll. So back on track running your pH pre-project on AWS Lambda ac yn ôl i'n ddweud y gallwch, ddweud o gwleidio ar EWS o'r FFAM ac profiadau. Felly ydych chi'n gwybod i'r mynd i'w ddweud? Dwi'n fyddech chi'n gweld y cyfweld sy'n gwybod i'r wefbeth ffordd yng Nghymru. Felly ydych chi'n gwybod i'w ddweud y cwyl i'r ysgolol i'r cyfweld i'w ddweud, rwy'n gweld i'n gwybod i'r ddweud ar y database. A dych chi'n gwybod i'w ffynol yw cael cyfrifol i SSL certification Wel tyfnodd maen nhw'n gweithio'r cyfioedd y gwaith ar unrhyw ystafell yw'r gael o'r wneud. Ac mae'r bwysig yn gweithio'r gwaith o'r wneud ac y gallwch yn gallu'n gweithio'r gael o'r fwortau. Mae ychydig o'r llyfr yn y peth yn ddechrau. Yn y gweithio yma, mae'n gweithio'r cyfrifysgig, dyna'r cyfrifysgau, mae'n gweithio'r gael o'r gael o'r bwysig sy'n gweithio'r gael o'r wneud. Ac mae'n gwybod i gallu allanonod gyda'r gwahen. Rydyn ni'n swydd iawn i'n ffod o'r llwedig. Rydyn ni'n gweithio gan gwellfryd. A ydw'n cael ei gweithio ar y gamen, cael cael ei gweithio'r gweithio. Mae'n ardal, i ni rwy'n gweithio'r functiad hwnnw i'r ysgogffian. Yn y ffan, rwy'n gweithio'r ysgogffian, ac aethau Rwm Cymraeg bob ddau ar bethau. You got to show what the global standard of拜itched means and when it goes from shores to ports to portsocket. It's been there in theHzhip. The way to think of it is as a server that doesn't exist until you make a request to it and then it goes away again. It doesn't exist until it's needed again. So think about the anatomy of how that might look. It's just filled up with a container. Inside that is some bootstrap code and that sits there waiting for the request to come in. When the request comes in that bootstrap called your application code, this is when you start getting charged when your application code is running. Then when that request goes back you stop getting charged, you've stopped paying for that bootstrap... that container is still bootstrapped and still waiting for the next request. The trouble is running PHP on Lambda was a complete pain in the ass until quite recently. A lot of articles on the internet all revolved around the same thing. It said, right, start your Lambda function, create a Lambda function yn ymddangos y gwaith sydd wedi'i gwerthu gwyllwch ar gyfer Gyfer Gwyrdorol, o Gyfer Gwyrdorol, o Siarfa o Python. Cydwch chi'n gwneud hynny o FHS Gwyrdorol, ac ydych chi'n ei wneud yn ymddangos ein rhai ein gwirach yw'r hwylhau cyliau cyflugol. Ydi'r hynny ar y cyflawn cyflawn. Felly mae rydyn ni'n gweithio ar y cyflawn. Yn ymwneud y fach yma, yw'r awes yn ymwneud yw dyfodol. and a bunch of documentation about it. It kind of opened up the possibility to have different programming languages. Any programming language you want running on AWS Lambda. There are some things to note here. You can have up to five different layers running in a Lambda function. The total unzipped code of everything has to be less than 250 mega bytes and by default you get a thousand concurrent invocations of lambda per region, that's across all of your functions. You can increase that if your traffic warrants it, but it's kind of a procedure in place to stop you exponentially running up your AWS bill. So let's think about how that might look now. So this is what we had previously and we've now got this, this bootstrap is now including the PHP layer and we've got a little handler that we can shim in there as well and this is sitting waiting for the request to come in. So our request comes in. Now we only pay for our framework code or our application code and everything gets sent back to the client and we stop paying for that at that point. Trouble is it's still a pain in the ass. You have to supply the layer and you have to supply the bootstrap. Well, apparently I can't click from over there. There is a website, bref.sh. Now bref is French for brief. It kind of references the brief nature of lambdas that exists only when you need it, very, very, very kind of ephemeral and very time constrained. Now bref's goal is to make running PHP apps on lambda simple. How does it achieve that? Well, it simplifies problems by removing choices. You don't get the kitchen sink thrown in. What we do is we give you simple and familiar solutions so that you can extend them if you want but things will always run the same and they should be stable and they should be predictable. I'm also empowered by sharing knowledge which is a way basically of saying we don't want to hide complexity behind leaky abstractions. We'll give you what you need and it's well documented and that's what you get. So what does bref actually do? Well, that's a very good question. I'm so glad you asked it. Bref provides simple and clear documentation. It supplies cake, layers even, not cake, and it aims to support the frameworks. Now PHP, plain old PHP runs on bref, Laravel runs on bref, Symphony runs on bref. I know these for a fact because I've done them. I believe we've got slim working with it and there's no reason why like Magento and PHP BB or anything else wouldn't be able to work with it now. Previously before the layers was announced it would have been a nightmare trying to do that but now we can do that. There's no reason why we wouldn't be able to support any framework to be honest. We have something called SAM which is an AWS package which deals with the actual deployment and I like to think of this as a guy called SAM who's deploying some lunch somewhere. So what SAM does is takes what we have here, this architecture and it pushes it up to AWS and puts an API gateway front on it as well. Now what you can do is attach your SSL certificate to API gateway and you've actually got your free SSL that we've all been, you know the holy grail that we were looking for. So let's dive in. I've got here just a very simple hello world dot PHP which is going to echo out hello world and then give me some PHP info. So I'm going to require the bref project and go back. Well nothing's actually changed so I need to run the init script so it's vendor been bref init. If we have a look at the output here it's saying to me what kind of lambda function do I want to create. Well I want to be able to look at this in my browser. I want to go to the PHP info and see what's happening and see that hello world. So I'm going to select number one and you can see that it's created for me an index dot PHP and a template dot yaml file. I'm going to delete the index dot PHP. I don't want it. Let's look at the template dot yaml. It's big and it's scary so the thing to do is go straight into it and see what's going on. We see here we've got a resources section which has got my function here and I've got a function name and I've got a pointer to an index dot PHP file and obviously I've deleted that index dot PHP so I need to point that to my hello world. I'm going to change the name of the lambda function that it's going to create as well to bref hello world. If we look here as well we've got the layer configuration. Now bref has automatically created this for me but it's put the layer in this reference in US east one so I'm going to change that to EU west one. Regions will come back and haunt you at some point. They do with me all the time so just always be aware that if anything goes wrong it's probably because you've knackered up your regions. If we look here we've got a couple of routing definitions here so we've got the route path. That just says to API gateway anything that matches the route path is going to be handled by this function and again HTTP subpaths it's not really relevant here but for applications with routing and multiple URLs it's what it will do is match that and send that all to your application as well. So how do we test locally? I'm going to install the AWS SAM CLI using homebrew. By the way Linux users if you haven't used Linux brew yet I suggest you do that. It's a really really good method of using homebrew stuff on Linux. So I'm just going to tap the AWS tap and then install the SAM CLI. Once that's done I can start the SAM local API in my project folder and it tells me that I need Docker. So I need to start Docker. Now if I start SAM local again it tells me it's running locally on port 3000. Fantastic I can go now so they're in my browser and see what I get. I've got an error. Okay there's something that I need to do here clearly. And if I look at the console it's told me I've got an invalid layer name but I know that that layer is valid that's what breath provided me and I know that that layer is a valid layer. So what's happened? Regions. My AWS profile is set to US east one by default and I forgot to set it as west one. So I've got two things I can do I can either set my profile default or I can just tag on the region at the end here. This is the simplest thing to do just to get things running. This time when I go to that URL in my browser the console output tells me it's going to download the layer and it's going to build the image. So the first time you access it it takes maybe a minute or so to get going to download and build the image. And we can see here I've got a lambda s environment running locally with my hello world and my phpn folder. It's not that impressive to be honest. So let's think now about how we can deploy and actually make that run somewhere in the cloud on top of AWS's stack. The first thing I need to do is create a deployment bucket. This is where the artifacts we're going to go. I only need to do this once per lambda function that I'm creating or per project that I'm creating. So once I've run that it comes back and says hey look I've made the bucket for you. Your breath hello world is right there. Now I can copy and paste the deployment commands from the breath documentation on the website. So the first one is to create the package which is going to be so the output template file think of the output template file is kind of being a bit like a composer.lock. It's going to lock things down. It's going to say this is a deployment configuration that we're going to use. And the s3 bucket of course is the s3 bucket I've just created. When I run it what happens is Sam CLI gives me a bunch of information. It says yeah I've done that and I've created the stack.yaml file. And if I go into my s3 console I can see that I've got the bucket created and I've got that artifact that it was just telling me about there. Quite hopefully Sam also says hey look run this cloud formation command and then we'll actually deploy the thing. So I'm going to take that put in the name of the stack that I want to create which is breath hello world and I'm going to run that. And Sam tells me it's got an error. Something to do with capabilities I am blah blah blah. I don't care. I'm going to go back to the breath website and see what command I actually should have run. So breath documentation says look that other command that Sam gives you isn't going to work. This is the one that you need to do. So Sam deploy blah blah blah. Again stack name. Breath hello world. This time when we create it I've got another error. Errors you're going to run into errors the first time you do this thing and these are all errors that I genuinely made yesterday when I was putting putting things together. You're going to run into errors. At this point I'm bored of doing things in the console. I want something visual. So I can go into cloud formation. I can see that something's gone wrong and I can drill down into the details and it says the bucket is in the wrong region. I've made that same mistake again. Okay. So what I decided to do at this point was delete the stack. Delete the bucket and start again. This time creating the bucket in the correct region and it was at this point I decided to put the region in my AWS profile in my credentials file. So now I can create the bucket and I can do package and I can do the deploy. Again using the command that's actually on the breath website rather than what Sam tells me to do and this time I've got a stack created. How cool is that? All right you're not impressed. Okay so this time in cloud formation let's have a look at what we've got. Let's explore what's happened. So I've got the stack is created. If I go to API gateway you can see I've got this whole thing that's been created here for me and we've got all the way here so we've got the API gateway stuff and then right at the end right on the right hand side here we've got this is where it's going to proxy through to your lambda function you've created which is kind of similar to what we had in this diagram right so we've got we don't have as much information on the API gateway side and we've got more information on the lambda stuff on this diagram but it's the same sort of thing. Now if I go to my lambda console I can see that I've got this functions being created. I've got an inline code editor with my php in it and if I look at the layers configuration here I can see that I've got that layer in the EU west one region that I the ARN the URI for that was copied from the breath website and if I go to API gateway configuration here I've got a couple of down the bottom here I've got a couple of endpoints that I can go to in my browser so if I open that up look at this I've got that hello world application with php info running remotely on a server that existed just to return that php info and doesn't exist anymore until I refresh the page and if I keep refreshing the page it brings that that server back up sends the response back and it goes away again the logs from that go to cloud watch so I can open up cloud watch and after I've refreshed a few times I kind of had to look at what was going on so I've got all of these requests and they're kind of they're they're running for like the duration for these flitters between what six milliseconds and 180 I think milliseconds is the longest set the first one the longest one that's 280 milliseconds was the first request where it had to build the the container and do the boot strapping and then get php ffm up and running so that's why it takes a little bit longer but the rest of them there they're kind of quick they're not they're not ridiculously fast just yet but they're you know they're they're quite reasonable I think and if we look here so I just want to draw your attention to this we've got this right at the beginning of the log we've got this entry about php ffm coming up and being ready to handle connections that's the only time that appears in that log that means that that kind of confirms that what we were saying about once it's bootstrapped it's there your bootstrap is working and that's still running and waiting for the requests so they it doesn't need to re bootstrap php ffm with each request now what about if you've got your own domain name that you want to use on that because let's be honest that's that's an ugly url right and we've got this weird prod thing at the end of it what's that all about well that's something that api gateway uses it's called the stage name but I don't like that I don't want to I don't want to have that in my URLs now let's assume for example that you really like cats and each time you do a presentation in fact you're obsessed with cats and each time you do a presentation you set up a new domain name that's something to do with cats and for the sake of this one you've set up a website called kittyquotes.net which which combines your your passion for puns and kittens and what we want to do is just kind of as a proof of concept we want to use that domain name for hello world and attach that to our hello world lambda that we've just created what I'm going to do is in api gateway I'm going to click custom domain names it's kind of a kind of simple when uh when you realise it so you click custom domain names and you put in there helloworld.kittyquotes.net as the as the domain name and I can select what SSL certificate I want to use but it has to be in the US east one region if you have certificates in any other region it won't work you have to transfer them to US east one to make this work so a quick save all right okay so it takes a little while to get that all running in the meantime we can make a cup of tea and we can then add some base path mappings now what that does is says that when something comes in to kittyquotes.net to that to that uh route path I want the destination to be that that stack that I've created and we're going to send it to that prod stage then I've got my uh cloud for an URL that it's created and I can take that I can copy that and I can go to my root 53 configuration and I can create an alias I'm going to create an A record there as an alias and just paste that in you can do a C name if you want to do a C name but the difference as far as I'm aware between doing an A record alias and a C name is that with a C name you get charged per look up whereas with aliases you don't so you can save a little bit more a little bit more money in that respect this time if I go to helloworld.kittyquotes.net I have got a fancy green padlock in my in my address bar and I've got my hello world and I've got my php info running again this is this is totally ephemeral so so that server only exists when the request is being made and it goes away again which is I think that's kind of cool so we've just gone through quite a bit there so let's let's recap what we've done we've looked at how functions as a service can simplify our architecture and save us a bit of money we're not paying for a server to run 24 seven we don't have to pay for a load balancer um you know we're we're only paying for stuff that we're actually using when we're using it we've installed the aws sam cli we've added breath into our project we've had a quick look at the template.yml file we've tested with the sam local we've created our deployment bucket we have packaged and deployed our application we've had to look at the stack that it's created we've tested the application we've had to look at the logs and we've added a custom domain name now I didn't take long at all we've done a lot there but it didn't take long at all we've also run into a few errors on the way well what about fully featured websites is it possible to take a you know a normal website your kind of web applications that you're running your blogs and and your your your business storefront and run that on on lambda let's find out eh now imagine that a website called kitty quotes dot net exists and this is the local version of it running on the local web server so we've what we've got here is some content returned from a database and we've got some css we've got some javascript we've got some uploaded images of of kittens we've got a back end system with uh which is secured with um it's actually with symphony's user management and we've got an admin panel uh which is from a uh which from a community bundle and we've got an uploading mechanism from a uh plug-in for the admin panel so let's let's have a look at what we can do to convert this we've got some things to remember though only the temp directory on lambda is writable so I can't put things where I'm used to putting them I'm going to run into problems and we also have to remember that the total unzip size of the code and the layers has to be less than 250 megabytes so with those two red lines in place let's see what we can do I'm going to require breath and I'm going to initialize it and again this is going to be an HTTP application that I'm going to go to in my browser so I'm going to choose option number one there if we look at the template.yaml what I've done here I've made a couple of adjustments already so I'm changing the function name to breathkitty quotes in the lambda console uh on the website I want to be able to identify this so I'm calling it breathkitty quotes I am pointing to the public index.php which is the symphony default entry point to the application and I've increased the memory size that's allowed for my for my lambda function to run by default I think lambda sets it to 128 megabytes which then means it takes forever to return a request and you're paying for more time on the lambda it seems kind of counterintuitive but if you increase the memory size you pay for more memory but you pay for less time to run that and so you end up saving a bit of money in that respect and I've changed the name of the resource to web application the reason for that will become clear a bit later on but let's move on from there so I'm going to start the API again so I can just test this locally and straight away I've got an exception and the reason being is because I forgot the very thing that I told you to remember which is that only the temp file system is writable so the thing to do is go into my kernel.php and configure the framework to write to temp instead we've got access to this environment variable which is am I running on lambda so I can just override the get cache directory method in the kernel and say if I'm on lambda then we put the cache into the temp and we can do the same thing with the logs as well but maybe it's better to use monologue or something to push your logs somewhere else for this trouble is now I'm getting a pdo exception it can't find the pdo driver which is obviously kind of a problem if you've got a database backed site you need to be able to access stuff from the database right now the reason for that let's go over there again the reason for that is because breath tries to keep everything very very small and very very optimized and very very fast it doesn't want to make choices for you it wants you to make these decisions so we've got some extensions are enabled by default they're installed and enabled and we've got pdo there and we've got pdo esculiat and one or two other bits and pieces that are going to be kind of a kind of requisite for a lot of applications and we've got some extensions which are installed but disabled and one of those is the my sql pdo driver so how do I how do I make that work what is documented on the breath website all you need to do is create a php slash conf dot d directory and inside there put php.anion and then say extension equals pdo my sql simple and what happens is things start working then but now we need to set up a database connection if you remember like currently our architecture looks like this what we want to do is connect to our data store optionally we can put it inside a vbc and we'll talk about vpcs in a bit vpc would obviously increase security by making sure that only the lambda can ever connect that database at the moment there are performance implications with that and we'll talk about that a bit later on now what we can do in the template we can define environment variables so I can just put the database url in there but that's not necessarily a good idea before you do that let's think about where this file is going to end up are we going to commit this file are we going to end up putting our database username and password in a file that we're going to push on github and then maybe make public at some point we don't want to do that so it might be a better option to put some kind of placeholder into the template.yml file and then just define that actual variable later on in the in the lambda application console so now on sam local I have got my database backed content coming out and I've also got the css and the and the js and the image is all working fine so let's think about deploying this so I'm going to create my bucket and I'm going to package it and this time I'm making sure that the bucket and everything is all in the region I want it to be and then I'm going to deploy it using that deploy command that was on the breath website I'm completely ignoring Sam's suggestion for this now but I've got an error okay let's see what the error is when I drill into it in the in the cloud formation events it says the unzip size must be smaller than 150 megabytes great okay so let's think about what we're trying to do what can we do we can remove maybe the dev dependencies and symphony the full stack framework comes with a bunch of stuff that you can install with yarn for for running your on course stuff and generating your assets I don't need the node modules when I'm on production so I can delete that but the problem is that doesn't go far enough the the deployment package is still too big so we think okay let's remove the cache before the deploy and let's think about removing my php storm configuration let's think about removing the trouble is these are all necessary you need all of these on your local development so this this isn't the right solution for that and currently we're kind of discussing the best way of trying to attack this I'll say actually if you're deploying from continuous integration or something you don't have this problem because things like your php storm configuration isn't in your ci and neither is your your git working configuration so you don't you don't need that you can just pull and do a composer install with the optimiser auto loader and everything and that and you'll never get the node modules and that will all be fine it'll be much much smaller at the moment if you're going to deploy locally from a laptop what you can do and currently the way we document it is to make a copy of your project get rid of what you don't need and upload the the optimised version so with that I've created just a very simple bash script I'll say simple it looks scary but there's a bash script that that I run from a different directory it says copy everything apart from the the hidden files so it cops everything and then remove the stuff that's in the cache remove the node modules install only the basic stuff and optimise it at the same time warm up the cache now that's that's a very small performance optimisation that we can make by warming the cache but it means that we don't have to warm a cold cache on that first request on land where it's pre-warmed and then we package and then we deploy and things start working now because I'm making code edits in my editor in one directory and that deploy script once I've created it like I can just keep hitting deploy and it will do everything for me it's just created my stack and I can go to it in my browser and I've got my database backed content but what I don't have which is what we had with Sam Local was all of the assets the the images and the the CSS and the JS and that's that's kind of I stopped using Sam Local at that point because it's it's similar to lambda but it's not quite similar enough so we need to fix this the first thing we're going to do is we're going to put our CSS and JavaScript on a CDN which if you're going down the serverless route you probably should be doing anyway and I'm sure you know many of you are probably already using CDNs right now it's well documented in symphony it's well documented in Laravel and probably any other framework that you want to use how to achieve this so I'm just going to copy and paste some code and I'm going to say look I've got this bucket set up and I've uploaded those assets to that bucket so this is where you need to go and then when I recompile the front end assets and deploy I've got my CSS back and I can log in the trouble is my back end is looking a little bit weary uh I don't have those back end assets that uh that I thought I'd have so what do I need to do I need to tell my uh PHP templates where to look for those assets as well once I've done that and deployed I've got this easy admin back there's something quite obvious missing though which is these images and we'll get to that in just a bit but first of all as I'm clicking around I get kicked out and it happens it happens as I'm trying to do stuff I get kicked the reason for that is because I've got my lambda function here and my sessions exist on that lambda function now there's no guarantee when I make another request I'm going to hit that same lambda container and my and I might have a session on a different container and I need some way of being able to combine the two and of course the uh one of the options is to put the sessions into the data store again it's well documented for Laravel it's well documented for uh symphony and it's the the theory and the um the kind of methods of doing so don't really change uh so I am just going to copy and paste the symphony configuration for it and of course I need to make the change on the uh on the database itself so I've created migration but now I'm I've got this problem I need to run that on my remote database to add the sessions table so I can store sessions in there how do I do that how do I need to configure that connection locally so I can run this locally or can I run that on the lambda environment well we need to be able to run console commands in template.yml and now it should become clear why I renamed that resource to web application before because now I've added another resource called console and I'm including that first layer the uh PHP 7.3 layer and I'm also adding a second layer here which gives me access to the console and what I've also done is put that database environment variable into a global variable that makes that variable uh accessible to both the web app and to the console app so I can move that out and only define that in one place now I need to run the command so locally I can do uh vendor bin breath cli and then the name of the function I want to invoke and I put a double dash and then the name of the command I want to run which is migrations my great force and what happens is it comes back and it tells me I've done this change to your database we are all good which is great I can click around and I can do stuff and I'm not going to get kicked anymore and it also means that when I redeploy my users aren't going to get kicked because their sessions are just going to be retrieved back from that uh that database table again so now let's think about the images that we're missing what I have done now is uh so we've got this this architecture and what I have done is added a file store just an s3 bucket and I've already moved all of the images across to there uh but I need to reference that within the application so I can just use again environment variables and say this is where you need to look for the uh for the uploads for those for those cats and in the in the back end it works and my front end templates I'm going to point to the same environment variable and I've got those cats on the front end again as well but how do I upload new cats I've already moved all the old ones over how do I upload new cats it's a very valid question there are different ways of doing it but one way is to use presign URLs um let's have a show of hands how many people have used presign URLs who hasn't used one but knows what one is good I get to show you some yaml now some uml now okay so we start off with a client our client will be our web browser and the web browser says to the server hey look I want to upload something can you get me a URL that I can use and that URL will have a token in it and the server says to amazon s3 hey listen somebody wants to upload something give me a URL that they can use to access uh to to to upload to now amazon says to the server yeah sure here it is here's here's the URL here's everything you need and the server says back to the browser here you go and then the browser says directly to amazon hey look here's that thing that you're expecting that the server told you that I was going to upload and amazon says great fantastic brilliant and then the client says back to the server look I've done that I've pushed it up you can update your record and then optionally the server can say to s3 hey look all right that's done we've got the new file we can delete the old one that is pre-signed URLs in a nutshell the idea is that the server pre-authenticates for the client and then the client goes ahead and completes what was uh completes the upload so what I've done is added a controller here with two routes in it one is uh to upload a kitty image and the other one is to get the pre-signed URL the content of those uh those methods isn't important right now but that's that's that's what we have and I've added some javascript to uh which is where the client does the interaction between the server and to s3 yes it's jQuery don't hate me um and what I can do now is actually remove that third party uploading bundle that I had and from my entities I can remove all of the code that was related to that as well so I'm kind of cleaning up my entities a little bit by removing stuff that I didn't necessarily want in there felt a bit dirty putting it in there so I can remove all that anyway and the great thing is now I can select any kitty in the list and I can click this upload kitty image button I can select a cat and you can see that it's changed uh so there's no actual uploading happening to lambda or to my server itself what we've got is the client saying hey let's stick this straight on amazon but let the server know when we've done it so let's have a recap now at what we've just done we've added breath to an existing site we've fixed the assets that were broken by moving them over to a cdn we've moved the session storage to a database we've run console commands to migrate the database and we've uh we've put presign URLs in to handle image uploading we've now got a completely serverless uh website and it didn't take long to do yay so let's think about performance cold boots for a start remember I told you about vpcs and their performance implications amazon have promised or they've told us that they're going to fix this early this year so we're almost kind of getting to mid 2019 so hopefully this will be coming soon but the trouble with cold boots is if we remember so we go from nothing and it creates the container and it bootstraps your runtime and then starts waiting for um waiting for requests right at the end here where it says warm start so the cold start is everything that comes before that where it sets up fpm and and all the rest when your code is in a vpc it adds load adds work to that cold start which means that you get extra security but your cold boots are very very long well how long you might ask depends on the memory you assign to your lambda function if you only have 128 megabytes on your lambda function it takes 11 seconds to start that container if you add more memory it brings it down it brings it down it brings it down um so hopefully this is going to be fixed very very very soon so that we can all have really fast really secure websites okay until then you've got to choose another option is to to keep the vpc's warm and you can use services like pingdom uh to do that if you're using pingdom any way to monitor your uptime then you've kind of got that for free and you reduce the chance of your users getting that 10 or 11 second wait but it feels kind of hacky and i'd much rather amazon just fixed it now all i want for christmas is fast php lambda which uh which kiran said in uh in in the slack channel uh some time ago now well look we're the layers thing gives us options to to to explore performance we couldn't do that before when we had the shim and we were pushing the js shim and we were pushing the binary up with that and trying to call that we just didn't have that option with layers we can we can experiment because we completely control the type of server that runs now we've got some performance benchmarks and early performance benchmarks which um which were created by the guy who initially wrote breath and the two that we've got here so the lower one here uh which is option e which is running php fpm the fastest we've got php down to is about one millisecond response and we've got an average of 18 milliseconds for a symphony response option a which is which has got the little warning sign next to it and is experimental using um php react kind of ideas we've shared memory and and those kind of things here be dragons uh we've got a symphony response down to six milliseconds that's three times faster on average for using that and let's say we have these options and there are many many more things that we can do to try to improve this but how much further can we go what about microservices what about if you're using messaging and sms uh and reacting to that with lambda you don't need uh an HTTP application or a console app what you need is just a function that's going to receive the um receive the event and act upon it where you can do we give you that option you can say i want to create a php function choose option zero and you're away you get that event and the great thing about that is then you can use the same code to send your message as you do to receive it you can if you've got validation you can you can serialize in php send it through sns and then un serialize it through php and you get back the exact same object now i know you're all wondering now how do i roll my own because we don't give you a lot in those layers you want to be able to do things there are a couple of options here um it's all kind of new ground for us there is a company um who are getting fully involved in the project and they've created a bunch of extensions to help you create layers if you want the other option right now is to clone the breath project and then you can open up the docker file which we compile php from add in anything that you want and then just run make publish and then what happens is your laptop fans go crazy for about 10 minutes and it uploads the layers for you and that's exactly what i did when i was playing with getting wordpress running i needed my sqli extension which we don't provide in breath so i thought well let's go in and let's do that and let's add my sqli which is which is interesting like i said we can probably start supporting anything in php with enough time with enough uh resources to to kind of play with it and do it um so does wordpress work with breath well sort of this is as far as i got after nearly breaking my laptop with those fans running for forever um it's an old laptop it doesn't really like doing much these days um we got it compiled and we got it running but i don't have enough experience with wordpress to be with with with developing wordpress locally with the remote database and all the rest and each time i don't know i just don't know enough about wordpress to really pursue it any further so if anybody that knows wordpress can get involved and kind of go hey look here's how we do it uh with a remote database and all the rest then that'll be that'll be pretty cool i think we can support wordpress quite easily wouldn't it be great if we could put in layers for like black fire and do deep profiling on things that are happening within within lambda that's something before layers we wouldn't have been able to do that we'd have been reliant upon the um the logs that you get within uh aws with it for for cloud watch metrics and things like that but now we can think about yeah we could add a layer for this i would love for that to happen this is my own aws billing console i started playing with breath around august last year and look here i have completely eliminated my load balancing cost completely and my other ec2 costs are coming down i've got one ec2 server left uh and that's because i haven't yet emailed the guy that's got the only site left on it to say that i'm shutting the server down and when i do that then i will have zero ec2 costs i think that's pretty good i've still got costs for other things like uh like uh elb and it's not elb rds and stuff but i'm looking at eliminating those as well so what are we working on at the moment we're trying to get better documentation we're improving speed and stability we're trying to think of a a recommended method of creating your own run times like i said you've got two options right now uh one is to use the that third party companies breath extensions uh library or you can clone breath and do it yourself and we want to have better framework integrations and of course a better deployment method from local so the thing to do is join us i i don't even know what this photo is about i i found it on unsplash um and i thought well i've got to use that so so join us um either at my builder come and join me come and work with me come and talk to me get on board with what we do or get involved with the project and tweet me and let me know what you thought or if if there are any problems um but please do get involved in the project even if it is just to try out and say i think your documentation isn't clear here or i tried this and it didn't quite work in my use case what can we do about it um and we'll try and take these things on board uh but if you've got any questions now do we have time yeah we've just about got time before lunch and we'll uh we'll we'll uh i'll do my best uh i'm sorry if i'm not wrong lambda had a limit for request size presign to url fixes that for file upload but is it still applicable that there was five megabytes or something like that ooh you might be right there um you know i haven't looked into that i knew there'd be something that hadn't looked into that somebody would ask me um you know i'll look into it and i'll tweet it out and uh and and get back to you on that because i i simply don't have the the answer on top of my head so and i had the second question so without forking breath without forking breath it's impossible to custom uh to install custom php extensions right it's not impossible but you have to you have to for all all yourself so you need to fork fork a breath and you don't need to fork breath um you can just clone it and then run it yourself and then what will happen is it will upload the the layers to your own account right so you won't be using breath's extensions that they're official extension repository but you'll have them uploaded to your own account and you'll be able to you're able to use those thank you is anybody else i can't really see people at the back is anyone to be there oh we've got somebody down the front yeah honey me um the request and payload for lambos six meg um just so you want to not on okay thank you um what's the difference between breath versus using stackeries images or serverless dot com sure okay so um the previous version of breath used serverless uh and it wasn't it wasn't a decision that i made that the guy who's running the who's leading the project when the when the layers came out he said look lambda is is kind of the most ubiquitous thing that everyone's using we should support that rather than trying to support everything it's the idea of getting rid of the kitchen sink and being opinionated so that we can do one thing and do it well so that's why we don't do um use serverless for the deployment anymore there with with regard to uh other options i know that rob allen who would have been here today is is working on something called image to lambda i don't know a lot about that but i think that that is something to do with taking your docker containers and pushing that to lambda and doing pretty much the same thing um so that's another option i haven't i haven't really looked into it so i don't i don't really know um but the point with breath is that we do one thing and we optimise it for that and we do it well and if you want to extend it and take it and run with it and and do things like that then you can do and you know that you've got a basic thing that's predictable that you can run with uh i hope that kind of kind of addresses your your question there i just have one question about um where i can get more technical information about how um breath uses docker i'm very interested in both subjects so sure okay so breath only uses docker uh in fact it doesn't directly use docker it's uh sam local which uses docker which is the aws package that uh that is provided by aws for the deployment so we don't actually do anything with docker within breath apart from the compilation which i just lied to you about there so yeah so we so we do compile php uh for the layers with docker but we're not actually using docker as as part of the normal workflow we're using aws sam local for that which is completely separate it's just that it's easier to use aws's own tool for the doing a deployment than it is to to do that ourselves um and what we do is we kind of we kind of set up the template for your aws sam deployment structure that's that's about as far as we go with with that is anybody else very good hi um most probably being a bit naive but um what's the pricing for lambda and and is there a crossover where it's mostly just easier just to keep with a vpc no sure okay um well i showed you my own results i i mean my my results there they're very infrequently used websites uh so i've i've basically knocked my costs down to nothing so i was spending about 150 pound a month just on load balances and and ec2 instances um and now it's it's negligible up to a certain point it's going to be cheaper um to use lambda but i think you're probably going to have to look at your use case and and and figure it out so the costings are all provided on the aws website as i'm sure you can get the costings for ec2 and you can get the costings for lambda et cetera it just takes a bit of rudimentary maths i think to say this is the amount of requests we get and this is like how much it's we project that it's going to cost the thing about this as well um being behind api gateway is that you can configure api gateway to block a bunch of requests that otherwise would get through to breath if you if you've got um maybe a set number of uh or a set of routes which are allowed into your application you can say anything outside of that which was in that um those those proxy urls in the template.yaml you can say you can get rid of the catch all and say only allow these ones through that match and then what happens is api gateway blocks that at the edge and you never even get charged for those to come through to lambda so you can probably optimise your costs in that respect um but i think you probably need to look at your own use case to figure out how much it's going to cost you or maybe experiment with it.