{"id":17904,"date":"2015-03-12T15:34:42","date_gmt":"2015-03-12T10:04:42","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=17904"},"modified":"2015-11-13T16:53:52","modified_gmt":"2015-11-13T11:23:52","slug":"introduction-to-aws-lambda","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/introduction-to-aws-lambda\/","title":{"rendered":"Introduction To AWS LAMBDA"},"content":{"rendered":"<p style=\"text-align: left;\" align=\"center\">The next buzz in cloud computing is the event-driven computing service. The service in preview mode <strong>\u201cAWS Lambda\u201d<\/strong> brings the same to existence. Lambda makes the best of the concept of &#8220;<strong>pay-per-use&#8221;<\/strong> and <strong>\u201cas a service\u201d<\/strong> much further than it did in the case of EC2. It offers <strong>pay-per-millisecond computing<\/strong>, a service always <em>available<\/em> without delays, <em>scalable<\/em> power, no systems <em>maintenance<\/em> costs,\u00a0<strong>response to events <\/strong>both from the rest of <a href=\"http:\/\/www.tothenew.com\/devops-automation-consulting\">AWS services<\/a> (such as a Kinesis stream or changes in DynamoDB) and events generated by your applications i.e. custom events (through API, the different SDK for programming languages or SDK for mobiles) .<\/p>\n<p>If we talk specifically, we can use AWS Lambda (currently) to respond to <em>table updates in Amazon DynamoDB<\/em>, <em>modifications to objects in Amazon S3 buckets<\/em>, <em>messages arriving in an Amazon Kinesis stream<\/em>, <em>AWS API call logs created by AWS CloudTrail<\/em>, and <em><strong>custom events<\/strong> from mobile applications, web applications, or other web services<\/em>.<\/p>\n<p><strong>Examples of using AWS Lambda<\/strong><\/p>\n<p><strong>\u00a0<\/strong>1) Suppose, if we upload a photo (from a mobile device) to S3 bucket, it will trigger a Lambda-function that we have written. The function will extract meta-data from that photo and put it on DynamoDB\u00a0and then it will trigger a function over all the streams of DynamoDB\u00a0to figure out which of the meta-data function, for example place, location or user are trending. This can be further enhanced, by adding a function that <em>notifies the customer if his\/her photo is one of the trending-photos<\/em>.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/s3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-17905\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/s3.png\" alt=\"s3\" width=\"1252\" height=\"397\" \/><\/a><\/p>\n<p>All of this can be done, without running any infrastructure or starting instances. So, it becomes really easy to build <strong>highly-reliable<\/strong> and <strong>concurrent application<\/strong> using Lambda.<\/p>\n<p>2) Suppose, we have an use case where we have to create a function to <strong>automate the creation of thumbnails<\/strong>. When a user uploads a photo to a bucket, a thumbnail of the same photo is automatically created and stored in the same bucket. Now, when the user opens his account, only the thumbnails are loaded to show a preview rather than the actual photo (<em>using a Lambda function on a web-app<\/em>).<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Thumbnail.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-17907\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Thumbnail.png\" alt=\"Thumbnail\" width=\"1035\" height=\"537\" \/><\/a><\/p>\n<p><i>To describe Lambda in more generic terms, the beauty of it is that you get to focus on your business logic instead of passing around data. You define a directed acyclic graph of small, composable functions and the rest happens on its own. This is the promise of <strong>Event-Driven Computing<\/strong> and Lambda.<\/i><\/p>\n<p><strong>&#8220;Focus on business logic not infrastructure&#8221;<\/strong><\/p>\n<p><strong>\u00a0<\/strong><i>Upload your code, Amazon Lambda handles:<\/i><\/p>\n<p>\u2022 Capacity<\/p>\n<p>\u2022 Scaling<\/p>\n<p>\u2022 Fault tolerance<\/p>\n<p>\u2022 Monitoring<\/p>\n<p>\u2022 Logging<\/p>\n<p style=\"text-align: justify; color: #ff9900;\"><span style=\"color: #000000;\"><strong>\u00a0Advantages of using AWS Lambda:<\/strong><\/span><\/p>\n<p>\u00a0\u2022 <i>AUTOMATIC SCALING<\/i><\/p>\n<ul>\n<li><i>Each object uploaded to Amazon S3 is an event <\/i><\/li>\n<li><i>Each event is a Lambda request <\/i><\/li>\n<li><i>Lambda <strong>scales<\/strong> to match the event rate <\/i><\/li>\n<li><i>Don\u2019t worry about <strong>over<\/strong> or <strong>under-provisioning <\/strong><\/i><\/li>\n<li><strong><i>Pay only for what you use<\/i><\/strong><\/li>\n<\/ul>\n<p>\u2022 <i>FINE GRAINED PRICING<\/i><\/p>\n<ul>\n<li style=\"text-align: left;\"><i>Price compute time <strong>by 100 ms \u00a0<\/strong><\/i><i>(so even short jobs make sense) <\/i><\/li>\n<li style=\"text-align: left;\"><i>Low request charge <\/i><\/li>\n<li style=\"text-align: left;\"><strong><i>No hourly, daily, or monthly minimums<\/i><\/strong><b>\u00a0<\/b><\/li>\n<\/ul>\n<p><strong>\u00a0Is Lambda a game changer?<\/strong><\/p>\n<p>Lambda isn&#8217;t a particularly a new concept i.e. Databases have had triggers but doing this at the cloud level is game changing. Building <strong>multi-service<\/strong>, <strong>event-based triggers<\/strong> on our own would have been a massive task at hand &#8211; we\u2019d have to assemble <strong>SQS, Kinesis, DynamoDB, and EC2<\/strong> clusters just to do it properly. But now we get it as part of AWS (&amp; as an <strong>service<\/strong>) . It enables us to run <strong>custom code<\/strong> in the cloud with <strong><em>zero administration<\/em><\/strong> and <em><strong>automatic scaling<\/strong><\/em>. Lambda runs our <strong>custom code<\/strong> on a <strong><em>high-availability<\/em><\/strong> compute infrastructure and administers all of the compute resources, including server and operating <strong><em>system maintenance<\/em><\/strong>, <em><strong>capacity provisioning<\/strong><\/em> and <em><strong>automatic scaling<\/strong><\/em>, code, and <em><strong>security patches<\/strong><\/em>.<\/p>\n<p><strong>What kind of code it supports?<\/strong><\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Node.js.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-17913\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Node.js.png\" alt=\"Node.js\" width=\"1050\" height=\"469\" \/><\/a><\/p>\n<p>Lambda is <strong>event-driven<\/strong> computing that supports code written in <a title=\"Node.js Development\" href=\"http:\/\/www.tothenew.com\/mean-node-js-development-consulting\">Node.js<\/a> (JavaScript). Your code can include existing Node.js libraries, even native ones.<\/p>\n<p><strong>\u00a0How secure is Lambda?<\/strong><\/p>\n<p><i><b>Lambda isolate<\/b><\/i><i><b>s<\/b><\/i><i><b> <\/b><\/i><i><b>our<\/b><\/i><i><b> code<\/b><\/i> &#8211; Each AWS Lambda function runs in its own <strong>isolated environment<\/strong>, with its own resources and file system view. AWS Lambda uses the same techniques as Amazon EC2 to provide security and separation at the infrastructure and execution levels.<\/p>\n<p><i>This is what AWS announced during the launch of AWS Lambda.<\/i><\/p>\n<p>\u201c<i><b>With Lambda, you simply create a Lambda function, give it permission to access specific AWS resources, and then connect the function to your AWS resources. Lambda will automatically run code in response to modifications to objects uploaded to Amazon Simple Storage Service (S3) buckets, messages arriving in Amazon Kinesis streams, or table updates in Amazon DynamoDB.\u201d<\/b><\/i><\/p>\n<p><i>Adding more to the cost-effectiveness of the service <\/i><\/p>\n<p>\u201c<i>From now on, it will be possible to calculate in the cloud asynchronously without having to provision infrastructure or adjust auto scale rules, and pay exclusively for the exact work required, all thanks to AWS Lambda<b>.\u201d<\/b><\/i><\/p>\n<p><strong>Use case<\/strong><\/p>\n<p>Initially, AWS changed the way computing used to be i.e. complete set of infrastructure to be managed programmatically just as operating Systems did provide <em><strong>abstraction<\/strong><\/em> over the hardware layer. Now, with AWS Lambda, this process of abstraction is further extended.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Abstraction-Layer.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-17908\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Abstraction-Layer.png\" alt=\"Abstraction Layer\" width=\"1156\" height=\"495\" \/><\/a><\/p>\n<p>Lambda can replace <strong>inefficient procedural systems<\/strong> and create a complete event-driven service for use that can be controlled by <strong>rules<\/strong>.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-17909 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Application-Management.png\" alt=\"Application Management\" width=\"1082\" height=\"286\" \/><\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Netflix.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-17912\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Netflix.png\" alt=\"Netflix\" width=\"86\" height=\"26\" \/><\/a>\u00a0is world&#8217;s leading Internet Television network with over 57 million members in nearly 50 countries (Source: <a title=\"netflix\" href=\"http:\/\/ir.netflix.com\/\" target=\"_blank\">ir.netflix.com<\/a>) and the content can be seen on any internet-connected screen.<\/p>\n<p>So, let&#8217;s see the following use cases:<\/p>\n<p><strong>1) Encoding Media Files<\/strong><\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Encoding-media-files.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-17911\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Encoding-media-files.png\" alt=\"Encoding media files\" width=\"1011\" height=\"407\" \/><\/a><\/p>\n<p>The studios pushe\u00a0media files to S3, which is with Netflix. The media is chopped into chunks of 5 minute each &amp; each chunk is encoded. The chunks are now re-packaged and deployed by Netflix &amp; made available to the end-user.<\/p>\n<p>The whole process and its <strong>monitoring<\/strong> and <strong>validation<\/strong> is done through <em><strong>Lambda&#8217;s Rules<\/strong><\/em> and <em><strong>Events<\/strong><\/em>. The Events are fired to <strong><em>track, aggregate, validate, tag<\/em><\/strong> and finally <em><strong>publish<\/strong><\/em>.<\/p>\n<p><strong>2) Backup for Disaster Recovery<\/strong><\/p>\n<p>In the\u00a0production environment, hundreds of processes <strong>save<\/strong> or <strong>update<\/strong> database continuously (<em>imagine the amount of data and relative updates!<\/em>). With Lambda, we can decide the data <em><strong>rules &amp; events<\/strong><\/em> that can <strong>trigger<\/strong> on the data update. Besides this, we can use it to trigger what needs to be <em><strong>backed up<\/strong><\/em> &amp; copied to off-site storage &amp; check and <strong><em>validate<\/em><\/strong> that it arrived safely. It can further <em><strong>re-make the copies, re-check &amp; re-validate<\/strong><strong> data<\/strong><\/em>. It can also raise <strong>alarms<\/strong> in case of failure.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-17910 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Backup-for-DR.png\" alt=\"Backup for DR\" width=\"803\" height=\"378\" \/><\/p>\n<p><strong>\u00a03) Monitoring<\/strong><\/p>\n<p>Lambda includes <em><strong>monitoring<\/strong><\/em> features on its own Dashboard i.e. there is no need to configure alerts against each service, unlike our current practice.Monitoring enables us to <em><strong>validate the current state of our configuration<\/strong><\/em> and in case of <strong><em>failure<\/em><\/strong>, <em><strong>proper follow-up<\/strong><\/em> can take place accordingly.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Monitoring.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-17916\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Monitoring.png\" alt=\"Monitoring\" width=\"935\" height=\"477\" \/><\/a><\/p>\n<p>* It generates logs in <em><strong>CloudWatch<\/strong><\/em> and they can be seen from the console.<\/p>\n<p style=\"text-align: justify; color: #ff9900;\">For implementation and Demo, visit:<\/p>\n<p style=\"text-align: justify; color: #000000;\"><a>http:\/\/www.tothenew.com\/blog\/aws-lambda-invocation-using-amazon-s3-invocation\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The next buzz in cloud computing is the event-driven computing service. The service in preview mode \u201cAWS Lambda\u201d brings the same to existence. Lambda makes the best of the concept of &#8220;pay-per-use&#8221; and \u201cas a service\u201d much further than it did in the case of EC2. It offers pay-per-millisecond computing, a service always available without [&hellip;]<\/p>\n","protected":false},"author":166,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4},"categories":[1174],"tags":[1679,1688,1691,1545,1689,1690],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/17904"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/166"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=17904"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/17904\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=17904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=17904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=17904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}