ITB2016 - AWS lambda

Download ITB2016 - AWS lambda

Post on 26-Jan-2017

91 views

Category:

Technology

2 download

Embed Size (px)

TRANSCRIPT

<p>PowerPoint Presentation</p> <p>AWS LambdaWhat, why, when, how?</p> <p>Andrew DixonWork for a digital agency call mso since 2000Technical DirectorWe are pivoting from a service agency to a product developer in the education sectorDevelopment platform of choice is Lucee but with new services like Lambda we are using these as well when they fit for our purposes3</p> <p>What is Lambda?</p> <p>Introduced by AWS in Oct 2014Compute service that runs code in response to events4</p> <p>Compute service where you don't think about</p> <p>Compute service and the interesting thing about it is what you dont have to think about5</p> <p>Servers</p> <p>You dont have to think about infrastructure, which has interesting consequences 6</p> <p>Capacity</p> <p>Dont worry about being under or over capacity, you can just give work to Lambda and it will do the compute for you.Same way as you give S3 your objects to store.Problems of having too many or too few servers dont occur7</p> <p>Deployments</p> <p>As your not worrying about the infrastructure, you dont have to worry about how to get things onto the infrastructureNo challenge of deploying code onto a fleet of servers, thats Lambdas problem8</p> <p>Scaling</p> <p>Scaling is all done automatically, you just make a request for compute and Lambda gives it to you.9</p> <p>Fault tolerance</p> <p>Again, all taken care of automatically by Lambda, it is fully managed and under the hood it sorts everything out, like:Availability zonesSpinning machines up and downTaking care of unhealthy hostsAll the things that have nothing to do with your business value as such, but stand between you and deploying production apps at scale10</p> <p>Metrics and logging</p> <p>The boiler plate activities like logging come ready made out of the box.11</p> <p>Automatic OS andlanguage updates</p> <p>As well as OS and language updates12</p> <p>All of that is taken care of automatically</p> <p>All taken care of for you, automatically, so there is nothing to manage.13</p> <p>You can easily</p> <p>But it is not a straight jacketVery flexible14</p> <p>Bring your own code, including native libraries</p> <p>For example, for Node you can bring a library like momentjs15</p> <p>Run code in parallel</p> <p>Because each Lambda call is a separate instance it automatically allows you to run code in parallelMassively and easily in parallelTell Lambda what you want it to run and it figures out how to get the code started.16</p> <p>Lambda use cases</p> <p>17</p> <p>Create backends</p> <p>Lambda is excellent for backends, mobile backends, web backends, IoT backends, etc 18</p> <p>Create event handlers</p> <p>Lambda responds to your events19</p> <p>Create dataprocessing systems</p> <p>If you have some data, somewhere, then you can use Lambda to recognise that data is there and get it to process it.20</p> <p>Serverless</p> <p>Amazon talk about Lambda as being a serverless environment, which of course is a misnomer.But because of this one of the most interesting things is the economics of itBecause you are not worrying about all the management there is a productive benefit to you because you dont have to spend time and therefore money on it21</p> <p>Event-driven scale</p> <p>This means that you dont have to worry about under or over provisioning to handle burst capacityThe scale is driven automatically from the events22</p> <p>100ms billing units</p> <p>Billed in fine grain 100ms units so as soon as your computation has finished you stop paying.23</p> <p>You never pay for idle!</p> <p>And when you dont have the infrastructure, you dont have to worry about under-utilising the infrastructure so you never pay for idle.24</p> <p>How it works</p> <p>How all of this works is relatively simpleCreate your function, that does the required task25</p> <p>Upload code in a zip file</p> <p>Take your code, and native libraries, in the form of a zip file upload that to Lambdaeither directly or from S3.From that point, Lambda is ready to deploy and run your code.26</p> <p>Code can be</p> <p>v0.10 &amp; v4.3Java 8v2.7</p> <p>Node JS version 0.10 and 4.3Java version 8Python version 2.727</p> <p>Code is stateless, persistence goes elsewhere</p> <p>The code that you upload is statelessPersistent data is put elsewhere, e.g. S3, RDS, DynamoDB, etc28</p> <p>Monitoring and logging handled automatically by CloudWatch</p> <p>For monitoring and logging you have built-in support for CloudWatch metrics and logs29</p> <p>Integrates with otherAWS services</p> <p>Lambda integrates with lots of other AWS solutions including30</p> <p>S3</p> <p>DynamoDB</p> <p>RDS</p> <p>VPC</p> <p>CloudWatch</p> <p>CloudFormation</p> <p>Cognito</p> <p>SNS</p> <p>API Gateway</p> <p>SES</p> <p>SWF</p> <p>Kinesis</p> <p>CloudTrail</p> <p>CloudWatchAll these &amp; more</p> <p>All these and moreS3, DynamoDB, RDS, API Gateway and so on...31</p> <p>Compute Power23 "power levels"</p> <p>32</p> <p>Specified in Lambdaas memory</p> <p>33</p> <p>From 128MBTo 1.5GB</p> <p>Ranging from 128MB to 1.5GB from a pre-defined list in 64MB incrementsWhile the power levels are express as memory you should think about them as the percentage of the machine that you are requesting.At 128MB you are getting a small slice of the machine and at 1.5GB you are getting the full power of the machine.34</p> <p>More memory = More CPU</p> <p>For CPU bound tasks allocate more memory for lower latencyFor example, choosing 256MB allocates approximately twice as much CPU power as requesting 128MB of memory and half as much as choosing 512MB.35</p> <p>Price scales withpower level</p> <p>36</p> <p>Pricing per 100ms(rounded up to nearest 100ms)</p> <p>37</p> <p>Run durations from100ms to 5 minutes</p> <p>38</p> <p>For compute intensive tasksset power level higher</p> <p>For compute intensive, set power level higher so that you pay more per 100ms but run for less time.39</p> <p>For I/O intensive tasksset power level lower</p> <p>For I/O intensive task, set power level lower as no point in paying for CPU.40</p> <p>Event Sources</p> <p>S3Schedule eventsAWS IoTCloudWatchDynamoDBKinesisSNSAPI Gateway (sort of)</p> <p>There are 7 event sources for Lambda and then there is API Gateway, which can invoke a Lambda function.41</p> <p>Serverless APIs withAWS API Gateway &amp; Lambda</p> <p>You can call Lambda functions to power an API via the API gateway, meaning you can create serverless APIsAPI gateway allows you to create HTTP endpoints that invoke a Lambda function(s).42</p> <p>Versioning</p> <p>Published versions are given and number and become immutableAliases can map to versions to give the end user a stable ARN, e.g. prod, dev, etc43</p> <p>By using versioningnothing changes</p> <p>By using versioning nothing changes in how you use LambdaUpload codeMake changes any timeLast update wins when no version number is specified44</p> <p>But now you canpublish a version</p> <p>Publish a new version from development at any timeThese published versions receive a numbered version and become immutableVersion numbers are a simple, integer counter starting at 1Versions of a function are accessed using the ARN with a colon and the version number, e.g. :1, :2, etc..45</p> <p>Versions can have aliases</p> <p>Versions can have aliases and aliases can move from one version to anothere.g. you could have a prod and dev alias and today prod points at version 1 and dev at version 2 but tomorrow prod could be at version 2 and dev at version 3, etcThis means the client can have a stable ARN but have the ability to change what that ARN does.Aliases can be moved to any version at anytime, so you could use it to roll forwards and roll back.46</p> <p>VPC Support</p> <p>Lambda functions can access private resources, e.g. RDS, private EC2 endpoints, Elasticache, etc47</p> <p>Pricing</p> <p>48</p> <p>$0.20 per 1 million requests</p> <p>49</p> <p>Pay for CPU usages in 100ms intervals. Price depends on memory allocation.</p> <p>From $0.000000208 to $0.000002501 per 100ms</p> <p>Pay for CPU usage in 100 millisecond intervals, so if you use 565ms you pay for 600ms. Price depends on memory allocation.</p> <p>50</p> <p>First 1 million request and400,000 GB-seconds of compute time per monthFREE!!!</p> <p>However first million request and 400,000 GB seconds are free, in perpetuity.51</p> <p>This is equal to approx.:888 hours at 128Mb.74 hours at 1.5Gb</p> <p>So if you have a small system with a limited number of requests you could get away without paying for any Lambda time at all.52</p> <p>Example uses</p> <p>Weve been using Lambda for over a year now for various different things.Mainly to try and remove heavy lifting from Lucee so we can reduce the instance sizes we are using.This has allowed us to reduce are overall cost base for compute.53</p> <p>Image processing</p> <p>Image processing is very CPU intensive.We have several clients that do a lot of image processing, both on user uploaded images and on images they are generating themselves.By shifting this to Lambda not only does it mean we can get maximum concurrencye.g. if 50 people all upload an image at the same time It can process all of them at the same time But the instance(s) the site is running on doesnt have to be able to cope with this.54</p> <p>Data processing</p> <p>Product used by schools - process large amounts of data from them every day.Originally this was all done in Lucee, but not sustainable.We would have to keep adding more and more instances to copeMoving it to Lambda has given us as much capacity as we will need, when we need it, without having to pay for it all the time.Not only can we run the data imports for all schools simultaneously, something we couldnt really do effectively in Lucee, but schools can also run it on-demand without it being a concern to us.55</p> <p>Scheduled Tasks</p> <p>We always had an issue with multiple instances or with auto-scaling clusters with scheduled tasks and where to trigger them from.You would not want your tasks on all instances if you only want that task to be run once a hour or once a day on one server, e.g. to send an email, etcWe are now using Lambda to trigger tasks, written in Lucee, using a simple HTTP call from Lambda.56</p> <p>Document generation</p> <p>Again, something else that can be heavy lifting like image processing, the generation of documents like PDFs, Word Documents, etc can be CPU intensive.Lambda let us move that off the web server and be dealt with independatley, without us having to worry about a peak surge in demand, e.g. lots of parents all trying to download their childrens school report as a PDF at the same time.57</p> <p>If you need help email meandrew.dixon@mso.net</p> <p>Essentially we used Lambda to remove the capacity headache while reducing our costs.Happy to help.58</p>