<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Serverless on Medium]]></title>
        <description><![CDATA[Stories by Serverless on Medium]]></description>
        <link>https://medium.com/@serverlessinc?source=rss-10625560e1ed------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Pjpah36Q3uZcsCEBV-rpnw@2x.jpeg</url>
            <title>Stories by Serverless on Medium</title>
            <link>https://medium.com/@serverlessinc?source=rss-10625560e1ed------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 14:35:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@serverlessinc/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Serverless monitoring — the good, the bad and the ugly]]></title>
            <link>https://medium.com/@serverlessinc/serverless-monitoring-the-good-the-bad-and-the-ugly-a3b4ac80c310?source=rss-10625560e1ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3b4ac80c310</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <dc:creator><![CDATA[Serverless]]></dc:creator>
            <pubDate>Fri, 03 Jun 2022 14:55:19 GMT</pubDate>
            <atom:updated>2022-06-03T14:55:19.886Z</atom:updated>
            <content:encoded><![CDATA[<h3>Serverless monitoring — the good, the bad and the ugly</h3><p>Originally posted at <a href="https://www.serverless.com/blog/serverless-monitoring-the-good-the-bad-and-the-ugly/">Serverless</a> on September 26th, 2017</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/0*oGt9Cb9MZrPw9N7N.gif" /></figure><p>Not so long ago, a job requirement pushed me into the world of FaaS, and I was thrilled. I had dreams of abstraction — eliminating all that tedious work no developer likes doing. “We are not operations engineers!” I exclaimed proudly. “We should not need to dabble in the dark arts of the Linux Shell.”</p><p>But little did I know how wrong I was. We humans are creatures of habit, and one of my habits as an AWS user is checking the AWS Console religiously. It was my central place to monitor everything I needed to know about my servers’ health.</p><p>Now comes the difficult question: How does monitoring work when using AWS Lambda and Serverless?</p><h3>Monitoring 101</h3><p>All applications have metrics we, as developers, need to monitor. This is crucial: downtime and slow apps can create some pretty grumpy customers.</p><p>Trust me, I get angry phone calls and rage mail every once in a while. So how can you avoid getting yelled at by customers? Track your errors and monitor your software!</p><p>Implement a good notification system that lets you know when and where an error occurred. Make sure to have good and easy to view logs of all errors, warnings and other crucial data your application creates. Be responsible for the software you write. Because it is our legacy as developers. We have made an oath, to be creators of awesome stuff!</p><p>But user experience is only one side of the performance metrics. The second crucial metric is the measure of computational resources. How much resources is the app consuming. If it is too much you need to scale down your servers, otherwise, if the app is capping all resources you may consider larger servers or more of them.</p><p><strong><em>Note</em></strong><em>: I recently came across an </em><a href="https://hackernoon.com/node-js-monitoring-done-right-70418ecbbff9"><em>awesome article</em></a><em> on this topic by none other than the CTO of RisingStack, Peter Marton. He explained in detail how to do monitoring right. I urge you to take a peek, it will change your view on monitoring forever.</em></p><h3>Overhead?</h3><p>Excuse me…? Can I have some monitoring, please? But, without being a burden on my application.</p><p>We’re lucky that, in 2017, this is a given. Monitoring software has become so advanced that in today’s world of programming the overhead is minimal. The sun was not shining so bright back in the day. Monitoring applications was followed by a known fact that it would impact your app’s performance significantly.</p><h3>How does this translate to Serverless?</h3><p>The Serverless revolution has been gaining strength for the past few years. I see no reason for it to stop. The hype is real.</p><p>Developers are starting to view the <strong>F</strong>unction as a <strong>S</strong> ervice architecture as a savior, something that makes it possible to scale applications automatically and serve only as many users as needed. The pay-as-you-go method cuts costs drastically and makes it possible for startups to create awesome software for a fraction of the cost.</p><p>But, wait a minute. What else needs to be cut for that to become a possibility?</p><p>A couple of things come to mind. The overview of your code performance and tracking errors are first. Silent failures as well. How do you monitor the performance of a server that is not a server? Schrödinger’s server? Okay, now my head hurts.</p><p>This paradox needs a new perspective. Monitoring Serverless is a new beast in itself. Traditional methods will not work. A new mindset is in order.</p><pre>server != functions</pre><p>Instead of telling our functions to send along additional data with every invocation, why not just collect their residual data? This is a cool idea! It’s a known fact all AWS Lambda functions send their logs to AWS CloudWatch.</p><h3>Serverless is unforgiving</h3><p>Unlike in traditional applications, you don’t have full overview of every part of your system. Not to mention how hard it is to test Serverless. You have to push code to AWS to see if it’s working or spend an eternity on setting up emulators on your local machine. The process is incredibly tedious. Not to start with adding third-party services to your app. It creates overhead and additional costs. Try attaching monitoring services to every single Lambda function. That’s never going to scale well!</p><p>Let’s imagine a scenario of monitoring a simple function on AWS Lambda. The purpose is to test the function and check the verbosity of the logs on CloudWatch.</p><p>After hitting the endpoint with Postman a couple of times I’m assured it works fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hfQJruXEfZ1ZAkrt.png" /></figure><p>Opening up CloudWatch I can see the logs clearly. All the function invocations are listed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pLvsHuoTJe9h_Zns.png" /></figure><p>The logs are extensive, the only issue is I can’t seem to make any sense of them. I can see the functions we’re invoked, but not much else. Error messages for failing functions are not verbose enough, so they often go unnoticed. I’m also having a hard time finding functions that timed out.</p><p>I also tried logging through the command line. It shows possible errors a bit better, but still, not good enough to have peace of mind.</p><pre>serverless logs -f my-function</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NwyIsPnvRhl5T-wL.png" /></figure><p>Not to mention the tiresome nature of having to push code to AWS every time you’d want to try out something new. Thankfully, all is not lost.</p><h3>Making my life less miserable</h3><p>What if I didn’t need to push code to AWS every time I wanted to test something? All heroes don’t wear capes. Like a knight in shining armor, <a href="https://github.com/dherault/serverless-offline">Serverless Offline</a> comes barging in to save the day! At least now I can test all my code locally before pushing it to AWS. That’s a relief.</p><p>Setting it up is surprisingly easy. Installing one npm module and adding a few lines to the serverless service’s <strong>serverless.yml</strong> and voila, API Gateway emulated locally to run Lambda functions.</p><p>Switching to the directory where I created the sample function and service, I just ran the following command in a terminal:</p><pre>npm install serverless-offline --save-dev</pre><p>After installing serverless offline I just referenced it in the <strong>serverless.yml</strong> configuration:</p><p>Back in my terminal running Serverless offline is as easy as just typing:</p><pre>serverless offline start</pre><p>That’s it, a local development simulation of API Gateway and Lambda is up and running!</p><h3>The logs are still bad though…</h3><p>I still can’t get over the fact how bland the logs are. Not to mention the lack of error reporting. I took me a good while to find failing functions in the logs. Imagine the nightmare of tracking them in a large scale production application. This issue is what bothers me to most. The lack of overview. It’s like swimming in the dark. I don’t have the slightest clue what’s down there.</p><p>What did I do? I went hunting. There has to be something out there on the web that can help me out. I was looking for a way to simulate the monitoring and logging of a server. I thought maybe there’s a way to create a broader perspective over the whole serverless system. What I found blew me away, in a good way. A bunch of tools exist that parse and analyze logs from all functions in a system on the account level. Now that’s cool.</p><p>I decided to try out <a href="https://dashbird.io/">Dashbird</a> because it’s <a href="https://dashbird.io/pricing/">free</a> and seems promising. They’re not asking for a credit card either, making it a “why not try it out” situation.</p><p>They say it only takes 5 minutes to hook up with your AWS account and be ready to go, but hey. I’m a skeptic. I timed myself.</p><p>The onboarding process was very straightforward. You just add a new policy and role on your AWS account, hook it to your Dashbird account and that’s it. They even have a great <a href="https://dashbird.io/docs/get-started/quick-start/">getting started tutorial</a>.</p><p>If you want to know, the timer stopped at 4 minutes. I’m impressed.</p><p>However, I’m much more impressed with Dashbird. I can finally see what’s going on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*QyGbyhcQtXJ-SiA2q6bbyQ.png" /></figure><p>Errors are highlighted, and I can see the overall health of my system. I feel great all of a sudden. It also tracks the cost so I don’t blow the budget. Even function tailing in real-time is included. Now that’s just cool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*BpYTAJ_zKsUvFWDFJY1E5Q.png" /></figure><p>With this watching my back I’d be comfortable with using Serverless for any large-scale application. The word relief comes to mind.</p><h3>Final thoughts</h3><p>Whoa… This has been an emotional roller-coaster. Starting out as a skeptic about the ability to monitor and track large-scale Serverless apps, I’ve turned into a believer.</p><p>It all boils down to the developer mindset. It takes a while to switch from the mental image of a server to FaaS. Serverless is an incredible piece of technology, and I can only see a bright future if we keep pushing the borders with awesome tools like Serverless Offline, Dashbird, CloudWatch, and many others.</p><p>I urge you to check out the tools I used above, as they have been of great help to me.</p><p>Hope you guys and girls enjoyed reading this as much as I enjoyed writing it. Until next time, be curious and have fun.</p><p><em>Do you think this tutorial will be of help to someone? Do not hesitate to share. If you liked it, let me know in the comments below.</em> <strong>Tools:</strong> <strong>Resources:</strong></p><ul><li><a href="https://hackernoon.com/node-js-monitoring-done-right-70418ecbbff9">https://hackernoon.com/node-js-monitoring-done-right-70418ecbbff9</a></li><li><a href="https://blog.risingstack.com/monitoring-nodejs-applications-nodejs-at-scale/">https://blog.risingstack.com/monitoring-nodejs-applications-nodejs-at-scale/</a></li><li><a href="https://en.wikipedia.org/wiki/Application_performance_management">https://en.wikipedia.org/wiki/Application_performance_management</a></li><li><a href="https://medium.com/dashbird/is-your-serverless-as-good-as-you-think-it-is-2baa3d36b1de">https://medium.com/dashbird/is-your-serverless-as-good-as-you-think-it-is-2baa3d36b1de</a></li></ul><figure><a href="https://console.serverless.com/?view=register&amp;utm_campaign=Console%20Signup&amp;utm_source=medium&amp;utm_medium=post&amp;utm_content=Serverless%20monitoring%20-%20the%20good%2C%20the%20bad%20and%20the%20ugly"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coRpboSHyAtv5UPafeHzbw.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NCHqjhEtW2FQQm5NO0ekAg.png" /></figure><p><em>Originally published at </em><a href="https://www.serverless.com/blog/serverless-monitoring-the-good-the-bad-and-the-ugly/"><em>https://www.serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3b4ac80c310" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Manage Your Alexa Skills With Serverless]]></title>
            <link>https://medium.com/@serverlessinc/how-to-manage-your-alexa-skills-with-serverless-b4f7bee08d3d?source=rss-10625560e1ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4f7bee08d3d</guid>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[alexa]]></category>
            <category><![CDATA[alexa-skills]]></category>
            <dc:creator><![CDATA[Serverless]]></dc:creator>
            <pubDate>Thu, 02 Jun 2022 22:36:49 GMT</pubDate>
            <atom:updated>2022-06-02T22:36:49.021Z</atom:updated>
            <content:encoded><![CDATA[<p>Originally posted at <a href="https://www.serverless.com/blog/how-to-manage-your-alexa-skills-with-serverless/">Serverless</a> on January 8th, 2018</p><p>Masashi here, creator of the Serverless Alexa plug-in.</p><p>Serverless and IoT go hand in hand, and it’s easy to use the <a href="https://serverless.com/framework/">Serverless Framework</a> to develop AWS Lambda functions for Alexa Skills.</p><p>Unfortunately, you can’t control Alexa Skills with the Framework, which was a bummer to me because I found the Alexa Skills Kit webapp and <a href="https://www.npmjs.com/package/ask-cli">ask-cli</a> didn’t have the simplicity I’d come to love with the Serverless Framework.</p><p>But! Luckily, the Serverless Framework has a great plugin system. I decided to solve this little problem with the power of the community!</p><p>The <a href="https://github.com/marcy-terui/serverless-alexa-skills">Serverless Alexa Skills Plugin</a> lets you integrate Alexa Skills into the Serverless Framework. We can now control the manifest and interaction model of Alexa Skills using sls command and serverless.yml!</p><h3>Installation</h3><p>The plugin is hosted by npm:</p><pre>$ npm install -g serverless<br>$ sls plugin install -n serverless-alexa-skills</pre><h3>Get your credentials</h3><p>Login with Amazon is an OAuth2.0 single sign-on (SSO) system using your Amazon.com account.</p><p>To get your credentials, log in to the <a href="https://developer.amazon.com/">Amazon Developer Console</a>, go to Login with Amazon from APPS &amp; SERVICES, and then Create a New Security Profile:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fH3Dqq2HqVJxmKub.png" /></figure><p>For following columns, you can enter whatever you like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oRZP_-rBS3Ujre9g.png" /></figure><p>Go to the Web Settings of the new security profile:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4-HhybyQInMoNvkA.png" /></figure><p>Allowed Origins can be empty. Enter http://localhost:3000 in Allowed Return URLs. This port number can be changed with serverless.yml, so if you want to change this, please do so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*__ZNPP5hjGvVYpwb.png" /></figure><p>Remember your Client ID and Client Secret of the new security profile, as well as Vendor ID. You can check your Vendor ID at <a href="https://developer.amazon.com/mycid.html">here</a>.</p><p>You only need to do this process once. You can continue to use the same credentials as long as you use the same account.</p><p><strong>The troublesome browser click-work is over!</strong> 👏 Let’s move on to the sls command.</p><h3>Put your credentials into the Framework</h3><p>Write the Client ID, Client Secret, and Vendor ID to serverless.yml. It is good to use environment variables as it is shown below.</p><p>Change the port number with Allowed Return URLs of Login with Amazon, add localServerPort, and write the port number:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/444bf4033d83185b219606c17b07c701/href">https://medium.com/media/444bf4033d83185b219606c17b07c701/href</a></iframe><p>Then, execute the following command:</p><pre>$ sls alexa auth</pre><p>This command opens the login page of Amazon.com in your browser. You will be redirected to localhost:3000 after authenticating. If the authentication is successful, you&#39;ll see the message: &quot;Thank you for using Serverless Alexa Skills Plugin!!&quot;.</p><p><strong>note:</strong> The security token expires in 1 hour. Therefore, if an authentication error occurs, please re-execute the command. I’m planning to implement automatic token refreshing in the future.</p><p>Let’s make a skill!</p><p>To start, execute the following command:</p><pre>$ sls alexa create --name $YOUR_SKILL_NAME --locale $YOUR_SKILL_LOCALE --type $YOUR_SKILL_TYPE</pre><p>These are descriptions of the options:</p><ul><li>name: Name of the skill</li><li>locale: Locale of the skill (en-US for English, ja-JP for Japanese and so on)</li><li>type: Type of the skill (custom or smartHome or video)</li></ul><p>A manifest is initially set for the skill. You can check the manifest with the following command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdd15841e8f426f6d5996f9d7494d370/href">https://medium.com/media/bdd15841e8f426f6d5996f9d7494d370/href</a></iframe><p>Copy [Skill ID] and [Skill Manifest] and paste it to serverless.yml as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/450fe8606880c4cf064f9cc7c3f506bf/href">https://medium.com/media/450fe8606880c4cf064f9cc7c3f506bf/href</a></iframe><p>Execute the following command to update the manifest after updating your serverless.yml (or you can use the --dryRun option to check the difference between the local setting and the remote setting without updating):</p><pre>$ sls alexa update</pre><p>You can see the format of the manifest <a href="https://developer.amazon.com/docs/smapi/skill-manifest.html#sample-skill-manifests">here</a>.</p><h3>Building the interaction model</h3><p>The skill does not have an interaction model at first, so you’ll need to write an interaction model definition to serverless.yml.</p><p>Like this!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55cf97b917e5821ebffb3258c778ef52/href">https://medium.com/media/55cf97b917e5821ebffb3258c778ef52/href</a></iframe><p>You can see the format of the interaction model <a href="https://developer.amazon.com/docs/custom-skills/custom-interaction-model-reference.html">here</a>.</p><p>Execute the following command to build the model after updating your serverless.yml (and you can also use the --dryRun option with this command):</p><pre>$ sls alexa build</pre><p>Then, you can check the model like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/932ab6708a8c71cb2173f9f550616394/href">https://medium.com/media/932ab6708a8c71cb2173f9f550616394/href</a></iframe><p>There are a few more steps needed in order to completely publish skills, so I’m planning to do further integrations with the Alexa Skills Kit in the future. It’s still pretty great to be able to integrate manifests and models, since we update those many times as we develop. All the better if we can manage them with the source code of our Lambda functions!</p><p>Now, we can completely manage our Lambda Functions and Alexa Skills with Serverless Framework + Serverless Alexa Skills Plugin!</p><p>If you have any comments or feedback, please create an <a href="https://github.com/marcy-terui/serverless-alexa-skills/issues">issue</a> or send a pull request. I always welcome them 🍻</p><figure><a href="https://console.serverless.com/?view=register&amp;utm_campaign=Console%20Signup&amp;utm_source=medium&amp;utm_medium=post&amp;utm_content=How%20To%20Manage%20Your%20Alexa%20Skills%20With%20Serverless"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coRpboSHyAtv5UPafeHzbw.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NCHqjhEtW2FQQm5NO0ekAg.png" /></figure><p><em>Originally published at </em><a href="https://www.serverless.com/blog/how-to-manage-your-alexa-skills-with-serverless/"><em>https://www.serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4f7bee08d3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CI/CD for monorepos]]></title>
            <link>https://medium.com/@serverlessinc/ci-cd-for-monorepos-35a36c0f9d9a?source=rss-10625560e1ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/35a36c0f9d9a</guid>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cicd]]></category>
            <dc:creator><![CDATA[Serverless]]></dc:creator>
            <pubDate>Thu, 02 Jun 2022 16:06:09 GMT</pubDate>
            <atom:updated>2022-06-02T16:06:09.789Z</atom:updated>
            <content:encoded><![CDATA[<p>Originally posted at <a href="https://www.serverless.com/blog/cicd-for-monorepos">Serverless</a> on March 6th, 2020</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-iR8N5mLmyKks6JW.png" /></figure><blockquote><em>This article was updated to reflect changes in the new dashboard at app.serverless.com</em></blockquote><p>When building serverless applications as a collection of Serverless services, we need to decide whether we are going to push each service individually to our version control system, or bundle them all together as a single repo. This article is not going to go into the details about which is better or not, but all our posts so far seem to show examples of services all stored in individual repositories.</p><p>What this article <strong>is</strong> going to demonstrate, however, is that deploying services from within a single monorepo is easily doable within Serverless Framework Pro’s CI/CD solution.</p><h4>Getting started</h4><p>You need to make sure that the services you are deploying are bundles together in a repo in separate subdirectories off the root of the repo. You can see a simple <a href="https://github.com/garethmcc/monrepotest">example repo here</a> to see how this is structured to make sure that yours matches as closely as possible. Really the biggest part to take note of is that all services are off the root of the repo as separate sub-directories and a f9older with shared code is also off that root. This just simplifies configuration later.</p><blockquote><strong><em>Note:</em></strong><em> Serverless Framework Pro has a generous free tier so you don’t need to worry about not having a paid account just to try this feature out for yourself.</em></blockquote><p>Once you have a repo setup (or you’ve cloned the sample repo), make sure each service in each subdirectory have the same app and org settings to connect to the dashboard and that those changes are also pushed to the repo.</p><p>The last step before we walk through setting up the monorepo deployment is to ensure that we have our connection to our AWS account all squared away, especially if you have a <a href="https://app.serverless.com">brand new dashboard account</a>. Here is a <a href="https://www.youtube.com/watch?v=VUKDRoUdMek">2 minute video</a> that shows you how to easily and quickly connect to AWS using Providers.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fembed%2FVUKDRoUdMek%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fwatch%3Fv%3DVUKDRoUdMek&amp;image=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttps%2Fi.ytimg.com%2Fvi%2FVUKDRoUdMek%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/56af67f4c6b3f265066dfb34b4ff6d3a/href">https://medium.com/media/56af67f4c6b3f265066dfb34b4ff6d3a/href</a></iframe><p>With that out of the way, let’s get cracking!</p><h4>First deploy</h4><p>The best way to get started is to just deploy first and get all your services deployed to AWS and created within the dashboard. Here are the steps to follow:</p><ol><li>Make sure you have credentials for the CLI to communicate to your Serverless account by running <em>serverless login</em> in the CLI and completing the login process.</li><li>If the app property you have added to your services’ serverless.yml files does not yet exist, click the <em>create app</em> button and choose to <em>add an existing Serverless Framework project</em></li><li>During that process you can create or choose a new Provider</li><li>Once the app is created, go back to your project on the CLI, make sure to <em>cd</em> into the first service and run <em>serverless deploy — stage [stageyouwanthere]</em>. The<em> — stage</em> is optional since it will always default to a value of <em>dev</em> unless you specify otherwise.</li><li>Repeat 4 by <em>cd</em>ing into each sub-directory and deploying each service into AWS.</li></ol><p>Even if these services are <strong>already</strong> deployed, you can deploy again. As long as nothing but the <strong>org </strong>and <strong>app</strong> properties have changed, all that this new deployment does is add these services to your dashboard account.</p><h4>Connecting to GitHub or BitBucket</h4><p>Now that everything is added to the dashboard, lets click the menu option to the right of the one of our service names and choose settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/0*EPKO4PG3_-YGPCun.png" /></figure><p>In the settings menu, select CI/CD and you should see the CI/CD configuration open up. If you are doing this for the first time, you have probably not connected to GitHub or BitBucket before, so just click the connect option and follow the prompts.</p><p>Once you have completed that process, you will need to choose the repository for your monorepo from the dropdown list, and since this is a monorepo, the CI/CD settings will also ask you to choose the right base directory for this specific service. Go ahead and do that!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/0*qBCjZNafCsXoT0bH.png" /></figure><h4>Setting up automated deployments</h4><p>Since we have the basic connection all set up now, let’s scroll down to the branch deploys` section. This is where you can now configure which branch in your repo deploys to which stage or environment. Most repos have a main branch (or master) and this is often selected as the prod stage. You can however add a develop branch that can deploy to the dev stage as in the image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/0*ub5-qbBI-8JgHt_H.png" /></figure><p>Just add any additional branch to stage mappings you want to have. This configuration will then trigger an automated deployment as soon as any code changes are made to the branch you configure; for example if a developer creates a PR to the develop branch, one that PR is merged it will automatically trigger a deployment of your service to the dev stage if configured like the image above.</p><blockquote><em>NOTE: You can use </em><a href="https://www.serverless.com/framework/docs/guides/providers/"><strong><em>Providers</em></strong></a><em> to configure a different AWS connection for each stage and </em><a href="https://www.serverless.com/framework/docs/guides/parameters/"><strong><em>Parameters</em></strong></a><em> to pass different configuration values for each stage at deployment time as well.</em></blockquote><p>You will need to repeat the above process for each sub-directory within your monorepo.</p><h4>More advanced configuration</h4><p><strong>Selective deployments</strong></p><p>By default, if you have multiple services of a monorepo configured and you merge a change anywhere in that repo, all services will redeploy, just in case. There’s no way for the system to know if there are any dependencies between the services so it cannot assume that only that one service that had a change should be redeployed. In other words, if you had 6 services and you made a change to just one, 6 seperate redeployments will occur, just in case.</p><p>However, you can configure it differently. If you open the CI/CD settings for one of the services and scroll down to expand the <em>build settings</em> section, you should see numerous options to help you maximise the efficiency of your CI/CD pipeline for a monorepo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/0*iJsTIAp_q58sZgk9.png" /></figure><p>By default, the <em>Only trigger builds on selected file changes</em> option is not selected and means that this service will <strong>always</strong> be redeployed with any change to the git repository, even if there were no changes to the code of this service. If you only want this service redeployed when its own code is edited, check the box and you should see something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/0*0F28ncpi4tBZurJ2.png" /></figure><p>Automatically, the directory of the current service is selected. From this point on, <em>servicea</em> will only be re-deployed when its own code is edited.</p><p><strong>Dependency deployment</strong></p><p>But what if you actually did have services that had dependencies on each other. So in the example with <em>servicea</em>, we could in fact link it to <em>serviceb</em> and configure it so that <em>servicea</em> will always be re-deployed when <em>serviceb</em> is also edited. Just by adding a reference to the correct service directory, I can ensure this will happen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/0*EyILx5_7-Sy4ZpHV.png" /></figure><p>I could of course do this for any number of services that <em>servicea</em> depends on and vice versa. But what if I have some kind of shared folder that <em>servicea</em> uses. Because we reference a directory structure in our configuration, you can point to any path in your monorepo to be watched for changes. In the example repo, we have a directory called shared that stores a number of classes and functions (or at least it could) that are re-used by multiple services. If I change anything in shared, multiple services need to redeploy.</p><p>I can accomplish this just by adding the path to shared:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/0*JN1UBpXkiD4_ysMF.png" /></figure><p>In the image above, <em>servicea</em> will be deployed on merges to Github if changes are detected in directories <em>servicea</em>, <em>serviceb</em> or shared. And I can configure any service with any specific arrangement of dependencies I need, providing me a ton of great flexibility to deploy what I need under the right circumstances.</p><p>Monorepo deployments are much simpler to manage using Serverless Framework Pro CI/CD. But if you do have any feedback for us or want to just share, please hop into our <a href="https://serverless.com/slack">Slack channels</a> or <a href="https://forum.serverless.com">Forums</a> and let us know. Or you can even <a href="https://twitter.com/garethmcc">DM me on Twitter</a> if you have any questions.‍</p><figure><a href="https://console.serverless.com/?view=register&amp;utm_campaign=Console%20Signup&amp;utm_source=medium&amp;utm_medium=post&amp;utm_content=CI%2FCD%20for%20monorepos"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coRpboSHyAtv5UPafeHzbw.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NCHqjhEtW2FQQm5NO0ekAg.png" /></figure><p><em>Originally published at </em><a href="https://www.serverless.com/blog/cicd-for-monorepos"><em>https://www.serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35a36c0f9d9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitor and debug all serverless errors]]></title>
            <link>https://medium.com/@serverlessinc/monitor-and-debug-all-serverless-errors-6ccc5b48cfdb?source=rss-10625560e1ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ccc5b48cfdb</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Serverless]]></dc:creator>
            <pubDate>Wed, 01 Jun 2022 17:52:31 GMT</pubDate>
            <atom:updated>2022-06-01T17:52:31.976Z</atom:updated>
            <content:encoded><![CDATA[<p>Originally posted at <a href="https://www.serverless.com/blog/monitor-and-debug-all-serverless-errors">Serverless</a> on September 12th, 2019</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4GVh6HxdIeraeGAA.png" /></figure><p>One of the most popular features of the Serverless Framework is its ability to provide monitoring with automatic instrumentation. By signing up for a free Serverless Framework account and deploying your service, it is automatically instrumented to capture all of the data needed to provide metrics, alerts, notifications, stacktraces and more.</p><p>This is especially powerful when it comes to monitoring and debugging errors. When your code throws an error, then the Serverless Framework provides a few ways to monitor and debug those errors:</p><ol><li>You will get a <a href="https://serverless.com/framework/docs/dashboard/monitoring/alerts#error-new-error-type-identified">New Error Type</a> alert for your service instance, notifying you in Slack or Email that a new error was identified.</li><li>The stack trace is captured and in the Serverless Dashboard you can see the stack trace highlighting the exact line which threw the error.</li><li>The invocations &amp; errors chart will show you the number of times errors have occurred over a span of time.</li><li>Using the invocation explorer you can search and identify the individual invocations which got the error and dig into all the details.</li></ol><p>No wonder this is such a popular feature.</p><p>However, until today, capturing the errors only worked for cases where the error was not caught by the code and resulted in a fatal crash of the Lambda invocation. But of course we do not want our services to return 500 in such cases, so more often than not, the errors are caught and the Lambda function returns a nicer 4XX error.</p><p>Today we are launching a new addition to the Serverless Framework to help capture errors even when they are caught by your code. So let’s look at this code first.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93818f6d852fa4e2379b62fff48efb91/href">https://medium.com/media/93818f6d852fa4e2379b62fff48efb91/href</a></iframe><p>In the example above, our lambda function handler throws an error; however, it is also caught. It calls the captureError function provided by the Serverless Framework SDK in the context object. The function was able to proceed and return a nice friendly error to the API while still capturing the error. The <a href="http://slss.io/docs-capture-error">documentation</a> provides more details on using the captureError method.</p><p>Now that the error is captured by the Serverless Framework, you can use the powerful dashboard features to help monitor and debug these errors. Here are a few ways you can interact with these newly captured errors in the dashboard.</p><p>When a new error is captured which hasn’t been captured before, you will get a <a href="https://serverless.com/framework/docs/dashboard/monitoring/alerts#error-new-error-type-identified">New Error Type</a> alert. You can also setup <a href="https://serverless.com/framework/docs/dashboard/monitoring/notifications/">notifications</a> to get notified in Slack or email, or custom SNS Topics or API endpoints.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vonO-R8BaAaktK5y.png" /></figure><p>All errors, including fatal errors and captured errors, are available in the Invocation Explorer so you can filter for invocations containing errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wSsdfr5accWjpgnX.png" /></figure><p>Also in the invocation explorer you can dive into the details of the individual invocation to get the details about the error, including the stack trace which was captured by the captureError method in the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l59Hq_iHpkXaVLpq.png" /></figure><p>Lastly, in the service instance overview page you can view invocation metrics and filter the results to identify the captured errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t0hXzMQLXriqTzIF.png" /></figure><p>If you want to improve monitoring and debugging for your Serverless Framework application, getting started with the automatic instrumentation is incredibly easy. <a href="https://app.serverless.com/">Sign up in the dashboard</a> and follow the instructions to start a new Serverless Framework project or incorporate the dashboard features into existing services.</p><figure><a href="https://console.serverless.com/?view=register&amp;utm_campaign=Console%20Signup&amp;utm_source=medium&amp;utm_medium=post&amp;utm_content=Monitor%20and%20debug%20all%20serverless%20errors"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coRpboSHyAtv5UPafeHzbw.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NCHqjhEtW2FQQm5NO0ekAg.png" /></figure><p><em>Originally published at </em><a href="https://www.serverless.com/blog/monitor-and-debug-all-serverless-errors"><em>https://www.serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ccc5b48cfdb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Efficient APIs with GraphQL and Serverless]]></title>
            <link>https://medium.com/@serverlessinc/efficient-apis-with-graphql-and-serverless-59a4a3af8960?source=rss-10625560e1ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/59a4a3af8960</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[api-development]]></category>
            <dc:creator><![CDATA[Serverless]]></dc:creator>
            <pubDate>Wed, 01 Jun 2022 15:03:28 GMT</pubDate>
            <atom:updated>2022-06-01T15:03:28.411Z</atom:updated>
            <content:encoded><![CDATA[<p>Originally posted at <a href="https://www.serverless.com/blog/efficient-apis-graphql-serverless/">Serverless</a> on July 23rd, 2018</p><p>GraphQL can be a tool for building enlightened APIs, but it can also be a source of mystery for developers accustomed to REST.</p><p>In this post, I’ll talk about the motivations that might lead you to choose GraphQL, and how to serve a GraphQL API that will let you really take advantage of its benefits.</p><p>Here’s what we’ll be covering:</p><ul><li><a href="https://www.serverless.com/blog/efficient-apis-graphql-serverless/#rest-api-design">REST API design</a></li><li><a href="https://www.serverless.com/blog/efficient-apis-graphql-serverless/#enter-graphql">A GraphQL approach</a></li><li><a href="https://www.serverless.com/blog/efficient-apis-graphql-serverless/#making-your-graphql-endpoint-serverless">Making your GraphQL endpoint serverless</a></li></ul><h3>REST API design</h3><p>First, let’s talk about some situations that arise in REST APIs; this directly segues into when and why you would want to use GraphQL.</p><p>Let’s say you have a REST resource to represent the products that your business offers:</p><pre>GET /products/123<br>{<br>  &quot;id&quot;: &quot;123&quot;,<br>  &quot;name&quot;: &quot;Widget&quot;,<br>  &quot;price&quot;: &quot;$10.00&quot;<br>}</pre><p>And also a resource for orders by customers:</p><pre>GET /orders/445566<br>{<br>  &quot;id&quot;: &quot;445566&quot;,<br>  &quot;customerName&quot;: &quot;John Q. Public&quot;<br>  &quot;deliveryAddress&quot;: &quot;1234 Elm St.&quot;,<br>  &quot;productId&quot;: &quot;123&quot;,<br>  &quot;quantity&quot;: 5<br>}</pre><p>The order refers to the product by its ID. If the client needs to display the product information in the context of the order, it makes two requests: one to get the order record, and one to get the details for the product specified on the order.</p><p>You might try to improve this API in a couple ways. One would be to offer a way to retrieve the product details directly from the order number, so that you can make the two requests in parallel.</p><pre>GET /orders/445566/product<br>{<br>  &quot;id&quot;: &quot;123&quot;,<br>  &quot;name&quot;: &quot;Widget&quot;,<br>  &quot;price&quot;: &quot;$10.00&quot;<br>}</pre><p>If you consistently need all the product information with the order, you might just decide to include the product information in the order resource:</p><pre>GET /orders/445566<br>{<br>  &quot;id&quot;: &quot;445566&quot;,<br>  &quot;customerName&quot;: &quot;John Q. Public&quot;<br>  &quot;deliveryAddress&quot;: &quot;1234 Elm St.&quot;,<br>  &quot;productId&quot;: &quot;123&quot;,<br>  &quot;productName&quot;: &quot;Widget&quot;,<br>  &quot;productPrice&quot;: &quot;$10.00&quot;<br>  &quot;quantity&quot;: 5<br>}</pre><p>Now you’ve solved the issue of having to make multiple requests, but you’ve polluted the order object with properties from another resource, which makes it harder to use and evolve. You can fix this by keeping all product information under a single property:</p><pre>GET /orders/445566<br>{<br>  &quot;id&quot;: &quot;445566&quot;,<br>  &quot;customerName&quot;: &quot;John Q. Public&quot;<br>  &quot;deliveryAddress&quot;: &quot;1234 Elm St.&quot;,<br>  &quot;product&quot;: {<br>    &quot;id&quot;: &quot;123&quot;,<br>    &quot;name&quot;: &quot;Widget&quot;,<br>    &quot;price&quot;: &quot;$10.00&quot;<br>  }<br>  &quot;quantity&quot;: 5<br>}</pre><p>That looks pretty good! It has the benefit that any code that was written to work with the /products response will also work with &quot;product&quot; property from /orders.</p><p>The drawback of including the product information on the order is how it affects the backend. This may require a more expensive multi-table query with SQL, or a second query under NoSQL, or else a denormalized table that records product information with the order. It also increases the size of the response body, which can become a real problem as the REST API gets more mature and the response includes more information for different purposes.</p><p>A slightly inelegant solution is to allow the request to flag whether it wants the product information:</p><pre>GET /orders/445566?omitProduct=true<br>{<br>  &quot;id&quot;: &quot;445566&quot;,<br>  &quot;customerName&quot;: &quot;John Q. Public&quot;<br>  &quot;deliveryAddress&quot;: &quot;1234 Elm St.&quot;,<br>  &quot;quantity&quot;: 5<br>}</pre><p>This is not very clean, but it does allow the backend to avoid doing the extra work when product information isn’t necessary, at the cost of increased code complexity. If you repeat this design struggle many times over the lifetime of your API, you may end up with a lot of flags for different properties.</p><p>If you reach this point in your API design, then congratulations! You have partially re-invented GraphQL.</p><h3>Enter GraphQL</h3><p>Let’s see how a GraphQL API answers the same questions.</p><p>You’d begin by creating types for products and orders. You don’t start the API by tying things together with foreign keys, as you did with REST. Instead, the order type contains a product field as we eventually decided on in the above example:</p><pre>type Product {<br>  id: String!<br>  name: String!<br>  price: String!<br>}</pre><pre>type Order {<br>  id: String!<br>  customerName: String!<br>  deliveryAddress: String!<br>  product: Product!<br>  quantity: Int!<br>}</pre><p>You create query fields to get orders and products:</p><pre>type Query {<br>  product(id: String!): Product<br>  order(id: String!): Order<br>}</pre><p>If the client needs to get an order and the relevant product details, you only need a single query.</p><p>Since the query contains an exact statement of all the properties that it expects, the service knows by design whether it needs to fetch product information. This allows you to write a backend that minimizes database and compute time.</p><p>For example, suppose you want to know the customer name, delivery address, order quantity, product name, and product price:</p><pre>{<br>  order(id: &quot;445566&quot;) {<br>    customerName<br>    deliveryAddress<br>    quantity<br>    product {<br>      name<br>      price<br>    }<br>  }<br>}</pre><p>This query would return only the requested properties:</p><pre>{<br> “customerName”: “John Q. Public”,<br> “deliveryAddress”: “1234 Elm St.”,<br> “quantity”: 5,<br> “product”: {<br> “name”: “Widget”,<br> “price”: “$10.00”<br> }<br>}</pre><h3>Making your GraphQL endpoint serverless</h3><p>There are even deeper advantages to having a serverless GraphQL endpoint, which you can <a href="https://serverless.com/blog/running-scalable-reliable-graphql-endpoint-with-serverless/">read more about here</a>.</p><p>The tl;dr is that when you use GraphQL, you are relying on only one HTTP endpoint; and when you have one HTTP endpoint to connect all your clients to your backend services, you want that endpoint to be performant, reliable, and auto-scaling.</p><h3>Building a GraphQL endpoint with the Serverless Framework</h3><p>So, how do we build this with the <a href="https://serverless.com/framework/">Serverless Framework</a>?</p><p>We’re going to target AWS Lambda with Node 8 in this example, and the code should be easily adaptable to other FaaS providers. You can download the code for this example <a href="https://s3-us-west-2.amazonaws.com/assets.blog.serverless.com/graphql-blog.zip">here</a>.</p><p>Using the GraphQL reference implementation in JS, we can easily create our GraphQL schema from the type declarations.</p><p>First import the utilities we need from the graphql library:</p><pre>const {<br>  graphql,<br>  buildSchema<br>} = require(&#39;graphql&#39;)</pre><p>Now you can use GraphQL schema language to specify the schema:</p><pre>const schema = buildSchema(`<br>  type Product {<br>    id: String!<br>    name: String!<br>    price: String!<br>  }</pre><pre>type Order {<br>    id: String!<br>    customerName: String!<br>    deliveryAddress: String!<br>    product: Product!<br>    quantity: Int!<br>  }</pre><pre>type Query {<br>    product(id: String!): Product<br>    order(id: String!): Order<br>  }<br>`)</pre><p>Next, we create resolvers so that queries can access our data. This is also where we make sure the resolver isn’t doing any more work than necessary. The graphql library is very flexible. Resolvers can exist for individual fields, and a resolver can either be a constant value, a function, a promise, or an asynchronous function. Functions have access to any arguments for the field via a single object parameter.</p><p>We want the database record for the product information to be retrieved only when requested, so we make the resolver for that field a function:</p><pre>const database = require(&#39;./database&#39;)<br>const resolvers = {<br>  product: ({ id }) =&gt; database.products.get(id),<br>  order: async ({ id }) =&gt; {<br>    const order = await database.orders.get(id)<br>    if(!order) return null</pre><pre>return {<br>      ...order,<br>      product: () =&gt; database.products.get(order.productId)<br>    }<br>  }<br>}</pre><p>The methods database.products.get() and database.orders.get() are both asynchronous functions, returning promises. The resolver for product simply calls through to the database. You do not need to worry about manually removing extraneous fields, since graphql-js does that for you.</p><p>The resolver for order is more complex. It uses async/await syntax to fetch the order record before returning. This allows us to get the productId for use in the resolver for the product field. Since the resolver for the product field is a function, it won’t be invoked unless the product field is actually included in the query.</p><p>All that remains is to create a handler for Lambda. Using the newer asynchronous syntax introduced by Node 8 for Lambda, this is very simple.</p><pre>module.exports.query = async (event) =&gt; {<br>  const result = await graphql(schema, event.body, resolvers)<br>  return { statusCode: 200, body: JSON.stringify(result.data, null, 2) }<br>}</pre><p>Since all of the set-up logic for the GraphQL schema is outside of the handler, this will only be executed when Lambda needs to spin up a new instance to serve requests. To enable us to query by POST request, we have to include the following in serverless.yml:</p><pre>service: my-api</pre><pre>provider:<br>  name: aws<br>  runtime: nodejs8.10</pre><pre>functions:<br>  hello:<br>    handler: handler.query<br>    events:<br>      - http:<br>          path: /<br>          method: POST</pre><p>That’s it. After a quick sls deploy, we can curl our new GraphQL endpoint to test the query:</p><pre>curl <a href="https://lsqgfkvs2i.execute-api.us-east-1.amazonaws.com/dev/">https://lsqgfkvs2i.execute-api.us-east-1.amazonaws.com/dev/</a> -d &#39;{<br>  order(id: &quot;778899&quot;) {<br>    customerName<br>    deliveryAddress<br>    quantity<br>    product {<br>      name<br>      price<br>    }<br>  }<br>}<br>&#39;</pre><pre>{<br>  &quot;order&quot;: {<br>    &quot;customerName&quot;: &quot;Stacey L. Civic&quot;,<br>    &quot;deliveryAddress&quot;: &quot;4321 Oak St.&quot;,<br>    &quot;quantity&quot;: 32,<br>    &quot;product&quot;: {<br>      &quot;name&quot;: &quot;Gadget&quot;,<br>      &quot;price&quot;: &quot;$8.50&quot;<br>    }<br>  }<br>}</pre><h3>Conclusion</h3><p>You’ve now got a working GraphQL endpoint built with Serverless that scales automatically with increased traffic!</p><p>In this example, we went with a single-Lambda approach. If you want infrastructural microservices, you can also use the flexibility of resolvers to have a primary Lambda that invokes other lambdas to resolve different query fields. If you want a more in-depth solution that uses GraphQL from top to bottom, you can use <a href="https://www.apollographql.com/docs/graphql-tools/schema-stitching.html">schema stitching</a> to combine multiple GraphQL APIs into one.</p><h3>Other Serverless + GraphQL resources</h3><ul><li><a href="https://serverless.com/blog/make-serverless-graphql-api-using-lambda-dynamodb/">How to make a Serverless GraphQL API using Lambda and DynamoDB</a></li><li><a href="https://serverless.com/blog/running-scalable-reliable-graphql-endpoint-with-serverless/">Running a scalable &amp; reliable GraphQL endpoint with Serverless</a></li></ul><figure><a href="https://console.serverless.com/?view=register&amp;utm_campaign=Console%20Signup&amp;utm_source=medium&amp;utm_medium=post&amp;utm_content=Efficient%20APIs%20with%20GraphQL%20and%20Serverless"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coRpboSHyAtv5UPafeHzbw.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NCHqjhEtW2FQQm5NO0ekAg.png" /></figure><p><em>Originally published at </em><a href="https://www.serverless.com/blog/efficient-apis-graphql-serverless/"><em>https://www.serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59a4a3af8960" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Challenges and patterns for building event-driven architectures]]></title>
            <link>https://medium.com/@serverlessinc/challenges-and-patterns-for-building-event-driven-architectures-2069c115c6ae?source=rss-10625560e1ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/2069c115c6ae</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[serverless-architecture]]></category>
            <dc:creator><![CDATA[Serverless]]></dc:creator>
            <pubDate>Tue, 31 May 2022 22:09:22 GMT</pubDate>
            <atom:updated>2022-05-31T22:09:22.344Z</atom:updated>
            <content:encoded><![CDATA[<p>Originally posted at <a href="https://www.serverless.com/blog/stream-based-challenges-and-patterns">Serverless</a> on July 19th, 2017</p><h3>Challenges with the Event-Driven Architecture</h3><p>In my <a href="https://serverless.com/blog/event-driven-architecture-dynamodb/">previous post</a>, I talked about how you can use DynamoDB Streams to power an event-driven architecture. While this architecture has a number of benefits, it also has some “gotchas” to look out for. As you go down this road, you need to be aware of a few challenges with these patterns.</p><h4>Changing Event Schemas</h4><p>In our user creation example from the last post, we’ve been saving the user’s first name and last name together in a single fullname field. Perhaps our developers later decide they&#39;d rather have those as two separate fields, firstname and lastname. They update the user creation function and deploy. Everything is fine -- for them. But downstream, everything is breaking. Look at the code for the Algolia indexing function -- it implicitly assumes that the incoming Item will have a fullname field. When it goes to grab that field on a new Item, it will get a KeyError exception.</p><p>How do we handle these issues? There’s no real silver bullet, but there are a few ways to address this both from the producer and consumer sides. As a producer, focus on being a polite producer. Treat your event schemas just like you would treat your REST API responses. See if you can make your events backward-compatible, in the sense of not removing or redefining existing fields. In the example above, perhaps the new event would write firstname, lastname, and fullname. This could give your downstream consumers time to switch to the new event format. If this is impossible or infeasible, you could notify your downstream consumers. The AWS CLI has a command for <a href="http://docs.aws.amazon.com/cli/latest/reference/lambda/list-event-source-mappings.html">listing event source mappings</a>, which shows which Lambda functions are triggered by a given DynamoDB stream. If you&#39;re a producer that&#39;s changing your Item structure, give a heads up to the owners of consuming functions.</p><p>As a consumer of streams, focus on being a resilient consumer. Consider the assumptions you’re making in your function and how you should respond if those assumptions aren’t satisfied. We’ll discuss different failure handling strategies below, but you shouldn’t just rely on producers to handle this for you.</p><h4>How to handle failure</h4><p>Failure handing is a second challenge to consider with Lambda functions that are triggered by DynamoDB streams. Before we talk about this, we should dig a little deeper into how Lambda functions are invoked by DynamoDB streams.</p><p>When you create an event source mapping from a DynamoDB stream to a Lambda function, AWS has a process that occasionally polls the stream for new records. If there are new records, AWS will invoke your subscribed function with those records. The AWS process will keep track of your function’s position in the DynamoDB stream. If your Lambda function returns successfully, the process will retain that information and update your position in the stream when polling for new records. If your Lambda function does not return successfully, it will not update your position and will re-poll the stream from your previous position. There are a few key takeaways here:</p><ul><li>You receive records in batches. There can be as few as 1 or as many as 10000 records in a batch.</li><li>You may not alter or delete a record in the stream. You may only react to the information in the record.</li><li>Each subscriber maintains its own position in the stream. Thus, a slower subscriber may be reading older records than a faster subscriber.</li></ul><p>The batch notion is worth highlighting separately. Your Lambda function can only fail or succeed on an entire batch of records, rather than on an individual message. If you raise a failure on a batch of records because of an issue with a single record, know that you will reprocess that same batch. Take care to implement your record handler in an idempotent way — you wouldn’t want to send a user multiple “Welcome!” emails due to the failure of a different user.</p><p>With this background, let’s think about how we should address failure. Let’s start with something simple, like a Lambda function that posts data about new user signups to Slack. This isn’t a mission-critical operation, so you can afford to be more lax about errors. When processing a batch of records, you could wrap it in a simple try/catch block that catches any errors, logs them to Cloudwatch, and returns successfully. For the occasional error that happens, that user isn’t posted to Slack, but it’s not a big deal. This function will likely stay up to date with the most recent records in the DynamoDB stream because of this strategy.</p><p>With our Algolia indexing function, we want to be less cavalier. If we’re failing to index users as they sign up or modify their details, our search index will be stale and provide a poor experience for users. There are two ways you can handle this. First, you can simply raise an exception and fail loudly if <em>any</em> record in the batch fails. This will cause your Lambda to be invoked again with the same batch of records. If this is a transient error, such as a temporary blip in service from Algolia, this should be fixed on the next invocation of your Lambda and processing will continue as normal. It’s more complicated if this is <em>not</em> a transient error, such as in the previous section where the event contract was changed. In that case, your Lambda will continue to be invoked with the same batch of messages. Each failure will indicate that your position in the DynamoDB stream should not be updated, and you will be stuck at that position until you either update your code to handle the failure case or the record is purged from the stream 24 hours after it was added.</p><p>This hard error pattern can be a good one, particularly for critical applications where you don’t want to gloss over unexpected errors. You can set up a Cloudwatch Alarm to notify you if the number of errors for your function is too high over a given time period or if the Iterator Age of your DynamoDB stream is too high, indicating that you’re falling behind in processing. You can investigate the cause of the error, make the necessary fix, and redeploy your function to handle the new record schema and continue your indexing as usual.</p><p>Between the “soft failure” mode of logging and moving on, and the “hard failure” mode of stopping everything on an error, I like a third option that allows us to retain the structured record in a programmatically-accessible way, while still continuing to process events. To do this, we create an SQS queue for storing failed messages. When an unexpected exception is raised, we capture the failure message and store it in the SQS queue along with the record. An example implementation looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df4c991de25847ddba78b8cabb4efcfb/href">https://medium.com/media/df4c991de25847ddba78b8cabb4efcfb/href</a></iframe><p>Our main handler function is very short and simple. Each record is passed through a handle_record function, which contains our actual business logic. If any unexpected exception is raised, the record and exception are passed to a handle_failed_record function, which is shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91bd7b93271e443edf093bcbbef6a130/href">https://medium.com/media/91bd7b93271e443edf093bcbbef6a130/href</a></iframe><p>Pretty straightforward — it takes in the failed record and the exception and writes them in a message to an SQS queue.</p><p>When using this pattern, it helps to think of operating on individual records, rather than a batch of records. All of your business logic is contained on handle_record, which operates on a single record. This is useful when reprocessing failed records, as you can reuse the same logic. Imagine the unexpected error in your function was due to a bug in your logic that only affected a subset of records. You can fix the logic and redeploy, but you still need to process the records that failed in the interim. Since your handle_record function operates on a single record, you can just read records from the queue and send them through that same entry point:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71935660011980d7987bfa7c41397182/href">https://medium.com/media/71935660011980d7987bfa7c41397182/href</a></iframe><p>This is a simple reprocessing script that you can run locally or invoke with a reprocessing Lambda. It reads messages from the SQS queue and parses out the record object, which is the same as the record input from a batch of records from the DynamoDB stream. This record is passed into the updated handle_record function and the queue message is deleted if the operation is successful. This pattern isn&#39;t perfect, but I&#39;ve found it to be a nice compromise between the two extremes of the failure spectrum when processing streams with Lambda.</p><h4>Concurrency Limits</h4><p>Finally, let’s talk about concurrency limits with DynamoDB streams. The big benefit of streams is the <em>independence</em> of the consumers — the Algolia indexing operations are completely separate from the process that updates the marketing team’s CRM. The development team that manages the user search index doesn’t even need to know about the marketing team’s needs or existence, and vice versa.</p><p>However, it’s not quite accurate to say that consumers are completely independent. DynamoDB streams are similar to <a href="https://aws.amazon.com/kinesis/streams/">Kinesis streams</a> under the hood. These streams throttle reads in two ways: throughput and read requests. For throughput, you may read 2 MB per second from a single shard. For read requests, Kinesis streams have a limit of 5 read requests per second on a single shard. For DynamoDB streams, these limits are even more strict — <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html#Streams.Processing">AWS recommends</a> to have no more than 2 consumers reading from a DynamoDB stream shard. If you had more than 2 consumers, as in our example from Part I of this blog post, you’ll experience throttling.</p><p>To me, the read request limits are a defect of the Kinesis and DynamoDB streams. If you are hitting throughput limits on your streams, you can increase the number of shards as the MB limit is on a per-shard basis. However, there’s no similar scaling mechanism if you want to increase the number of read requests. Every consumer needs to read from every shard, so increasing the number of shards does not help you scale out consumers. The entire notion of an immutable log like Kinesis or Kafka is to allow for multiple independent consumers (check out Jay Krep’s excellent book, <a href="http://shop.oreilly.com/product/0636920034339.do">I Heart Logs</a>, for a better understanding of immutable logs). With the current read request limits in Kinesis and DynamoDB streams, the number of consumers is severely constrained.</p><h4>Conclusion</h4><p>In this post, we discussed some implementation details and some gotchas to watch out for when using stream-based Lambda invocations. Now it’s your turn — tell us what you build with event-driven architectures!</p><figure><a href="https://console.serverless.com/?view=register&amp;utm_campaign=Console%20Signup&amp;utm_source=medium&amp;utm_medium=post&amp;utm_content=Challenges%20and%20patterns%20for%20building%20event-driven%20architectures"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coRpboSHyAtv5UPafeHzbw.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NCHqjhEtW2FQQm5NO0ekAg.png" /></figure><p><em>Originally published at </em><a href="https://www.serverless.com/blog/stream-based-challenges-and-patterns"><em>https://www.serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2069c115c6ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless Aurora: What it means and why it’s the future of data]]></title>
            <link>https://medium.com/@serverlessinc/serverless-aurora-what-it-means-and-why-its-the-future-of-data-1c562422c703?source=rss-10625560e1ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c562422c703</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aurora]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Serverless]]></dc:creator>
            <pubDate>Tue, 31 May 2022 21:45:56 GMT</pubDate>
            <atom:updated>2022-05-31T21:45:56.362Z</atom:updated>
            <content:encoded><![CDATA[<p>Originally posted <a href="https://www.serverless.com/blog/serverless-aurora-future-of-data/">Serverless</a> on Dec 4th, 2017</p><p>AWS had their annual re:Invent conference last week (missed it? <a href="https://serverless.com/blog/ultimate-list-serverless-announcements-reinvent/">Check out our full recap</a>).</p><p>AWS Lambda started the Serverless movement by releasing Lambda at re:Invent 2014. But the Lambda releases this year were run-of-the-mill incremental improvements- <a href="https://serverless.com/blog/ultimate-list-serverless-announcements-reinvent/#3gb-memory">higher memory limits</a>, <a href="https://serverless.com/blog/ultimate-list-serverless-announcements-reinvent/#concurrency-controls">concurrency controls</a>, and of course, <a href="https://serverless.com/blog/ultimate-list-serverless-announcements-reinvent/#golang-support">Golang support (coming soon!)</a>.</p><p>All this to say, there was nothing game-changing in the functions-as-a-service (FaaS) world itself.</p><p>Well then. Does this mean that AWS is slowing down on serverless?</p><p>Hardly.</p><p>We saw AWS asserting that serverless is more than just functions:</p><h3>TJ Holowaychuk 🇺🇦 on Twitter: &quot;serverless != functions, FaaS == functions, serverless == on-demand scaling and pricing characteristics (not limited to functions) / Twitter&quot;</h3><p>serverless != functions, FaaS == functions, serverless == on-demand scaling and pricing characteristics (not limited to functions)</p><blockquote>For a deeper explanation of this, check out Ben Kehoe’s excellent post on <a href="https://read.acloud.guru/the-serverless-spectrum-147b02cb2292">The Serverless Spectrum</a>.</blockquote><p>In five years when we look back at re:Invent 2017, we won’t be talking about the different <a href="https://serverless.com/blog/ultimate-list-serverless-announcements-reinvent/#aws-eks">managed</a> <a href="https://serverless.com/blog/ultimate-list-serverless-announcements-reinvent/#aws-fargate">container</a> offerings. We’ll be talking about this:</p><h3>AWS re:Invent on Twitter: &quot;Announcing Aurora Serverless. All the capabilities of Aurora, but pay only by the second when your database is being used #reInvent pic.twitter.com/AP5R6jf7RB / Twitter&quot;</h3><p>Announcing Aurora Serverless. All the capabilities of Aurora, but pay only by the second when your database is being used #reInvent pic.twitter.com/AP5R6jf7RB</p><p>That’s right. <strong>Serverless Aurora.</strong></p><p>Why is Serverless Aurora so important? We first need to understand two things: the technology-driven changes in software architectures in the cloud era, and the current state of the data layer in serverless architectures.</p><h3>The Architectural Evolution</h3><p>Earlier this year, Adrian Cockcroft wrote a piece on the <a href="https://read.acloud.guru/evolution-of-business-logic-from-monoliths-through-microservices-to-functions-ff464b95a44d">Evolution of Business Logic from Monoliths through Microservices, to Functions</a> that blew my mind. It showed how changes in technology are driving changes in development patterns and processes. Adrian has had a front row seat for these changes over the years from his work at eBay, Netflix, and now AWS.</p><p>A bunch of unrelated technologies combined to drive these changes. Faster networks and better serialization protocols enabled compute that was distributed rather than centralized. This enabled API-driven architecture patterns that used managed services from SaaS providers and broke monoliths into microservices.</p><p>Chef, Puppet, EC2 and Docker and eventually Lambda combined to enable and promote ephemeral compute environments that reduced time to value and increased utilization. These tools were combined with the necessary process improvements from the DevOps movement to increase velocity. We’re seeing smaller teams deliver features faster with lower costs.</p><p>These changes have been huge, but the data layer has been lagging. Adrian touched on database improvements, but they aren’t as mind-blowing. They have explicit tradeoffs of simple query patterns:</p><blockquote><em>Compared to relational databases, NoSQL databases provide simple but extremely cost effective, highly available and scalable databases with very low latency.</em></blockquote><p>The lagging data layer is particularly problematic in Serverless architectures.</p><h3>The Problem of the Serverless Data Layer</h3><p>I <a href="https://serverless.com/blog/serverless-conf-2017-nyc-recap/#data-layer-in-the-serverless-world">spoke on this problem</a> at ServerlessConf NYC in October. In short, there are two approaches you can take with databases with serverless compute: <em>server-full</em> or <em>serverless</em>.</p><h3>Server-full databases</h3><p>A server-full approach uses instance-based solutions such as MySQL, Postgres, or MongoDB. I classify them as instance-based when you can tell me how many instances you have running and what their hostnames are.</p><p>I like Postgres + Mongo because of <a href="https://db-engines.com/en/ranking">their popularity</a>, which means data design patterns are well-known and language libraries are mature.</p><p>However, these instance-based solutions were designed for a pre-serverless world with long-running compute instances. This leads to the following problems:</p><p><em>Connection Limits</em></p><p>Postgres and MySQL have limits of the number of active connections (e.g. 100) you can have at any one time. This can cause problems if you get a spike in traffic which causes a large number of Lambda to fire.</p><p><em>Networking issues</em></p><p>Your database instances will often have strict firewall rules about which IP addresses can access them. This can be problematic with ephemeral compute — adding custom network interfaces will add latency to your compute’s initialization.</p><p><em>Provisioning issues</em></p><p>Serverless architectures fit well with defining Infrastructure as Code. This is harder with something like Postgres roles (users). These aren’t easily scriptable in your CloudFormation or Terraform, which spreads your configuration out across multiple tools.</p><p><em>Scaling issues</em></p><p>This is one of the most important problems. Instance-based databases aren’t designed to scale up and down quickly. If you have variable traffic during the week, you’re likely paying for the database you need at peak rather than adjusting throughout the week.</p><h3>Serverless databases</h3><p>In contrast to server-full, instance-based databases, there is a class of serverless databases. Serverless databases are different in that you’re usually paying for <em>throughput</em> rather than a particular number and size of instances.</p><p>There are a few options for serverless databases, including <a href="https://firebase.google.com/">Firebase</a> and <a href="https://fauna.com/">FaunaDB</a>. However, the most common of these databases is <a href="https://aws.amazon.com/dynamodb/">DynamoDB</a> from AWS.</p><p>DynamoDB addresses most of the problems listed above with server-full databases. There are no connection limits, just the general throughput limits from your provisioned capacity. Further, DynamoDB is <em>mostly</em> easy to scale up and down with <a href="https://read.acloud.guru/why-amazon-dynamodb-isnt-for-everyone-and-how-to-decide-when-it-s-for-you-aefc52ea9476#5aa1">some caveats</a>. Also, the networking and provisioning issues are mitigated as well. All access is over HTTP and authentication / authorization is done with <a href="https://serverless.com/blog/abcs-of-iam-permissions/">IAM permissions</a>. This makes it much easier to use in a world with ephemeral compute.</p><p>However, DynamoDB isn’t perfect as a database. You should really read Forrest Brazeal’s excellent piece on <a href="https://read.acloud.guru/why-amazon-dynamodb-isnt-for-everyone-and-how-to-decide-when-it-s-for-you-aefc52ea9476">Why Amazon DynamoDB isn’t for everyone</a>. In particular, the query patterns can be very difficult to get correct. DynamoDB is essentially a key-value store, when means you need to configure your data design very closely to your expected query patterns.</p><p>To me, the biggest problem is the loss of flexibility in moving from a relational database to DynamoDB. With a relational model, it’s usually easy to query the data in a new way for a new use case. There isn’t that same flexibility for DynamoDB.</p><p>Developer agility is one of the key benefits of serverless architectures. Having to migrate and rewrite data is a major blocker to this agility.</p><h3>The Future of Data</h3><h3>Ben Kehoe on Twitter: &quot;Transition to the #cloud: treat servers like cattle, not pets. Transition to #serverless cloud architecture: treat servers like roaches / Twitter&quot;</h3><p>Transition to the #cloud: treat servers like cattle, not pets. Transition to #serverless cloud architecture: treat servers like roaches</p><p>Ben Kehoe loves to hammer the point that to be truly serverless, your compute should not exist when it’s not handling data. This hyper-ephemeral compute requires a new type of database. Highly-scalable, automation-friendly, global, with a flexible data model to boot.</p><p>Distributed databases are hard. The NoSQL movement, including the <a href="http://www.allthingsdistributed.com/files/amazon-dynamo-sosp2007.pdf">Dynamo paper</a> that describes the principles of DynamoDB and influenced its cousins (Apache Cassandra, Riak, etc.), was a first step in the database revolution.</p><p>The second step is in motion now. AWS announced <a href="https://aws.amazon.com/about-aws/whats-new/2017/11/sign-up-for-the-preview-of-amazon-aurora-multi-master/">multi-master Aurora</a>, allowing for your Aurora instances to have masters that accept writes in different Availability Zones. Similarly, they announced <a href="https://aws.amazon.com/dynamodb/global-tables/">DynamoDB Global Tables</a> which syncs data from DynamoDB tables <em>across different regions</em> (!). Writes in São Paulo will be replicated to your copies in Ohio, Dublin, and Tokyo, seamlessly. These manage the difficulty of multi-master global databases.</p><p>The next step is Serverless Aurora, due sometime in 2018. It checks all the boxes for a serverless database:</p><p>✔︎ Easy scaling.</p><p>✔︎ Pay-per-use.</p><p>✔︎ Accessible over HTTP.</p><p>✔︎ Authentication &amp; authorization over tightly-scoped IAM roles rather than database roles.</p><p>✔︎ A flexible relational data model that most developers know.</p><p>This is a big deal.</p><p>We’ve seen the hints that Amazon recognizes the issues with existing relational solutions in the cloud-native paradigm. They’ve implemented <a href="http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html">IAM authentication</a> for MySQL and Aurora MySQL databases already. Further, the <a href="https://media.amazonwebservices.com/blog/2017/aurora-design-considerations-paper.pdf">Aurora design paper</a> notes how they have changed the relational database for a cloud-native world.</p><p>I believe this is only the first step in Amazon’s plan to push the database further. With the rise of social networks and recommendation engines, graph databases have become more popular. Amazon’s new <a href="https://aws.amazon.com/neptune/">Neptune graph database</a> is an foray into another data area. Graph databases are <a href="http://jimwebber.org/2011/02/on-sharding-graph-databases/">notoriously hard to shard</a>, so it may be a while before we see a Serverless Neptune. I wouldn’t bet against it coming eventually.</p><p>re:Invent is about the future, and that’s why it’s my favorite conference of the year. When we look back on re:Invent 2017, I have a feeling the data layer improvements will be the most important of all.</p><figure><a href="https://console.serverless.com/?view=register&amp;utm_campaign=Console%20Signup&amp;utm_source=medium&amp;utm_medium=post&amp;utm_content=Serverless%20Aurora%3A%20What%20it%20means%20and%20why%20it%27s%20the%20future%20of%C2%A0data"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coRpboSHyAtv5UPafeHzbw.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NCHqjhEtW2FQQm5NO0ekAg.png" /></figure><p><em>Originally published at </em><a href="https://www.serverless.com/blog/serverless-aurora-future-of-data/"><em>https://www.serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c562422c703" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using TensorFlow and the Serverless Framework for deep learning and image recognition]]></title>
            <link>https://medium.com/@serverlessinc/using-tensorflow-and-the-serverless-framework-for-deep-learning-and-image-recognition-1b1e5fb730d8?source=rss-10625560e1ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b1e5fb730d8</guid>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[image-recognition]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Serverless]]></dc:creator>
            <pubDate>Tue, 31 May 2022 16:59:06 GMT</pubDate>
            <atom:updated>2022-05-31T16:59:06.429Z</atom:updated>
            <content:encoded><![CDATA[<p>Originally posted at <a href="https://www.serverless.com/blog/using-tensorflow-serverless-framework-deep-learning-image-recognition/">Serverless</a> on July 24th, 2018</p><p>Deep and machine learning is becoming essential for a lot of businesses, be it for internal projects or external ones.</p><p>The data-driven approach allows companies to build analytics tools based on their data, without constructing complicated deterministic algorithms. Deep learning allows them to use more raw data than a machine learning approach, making it applicable to a larger number of use cases. Also, by using pre-trained neural networks, companies can start using state of the art applications like image captioning, segmentation and text analysis-without significant investment into data science team.</p><p>But one of the main issues companies face with deep/machine learning is finding the right way to deploy these models.</p><p>I wholeheartedly recommend a serverless approach. Why? Because serverless provides a cheap, scalable and reliable architecture for deep learning models.</p><p>In this post, we’ll cover how to build your first deep learning API using the <a href="https://serverless.com/framework/">Serverless Framework</a>, TensorFlow, AWS Lambda and API Gateway.</p><p>We will cover the following:</p><ul><li>Using serverless for deep learning — standard ways of deploying deep learning applications, and how a serverless approach can be beneficial.</li><li>“Hello world” code — a basic Lambda function with only 4 lines of code. There is no API here, we’ll start with the simplest possible example.</li><li>Code decomposition — looking through the configuration file, and the python code for handling the model, to understand how the whole example works.</li><li>API example — get a working API for image recognition on top of our example.</li></ul><p>If you want to skip the background about what TensorFlow is and why you’d want to use serverless for machine learning, <a href="https://www.serverless.com/blog/using-tensorflow-serverless-framework-deep-learning-image-recognition/#the-basic-4-line-example">the actual example starts here</a>.</p><h3>Why Serverless + TensorFlow?</h3><p>First of all, let’s briefly cover what TensorFlow is: an open source library that allows developers to easily create, train and deploy neural networks. It’s currently the most popular framework for deep learning, and is adored by both novices and experts.</p><p>Currently, the way to deploy pre-trained TensorFlow model is to use a cluster of instances.</p><p>So to make deep learning API, we would need stack like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*bmnhD2CK4o1Gqpdn.gif" /></figure><p>The main pain points in this infrastructure is that:</p><ul><li>you have to manage the cluster — its size, type and logic for scaling</li><li>you have to pay for unused server power</li><li>you have to manage the container logic — logging, handling of multiple requests, etc</li></ul><p>With AWS Lambda, we can make the stack significantly easier and use simpler architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/0*k0eS2HmLg7bNo8fO.png" /></figure><h3>The difference in both approaches</h3><p>First of all, a serverless serverless approach is very scalable. It can scale up to 10k concurrent requests without writing any additional logic. It’s perfect for handling random high loads, as it doesn’t take any additional time to scale.</p><p>Second, you don’t have to pay for unused server time. Serverless architectures have pay-as-you-go model. Meaning, if you have 25k requests per month, you will only pay for 25k requests.</p><p>And not only does it make pricing completely transparent, it’s just a lot cheaper. For the example TensorFlow model we’ll cover in this post, it costs 1$ for about 25k requests. A similar cluster would cost a <em>lot</em> more, and you’d only achieve pricing parity once you hit 1M requests.</p><p>Third, infrastructure itself becomes a lot easier. You don’t have to handle Docker containers, logic for multiple requests, or cluster orchestration.</p><p>Bottom line: you don’t have to hire someone to do devops for this, as any backend developer can easily handle it.</p><p>As we’ll see in a minute, deploying a serverless deep/machine learning infrastructure can be done with as little as 4 lines of code.</p><p>That said, when <em>wouldn’t</em> you go with a serverless approach? There are some limitations to be aware of:</p><ul><li>Lambda has <a href="https://docs.aws.amazon.com/lambda/latest/dg/limits.html">strict limits</a> in terms of processing time and used memory, you’ll want to make sure you won’t be hitting those</li><li>As mentioned above, clusters are more cost effective after a certain number of requests. In cases where you don’t have peak loads and the number of requests is really high (I mean 10M per month high), a cluster will actually save you money.</li><li>Lambda has a small, but certain, startup time. TensorFlow also has to download the model from S3 to start up. For the example in this post, a cold execution will take 4.5 seconds and a warm execution will take 3 seconds. It may not be critical for some applications, but if you are focused on real-time execution then a cluster will be more responsive.</li></ul><h3>The basic 4 line example</h3><p>Let’s get started with our serverless deep learning API!</p><p>For this example, I’m using a pretty popular application of neural networks: image recognition. Our application will take an image as input, and return a description of the object in it.</p><p>These kinds of applications are commonly used to filter visual content or classify stacks of images in certain groups. Our app will try to recognize this picture of a panda:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/102/0*_4XOBCbGFjbiw5vk.png" /></figure><p><strong>Note:</strong> The model and example are also available <a href="https://www.tensorflow.org/tutorials/images/image_recognition">here</a>.</p><p>We’ll use the following stack:</p><ul><li>API Gateway for managing requests</li><li>AWS Lambda for processing</li><li>Serverless framework for handling deployment and configuration</li></ul><h3>“Hello world” code</h3><p>To get started, you’ll need to <a href="https://serverless.com/framework/docs/providers/aws/guide/installation/">have the Serverless Framework installed</a>.</p><p>Create an empty folder and run following commands in the CLI:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd04cb6976734bceb1336f09b3084c57/href">https://medium.com/media/dd04cb6976734bceb1336f09b3084c57/href</a></iframe><p>You’ll receive the following response:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ae3208878084586c87fd6251a2f1dce/href">https://medium.com/media/6ae3208878084586c87fd6251a2f1dce/href</a></iframe><p>As you can see, our application successfully recognized this picture of a panda (0.89 score).</p><p>That’s it. You’ve just successfully deployed to AWS Lambda with TensorFlow, using the Inception-v3 model for image recognition!</p><h3>Code decomposition — breaking down the model</h3><p>Let’s start with serverless YAML file. Nothing uncommon here-we’re using a pretty standard deployment method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f593e857e5b24dd14703615242d9a294/href">https://medium.com/media/f593e857e5b24dd14703615242d9a294/href</a></iframe><p>If we will look into the index.py file itself, we will see that first we need to download the model (.pb file) to the AWS Lambda .tmp folder, and then load it via a standard TensorFlow import function.</p><p>Here are the parts you have to keep in mind if you want to put your own model, with the links straight to the full code in GitHub:</p><p><a href="https://github.com/ryfeus/lambda-packs/blob/master/Tensorflow/source/index.py#L141"><strong>Model download from S3</strong></a><strong>:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c84564b639d4114412ebd198261d961c/href">https://medium.com/media/c84564b639d4114412ebd198261d961c/href</a></iframe><p><a href="https://github.com/ryfeus/lambda-packs/blob/master/Tensorflow/source/index.py#L80"><strong>Model import</strong></a><strong>:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e73e45371b70b84f76486c47b3228166/href">https://medium.com/media/e73e45371b70b84f76486c47b3228166/href</a></iframe><p><a href="https://github.com/ryfeus/lambda-packs/blob/master/Tensorflow/source/index.py#L147"><strong>Getting the image</strong></a><strong>:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/078936d0e78dadc10c89392b0cf730d0/href">https://medium.com/media/078936d0e78dadc10c89392b0cf730d0/href</a></iframe><p><a href="https://github.com/ryfeus/lambda-packs/blob/master/Tensorflow/source/index.py#L107"><strong>Getting predictions from the model</strong></a><strong>:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c32cf88f642a962c22671787c7050ac/href">https://medium.com/media/6c32cf88f642a962c22671787c7050ac/href</a></iframe><p>Now, let’s move on, and add an API to this!</p><h3>API example</h3><p>The simplest way to add an API to the example is to modify the serverless YAML file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1a7e5728a352f4b750f68ad10e6f596/href">https://medium.com/media/c1a7e5728a352f4b750f68ad10e6f596/href</a></iframe><p>Then, we redeploy the stack:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/409243ad1a47f355c8e0288a0dc6db1b/href">https://medium.com/media/409243ad1a47f355c8e0288a0dc6db1b/href</a></iframe><p>And receive the following response:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4174e59b4bd549d18f29f02b692db54e/href">https://medium.com/media/4174e59b4bd549d18f29f02b692db54e/href</a></iframe><p>To test the link, we can just open it in the browser:</p><p><a href="https://.execute-api.us-east-1.amazonaws.com/dev/handler">https://.execute-api.us-east-1.amazonaws.com/dev/handler</a></p><p>Or run curl:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47128ad6e9af94724de10cc53d70b674/href">https://medium.com/media/47128ad6e9af94724de10cc53d70b674/href</a></iframe><p>We will receive:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/349e4c45bfec3e8450845732de78e8f8/href">https://medium.com/media/349e4c45bfec3e8450845732de78e8f8/href</a></iframe><h3>Conclusion</h3><p>We’ve created a TensorFlow endpoint on AWS Lambda via the <a href="https://serverless.com/framework/">Serverless Framework</a>. Setting everything up was extremely easy, and saved us a lot of time over the more traditional approach.</p><p>By modifying the serverless YAML file, you can connect SQS and, say, create a deep learning pipeline, or even connect it to a chatbot via AWS Lex.</p><p>As a hobby, I port a lot of libraries to make the serverless friendly. <a href="https://github.com/ryfeus/lambda-packs">You can look at them here</a>. They all have an MIT license, so feel free to modify and use them for your project.</p><p>The libraries include the following examples:</p><ul><li>Machine learning libraries (Scikit, LightGBM)</li><li>Computer vision libraries (Skimage, OpenCV, PIL)</li><li>OCR libraries (Tesseract)</li><li>NLP libraries (Spacy)</li><li>Web scraping libraries (Selenium, PhantomJS, lxml)</li><li>Load testing libraries (WRK, pyrestest)</li></ul><p>I’m excited to see how others are using serverless to empower their development. Feel free to drop me a line in the comments, and happy developing!</p><figure><a href="https://console.serverless.com/?view=register&amp;utm_campaign=Console%20Signup&amp;utm_source=medium&amp;utm_medium=post&amp;utm_content=Using%20TensorFlow%20and%20the%20Serverless%20Framework%20for%20deep%20learning%20and%20image%20recognition"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coRpboSHyAtv5UPafeHzbw.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NCHqjhEtW2FQQm5NO0ekAg.png" /></figure><p><em>Originally published at </em><a href="https://www.serverless.com/blog/using-tensorflow-serverless-framework-deep-learning-image-recognition/"><em>https://www.serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b1e5fb730d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[6 Things to Know Before Migrating An Existing Service to Serverless]]></title>
            <link>https://medium.com/@serverlessinc/6-things-to-know-before-migrating-an-existing-service-to-serverless-7da071ebd7b9?source=rss-10625560e1ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/7da071ebd7b9</guid>
            <category><![CDATA[serverless-architecture]]></category>
            <category><![CDATA[serverless-computing]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[serverless-apps]]></category>
            <dc:creator><![CDATA[Serverless]]></dc:creator>
            <pubDate>Tue, 31 May 2022 16:00:19 GMT</pubDate>
            <atom:updated>2022-05-31T16:00:19.979Z</atom:updated>
            <content:encoded><![CDATA[<p>Originally posted at <a href="https://www.serverless.com/blog/6-things-to-know-before-migrating-an-existing-service-to-serverless">Serverless</a> on August 7th, 2017</p><p>Last year, my company decided to make the plunge. We were going to go Serverless! Except…most of the resources about serverless architectures are about how to start from scratch, not how to migrate existing services over.</p><p>We spent eight months figuring it out along the way and, for all of you serverless hopefuls, we made a cheat sheet. These are the steps that worked for us:</p><ol><li>Identify the problems</li><li>Train the existing team</li><li>Create a Proof of Concept to verify that the problem is solved</li><li>Optimize the solution to take advantage of the cloud</li><li>Automate your Continuous Integration/Continuous Deployment pipeline</li><li>Automate your testing</li></ol><h3>1. Identify the problems</h3><p>What problems will serverless solve that your current solution does not? We (for example) wanted serverless to help us (1) lower operational costs, and (2) give us an easier way to replace a bunch of legacy systems with a small team.</p><p>At my company, we decided that since AWS Lambda can be used as a glue between different AWS managed services, it was the best option for us.</p><h3>2. Train the team</h3><p>After you have defined the problems, it is easier to define (more or less) what set of technologies can help you. Your developers are the ones who already know your business logic and service requirements better than anyone else. So instead of heavily outsourcing, I’d recommend that if no one on your existing team is familiar with serverless, it is time to train them.</p><p>We encouraged our developers to go to meetups, conferences and to spend time (even work hours) tinkering with new technologies. In addition to that, we did hire a Serverless consultant to show us how to think in an event-driven manner and make sure we were following best practices.</p><p>In my opinion, one of the reasons our project was so successful was the weekly workshop meetings we held. They lasted 3–4 hours per week, and we used that time for discussing new serverless-related topics, solving issues and implementing solutions. We all got to learn a lot from each other, and workshop was very inspiring.</p><p>After you have identified the key problems to solve, and after your team has a better understanding of the tools available, it’s time to create Proof of Concept. By now, your team should have an idea of what to do next-a “hypothesis”. A Proof of Concept will help the team validate their hypothesis.</p><p>Remember: a Proof of Concept is <em>not</em> production code. Use it to focus on solving your problem and get rid of it. Your Proof of Concept should go to the trash after validating your hypothesis.</p><p>In our project, we developed five Proofs of Concept. Recall that our problems were: (1) to replace legacy systems and (2) reduce operational costs. Our hypotheses were as follows:</p><p><strong>To replace legacy systems:</strong></p><ul><li>AWS Cognito will replace the existing authentication system</li><li>DynamoDB will replace the existing Riak database as our NoSQL database</li><li>AWS Lambda + S3 + Elastic Transcoding will replace our existing transcoding process</li><li>AWS Lambda + API Gateway + S3 will replace our existing image resizing and provide better caching mechanisms</li></ul><p><strong>To reduce high operational costs:</strong></p><p>By implementing these Proofs of Concept, my team ended up validating all of our hypotheses.</p><h3>4. Optimize the solution to take advantage of the cloud</h3><p>This step is critically in line with the previous step. When thinking about your Proofs of Concept and new architecture, it’s important to take full advantage of the cloud. As in: don’t just grab your instances and decompose them into AWS Lambdas and API Gateways using a DynamoBD; try to think about how to take advantage of cloud-managed services, like queues and caches.</p><p>Also remember that by migrating everything to Serverless, you are transforming the architecture of your system into an event-driven architecture. In an event-driven architecture, events move around your system and all the services are decoupled from each other. AWS has a lot of services that can be used to manage events communication, like queues and streams. S3 is a great place to store your events. DynamoDB Streams can be used to let other services know that there was a change in your DynamoDB database.</p><h3>5. Automate your Continuous Integration/Continuous Deployment pipeline</h3><p>Since people can disagree on what exactly a ‘microservice’ is, I call a microservice a collection of AWS Lambdas and other resources related to some very specific domain, like authentication, application management or transcoding. Serverless architectures involve lots of resources being deployed into different environments in this way. When you have several moving parts, one way to make things simpler is to automate everything you can.</p><p>On my team, we used Serverless Framework to organize our projects and to automate microservice deployment into different environments. We wanted to define all our infrastructure configuration as code. The Serverless Framework helped us to do that, as all the resources needed in the microservice can be defined using Cloud Formation notation in the Serverless YAML file.</p><p>We used Jenkins Continuous Integration server to take care of running the Serverless Framework deployment in three different environments (development, staging, and production). For each environment, we used a different AWS account. We wanted to have three accounts so we could take advantage of managed resources soft limits as much as possible, and also to keep the different environments isolated.</p><h3>6. Automate your testing</h3><p>Testing is undervalued by a lot of teams. In a Serverless and event-driven architecture, the complexity of the code moves to the architecture itself. Because of this, testing at all levels is critical for peace of mind. Test, test, test. Also, test.</p><p>Unit tests will help you to make sure that your business logic works. For your managed services, you should write integration tests against them. It’s important to define clear interfaces between your services and the managed services so that you can have control of what is going in and out of your service.</p><p>Don’t forget about End-to-end Testing. In an event-driven architecture, the services are decoupled from each other; as a result, it can be hard to know how the events are moving around the architecture.</p><h3>Conclusion</h3><p>Migrating an existing service to Serverless was work, true-but honestly, it was also fun. The two most important things to have in mind when migrating one (or all) of your existing services to serverless are:</p><ul><li>optimize your architecture to take advantage of the cloud</li><li>remember that your new architecture is an event-driven one</li></ul><p>Best of luck, and see you on the other side.</p><figure><a href="https://console.serverless.com/?view=register&amp;utm_campaign=Console%20Signup&amp;utm_source=medium&amp;utm_medium=post&amp;utm_content=6%20Things%20to%20Know%20Before%20Migrating%20An%20Existing%20Service%20to%20Serverless"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coRpboSHyAtv5UPafeHzbw.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NCHqjhEtW2FQQm5NO0ekAg.png" /></figure><p><em>Originally published at </em><a href="https://www.serverless.com/blog/6-things-to-know-before-migrating-an-existing-service-to-serverless"><em>https://www.serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7da071ebd7b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The State of Serverless Multi-cloud]]></title>
            <link>https://medium.com/@serverlessinc/the-state-of-serverless-multi-cloud-f9a824b39367?source=rss-10625560e1ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9a824b39367</guid>
            <category><![CDATA[multi-cloud]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[serverless-architecture]]></category>
            <dc:creator><![CDATA[Serverless]]></dc:creator>
            <pubDate>Fri, 27 May 2022 17:25:04 GMT</pubDate>
            <atom:updated>2022-05-27T21:27:59.829Z</atom:updated>
            <content:encoded><![CDATA[<p>Originally posted at <a href="https://www.serverless.com/blog/state-of-serverless-multi-cloud">Serverless</a> on November 6th, 2017</p><h3>To multi-cloud, or not to multi-cloud</h3><p>Vendor lock-in runs deep in serverless applications. “Cloud provider” used to mean “whoever hosts your servers”. In a serverless paradigm, it means “whoever runs your functions”.</p><p>And when the space doesn’t (yet) have standardization, developers must twirl those functions round and round in a whole vendor ecosystem of events and data storage. There’s no way to use Azure Functions and EC2 together.</p><p>“But,” you say, “ <a href="https://serverless.com/framework/">vendor-agnostic frameworks</a> let you easily deploy functions across providers, at least.” That they do! But then, there’s the small technicality of language choice. Write your application in Python and you’ll have a hard time moving that over to Google Cloud Functions.</p><p>Given all this, what do we make of the multi-cloud? Is it a pipe dream, or an attainable goal-and do we <em>actually</em> need it?</p><h3>Multi-cloud gives you wings</h3><p>The biggest advantage to serverless multi-cloud we hear in the field is feature arbitrage. Imagine plucking all your favorite aspects of each cloud provider and placing them nicely together in your very own, custom-made bouquet.</p><p>It’s hard to commit to a single ecosystem, especially when serverless compute vendors are constantly adding new features that change the value equation. AWS Lambda is adding traffic shifting in Lambda aliases any day now; Microsoft Azure has their (still unique) Logic Apps, which lets you manage event-driven services much like you’re composing an IFTTT.</p><p>Pricing works out differently across vendors for different services. The same project could work better elsewhere in less than 6 months because of all this rapid feature launching. We fear lock-in because it removes our flexibility of choice.</p><p>And then, add failover into the mix.</p><p>With serverless compute, you don’t have to worry about redundancy quite as much-Lambda, for instance, automatically scales across multiple availability zones for you. But entire regions can (and do) go down.</p><p>While it’s a rare corner case, cloud outages can be devastating; we see larger companies caring more about this and moving to incorporate strategies for full cloud redundancy.</p><h3>Multi-cloud gives you pause</h3><p>As fun as dreamspace is, we do still have to wake up in the morning and ask ourselves: is a multi-cloud attainable and worth it?</p><p>Let’s say you want to actually try and instrument full cloud failover. The first thing you’ll have to do is write everything in the only language all four major cloud providers support. Aka: JavaScript.</p><p>Then, you’ll need to abandon your cloud databases for something like MySQL. You’ll need to constantly replicate that data from one cloud provider to another so that everything is up to date when failover occurs. You have to think, hard, about how each cloud handles logging? Secrets? Metrics?</p><p>The rule of the game is to make everything as generic as possible-which seems to go against the serverless ethos, in a way, and prevents you from utilizing those powerful features you were trying to get with multi-cloud in the first place.</p><p>It’s also worth mentioning that, for those who do choose to run an ecosystem across multiple providers, you’re paying for transfer. Not cheap.</p><p>Maybe the answer ends up being: yes, it would be cool to leverage any service I want, whenever I want, and still maintain that serverless flexibility, but things just aren’t there yet. We don’t have a Schroedinger’s cake.</p><h3>The multi-way forward</h3><p>There are a series of things that could happen to make multi-cloud easier.</p><p><strong>Cross-cloud service compatibility</strong> Data management and storage, for instance, are ecosystem-dependent. Google has best machine learning right now; and while it’s <em>feasible</em> to use GC services on different cloud providers, it isn’t necessarily simple.</p><p>To make multi-cloud less work and less compromise, we need to be better ways to share data across cloud providers, and better ways react to any event source regardless of cloud provider.</p><p><strong>Add shims for polyglot language support</strong> That way, it wouldn’t matter whether or not you wrote your functions in Go. Doing this yourself could be cumbersome, but soon there will probably be tools that facilitate this for you.</p><p><strong>Smartly route your data</strong> This one’s on you, the spritely developer. Divide your application into two conceptual parts: ‘critical path’ and ‘specialized features that don’t need need to work 100% of the time’.</p><p>Anything in the critical path (things that serve your site, for instance) should be written in a cloud-agnostic way. That makes it easier to implement failover or port things over to another provider, should you need. Specialized services (e.g., image tagging) can be maintained separately for a time, or be made to process important data later in case of an outage.</p><h3>The…multi-verse?</h3><p>Multi-cloud probably won’t ever be completely work-free, but we expect it’ll be easy enough-sooner more than later.</p><p>And then we’ll start to see the landscape shift. Cloud providers won’t be fighting for bigger chunks of your server space; they’ll be fighting for bigger chunks of your application, in the form of features and services.</p><p>This is frankly already happening. We stereotype giants like Microsoft and Amazon as being slow to innovate, yet they’ve been rushing to push feature after serverless feature for the past two years. They’re moving faster than most startups.</p><p>As an industry, we’re headed for a user-centric software reality. Businesses will increasingly differentiate themselves with highly customized software, and multi-cloud is how they’ll do it.</p><figure><a href="https://console.serverless.com/?view=register&amp;utm_campaign=Console%20Signup&amp;utm_source=medium&amp;utm_medium=post&amp;utm_content=The%20State%20of%20Serverless%20Multi-cloud"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coRpboSHyAtv5UPafeHzbw.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NCHqjhEtW2FQQm5NO0ekAg.png" /></figure><p><em>Originally published at </em><a href="https://www.serverless.com/blog/state-of-serverless-multi-cloud"><em>https://www.serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9a824b39367" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>