<?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 Brian McCann on Medium]]></title>
        <description><![CDATA[Stories by Brian McCann on Medium]]></description>
        <link>https://medium.com/@bmccann?source=rss-172af88a378e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*d5OImH6A2rz57MR7IiuiIg.jpeg</url>
            <title>Stories by Brian McCann on Medium</title>
            <link>https://medium.com/@bmccann?source=rss-172af88a378e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:52:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bmccann/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[Is Quarkus the magic bullet for Java and AWS Lambda?]]></title>
            <link>https://bmccann.medium.com/is-quarkus-the-magic-bullet-for-java-and-aws-lambda-567a0968a971?source=rss-172af88a378e------2</link>
            <guid isPermaLink="false">https://medium.com/p/567a0968a971</guid>
            <category><![CDATA[quarkus]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[cloud-native]]></category>
            <dc:creator><![CDATA[Brian McCann]]></dc:creator>
            <pubDate>Mon, 05 Apr 2021 12:06:32 GMT</pubDate>
            <atom:updated>2021-04-05T12:06:32.865Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I’ll investigate the benefits of using Quarkus to package a micro-service written in Java as a native executable to speed up Lambda execution time and reduce memory footprint. This article assumes familiarity with the concepts of AWS Lambda, cold starts, and Java. Here is a <a href="https://medium.com/@bmccann36/java-developers-its-time-to-give-aws-lambda-a-try-c265215603a1">previous article</a> I wrote that may be a good starting point in case Lambda is new to you.</p><p>When we consider using AWS Lambda as an option to run our code, we frequently assume that the code is written in Node.js or Python. According to <a href="https://www.datadoghq.com/state-of-serverless/">data dog</a>’s state of serverless survey, of all currently deployed Lambdas, 47% are python and 39% are Node. Java is a distant third at under 10%.</p><p>If you search for tutorials on the web the majority are geared toward one of these popular runtimes. Part of the reason is probably just that these languages are popular and have been trending upward in popularity in past years. Another reason for the trend is the inherent characteristics of the JVM and popular associated Java frameworks.</p><p><em>TLDR; the JVM takes a while to start up and uses a lot of memory.</em></p><p>This can be a blocker if you want to publish an application on Lambda, primarily because a trade off of using AWS Lambda is that we have to deal with <strong>cold starts. </strong>As most people with experience using Lambda in production will tell you, cold starts are really not something you should worry about. Their effect on most applications is close to nothing. But still, it’s something that scares people who are new to Lambda. If you want know more about cold starts or don’t have first hand experience here are two good articles.</p><ul><li><a href="https://lumigo.io/blog/this-is-all-you-need-to-know-about-lambda-cold-starts/">This is all you need to know about Lambda cold starts | Lumigo</a></li><li><a href="https://blog.symphonia.io/posts/2020-06-30_analyzing_cold_start_latency_of_aws_lambda">Analyzing Cold Start latency of AWS Lambda</a></li></ul><h4>When should I care about cold starts?</h4><p>There are situations where cold starts are a problem. In this article I’ll bring up two. First, in the case that you really need your backend to always respond in under a second or two, cold starts will be problem for you. Second, if you are using Spring, even though cold starts are infrequent, the amount of time it takes for the Spring application to initialize, and therefore be ready to serve requests, is so long it’s probably unacceptable if your backend serves a user interface. Java already has a performance disadvantage (only in regard to cold starts) compared to other languages you can use with lambda. In addition to the cold start overhead of the JVM itself, your app written with Spring also has to initialize the Spring context with all of the classes your application will use at runtime. In the past, when Spring was becoming popular, this was no concern because a calling client would never need to wait for a Spring application to start up. Startup was something you did in the background while the previous version of your app was still up and serving client requests as they came in. Only when your new deployment was fully booted and ready to respond to traffic would traffic actually be directed to it.</p><p>Lambda by contrast does not always work this way. Sometimes a client will call a Lambda and an available execution environment will not be running so the client will have to wait for a new one to be created from scratch. If you’ve worked with docker you can think of it as running docker run for the first time to create a container instance on a given machine. Most of the time this doesn’t have to happen because there is a “hot” Lambda container instance ready to respond to the request. You will rarely see a Lambda runtime instance alive for more than 40–50 minutes. They are deliberately engineered to be very short lived. This is how AWS can offer the “pay only for what you use” billing model and for the functions to scale up and down rapidly at massive scale.</p><p>When we build with Spring we assume that a given iteration of our app will start once and run until it’s time to push an update. The Lambda execution model flips this assumption on its head. When we run our code on Lambda, we are effectively shutting down and restarting our whole app many times a day.</p><h4>Enter Quarkus</h4><p>Quarkus, in contrast to Spring is engineered to boot-up quickly and use less memory. It is therefore well suited to use with Lambda. Even more important is the fact that it is designed to work seamlessly with GraalVM so that if desired, you can build your app as a native executable. Here is a blurb from the official GraalVM page:</p><blockquote>Native Image is a technology to ahead-of-time compile Java code to a standalone executable, called a <strong>native image</strong>. This executable includes the application classes, classes from its dependencies, runtime library classes, and statically linked native code from JDK. It does not run on the Java VM, but includes necessary components like memory management, thread scheduling, and so on from a different runtime system, called “Substrate VM”.</blockquote><p>A quick review of what’s stated above</p><ul><li>Moves a lot of runtime work to build time</li><li>No JVM needed to run the software artifact (./application instead of application.jar)</li></ul><p>Go here to read about it more detail <a href="https://www.graalvm.org/reference-manual/native-image/">https://www.graalvm.org/reference-manual/native-image/</a>.</p><p>If you know about AWS Lambda you probably know that since a few years ago you can “bring your own” runtime to Lambda. This basically means that instead of using a pre-installed version of Javascript, Java, or Python, you can provide to your Lambda function the interpreter that will execute your code at runtime. In the case of a native image, we don’t need any special interpreter at all. The base Lambda execution environment is Amazon Linux which is capable of executing the native image that GraalVM builds. Quarkus provides a plugin that makes it easy to take advantage of the Lambda BYO runtime feature. I have used it to build the sample applications that we’ll discuss soon.</p><h4>Cold starts, Quarkus, Custom Runtimes, Graal what does it all mean?</h4><p>We’ve established that in some situations cold starts are a problem. By building our application as a native image we will still face cold starts but they will be significantly faster. Lambda will support us running a native image since the Lambda service now allows us to specify our own runtime. By applying Quarkus, and GrallVM to fix the cold start problem, we are effectively authoring our source code in Java but we are not executing our Java classes inside of a JVM. Instead we are doing a lot of the heavy lifting at application build time so at runtime things will go faster.</p><p>The intention of this article is not to explain how the magic of Quarkus and GraalVM works, there is plenty of good writing on the Quarkus and Graal sites if you want to know more. In this post, we will look at what Quarkus means to us as rank-and-file developers who want to use it with Lambda.</p><h4>Comparing 4 “flavors”</h4><p>I’m going to compare 4 different variations of a completely bare bones “hello world” backend micro-service. Each deployment will have one RESTful route exposed to the internet that a client can call. Each will return a simple string response without doing any extra processing or calling out to any external systems like another API or a database. I’ve deployed one Node.js Lambda with the Express framework so we have something to compare Java against.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CZMXLhkpPvQ7kxcMpDvo2g.png" /><figcaption>the four different “flavors” I will compare</figcaption></figure><p>As depicted in the diagram the 4 different configurations will be</p><ol><li>Node.js with Express backend framework</li><li>Java 11 (Amazon Corretto) with Spring Boot backend framework</li><li>Java 11 (Amazon Corretto) with Quarkus backend framework</li><li>Code authored in Java with Quarkus then built with graalVM and deployed as native binary executable.</li></ol><p>Across these different runtimes and configurations we will compare</p><ul><li>How long it takes for a fresh Lambda Execution environment to start (cold start)</li><li>How much memory is consumed on a cold start</li><li>Cold start vs. warm start (already initialized) Lambda execution time</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tVxgoYgq3fcN-sMwYxDXrQ.png" /><figcaption>average cold starts in milliseconds across runtimes with 256mb of ram configured</figcaption></figure><p>Let’s first look at how the 4 different “runtime flavors” stack up with 256mb of Ram configured. In a production setting you would probably want to allocate more memory to your function. One interesting design feature of Lambda is that the maximum amount of compute capacity is available for the first ten seconds that your function is initializing on cold start. Therefore it is pointless to allocate more memory to your function hoping to improve the initialization phase performance.</p><p>The “average response time” field is just the sum of average duration and average init duration since those two things added together equals how long the function takes to return a response. The Quarkus native Lambda is about neck and neck with Node in terms of average response time. You can see that it uses marginally less memory but takes a few milliseconds more to initialize as well as to run. In my opinion the performance profile is close enough to essentially be equal.</p><p>These stats are for COLD STARTS ONLY, so this is worst case scenario. Most of the time the response will come much faster. In my opinion ~300ms is perfectly acceptable as a worst case response time for an API backend that synchronously responds to a client (like a UI). Of course, all of these functions include only a small bit of “hello world” code, when we start adding real logic and importing more external libraries it will affect the function’s duration and how much memory it uses. This isn’t a Lambda specific consideration though, this would be true for any code you want to run.</p><h4>What’s going on with the “init” phase?</h4><p>The init phase includes everything that has to happen before your actual Lambda code can run. The only time we will see an init phase is during a cold start. Remember that Lambda itself is a service offered by AWS. Any time we invoke a Lambda we are asking AWS to run our code in one of their billions of ephemeral sandboxes. In the case of a cold start, that sandbox doesn’t exist yet and needs to be built. You can read more about the different lifecycle phases of a Lambda function here. <a href="https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html">https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html</a></p><h4>The JVM flavored Lambdas</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sKl4ou5wzKpfWwwmyPphgw.png" /><figcaption>the same table data depicted in previous image summed up in a chart</figcaption></figure><p>The average total response time for the JVM Lambda with Quarkus framework is ~5 seconds while the Lambda using a JVM + Spring Boot is ~7 seconds. Spring boot uses on average 181mb of memory and Quarkus 163. It is interesting to note that the Spring Boot Lambda actually executes more quickly than Quarkus but takes Significantly longer to initialize. When you add in the network latency and time it takes to forward the request from API gateway we are looking at an overall 8–9 second wait between when we call the http endpoint and get response when using Spring Boot. At this point we should ask ourselves</p><p><em>Is it acceptable for my REST api to take 8 seconds to respond?</em></p><p>8 seconds is probably not an acceptable response time for an API service that would affect a customer facing User Interface. In 2021 if a user is on a web site and it takes more than 4–5 seconds for a page to load they will start to notice. Also keep in mind that a UI likely has to make a number of API requests to load in addition to running whatever Javascript it needs to render.</p><p>The Quarkus flavor is around 2 seconds faster, which is significant, but over 5 seconds is still not a great total response time. Before we get too concerned though let’s look at how frequently we can expect a client (and by proxy a user) to experience a cold start. I queried the logs to find out. In the table below, if isWarmStart = 1 that means the invocation is a warm start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZCV5QKzzBh3uHI8F9YpwWA.png" /><figcaption>number of cold starts compared to warm starts over a few days</figcaption></figure><p>These numbers actually surprised me. I knew that cold starts were infrequent but I did not realize just how infrequent. For Spring Boot, just 54 out of 36,195 invocations were cold starts. Thats just .14% of the invocations, meaning our users would get a slow reply about 1 out of 1000 times. This makes the Spring Boot option look a lot more desirable. I think that most businesses would be fine with these odds. Have you ever tried to buy something on Amazon and the checkout took a little extra time to load? I wonder what was happening under the hood? I bet you did not wonder this at the time, I also bet that you didn’t throw your hands up in frustration, walk away from the computer and give up on your purchase. Let’s re-frame the question I asked a moment ago.</p><p><em>Is it acceptable for my REST api to take 8 seconds to respond 1 in 1000 times, and less than a second the majority of the time ?</em></p><p>This is this question you should ask yourself if you are deploying a Java app written with Spring boot on AWS Lambda. I think that most of the time the answer is yes, it is acceptable but of course it all depends on what you are trying to do. I should also point out that a real spring boot application can take significantly longer to initialize. So are occasional cold starts still acceptable if they last 15–20 seconds. That, I’d say is pushing it.</p><p>I’ve played around a bit with the aws labs <a href="https://github.com/awslabs/aws-serverless-java-container">serverless java container</a> and once you start adding code and libraries that a real Spring Boot app would have, (like setting up a JDBC connection) the initialization times become pretty abysmal. In the instructions for implementing spring boot they recommend some techniques like not using component scan. They’ve also built in an option to initialize your app asynchronously</p><blockquote>If your application takes longer than 10 seconds to start, AWS Lambda will assume the sandbox is dead and attempt to start a new one. To make the most of the 10 seconds available in the initialization, and still return control back to the Lambda runtime in a timely fashion, we support asynchronous initialization</blockquote><p>The mere fact that they’ve had to build this feature in is a bit disconcerting.</p><h4>Response time for warm invocations</h4><p>Up to this point I’ve only discussed cold starts. As I said, cold starts only account for roughly .1 % of our function invocations in a best case scenario and possibly up to 1% worst case. The vast majority of the time our Lambda response times will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AaHXzR4kf1f9yHGj4epc_A.png" /><figcaption>averages across the same time span as samples above. (duration is in milliseconds)</figcaption></figure><p>As you can see they are all plenty fast, with the Quarkus native flavor as the clear winner. In this case there is no “init duration” field because the function is already initialized. These are the kind of numbers we’d expect from a traditional “long running” backend application like we’d deploy with Kubernetes or on an EC2 instance. All of these averages are so fast that there kind of isn’t much to talk about. Technically the native image flavor is more than 10x as fast the Quarkus/JVM flavor, but who really cares since its only a 10ms difference. That amount of time is imperceptible to a human.</p><h4>What about price ?</h4><p>One compelling reason we could have for making execution times as short as possible is price. With Lambda we are billed for every millisecond of compute we use and no more. Take note also that we are <strong>not billed for function initialization time</strong>, only for execution time so although Spring Boot takes a long time to initialize, we won’t be billed for that time. In the examples above we have configured 256mb of ram. We could actually up the ram to 512mb and still pay the same price. On the Lambda pricing page you can see the increments used for billing <a href="https://aws.amazon.com/lambda/pricing/">https://aws.amazon.com/lambda/pricing/</a>.</p><p>Let’s check to see what our bill would be for 5 million invocations assuming our function only takes 2 milliseconds to run and has under 512mb of ram configured.</p><p><em>5,000,000(invocations) x 2(ms) x $0.0000000083(price per ms runtime) = </em><strong><em>8</em>¢</strong></p><p>That is a pretty reasonable prices for 5 million function executions. Let’s take a look at what the Spring Boot version would cost</p><p><em>5,000,000(invocations) x 13(ms) x $0.0000000083(price per ms runtime) = </em><strong><em>53</em>¢</strong></p><p>As you can see, the price per milliseconds of running Lambda code is unbelievably cheap. Before you get too excited remember that in the real world our Lambda functions will be interacting with downstream systems that are likely not as fast. Any useful code is likely calling other APIs or interacting with external databases. To account for this I’m going to make up a more realistic number. Let’s say that our Lambda interacts with two other rest apis which it must wait on before responding to the client, bringing the total average execution time up to 800ms. Now our Lambda function costs $33 per 5 million requests. Still not bad at all. But now, if we are paying $33 a month for our Lambda function’s 5 million executions there isn’t much point in shaving off a few milliseconds. Doing so will only save us about 50 cents. My point is that the Lambda execution you will pay for typically won’t represent time that your code is processing data, it will be time that your function is blocked waiting to receive a response from another system.</p><p>Still its important to be aware of how your bill is calculated and where the costs are coming from. You may have an application that doesn’t reach out to external APIs and databases and instead does all of its processing without making additional networks calls. In this scenario it may be worth it to use Quarkus and GraalVM to get your execution time down as low as possible as it will save you money.</p><h4>Why you wouldn’t use native-image</h4><p>After reading this article you might think to yourself, “why would I ever choose the regular old JVM when I can have a native image that runs faster, uses less memory, and is therefore cheaper than the alternative?”. As you’ve probably guessed using the Quarkus native image feature is not without its tradeoffs. The graalVM team has put together a nice explanation of the limitations and tradeoffs involved with this technology. You can read about them here: <a href="https://github.com/oracle/graal/blob/master/substratevm/Limitations.md">https://github.com/oracle/graal/blob/master/substratevm/Limitations.md</a></p><p>One of the bigger caveats is that all code must be known at build time. I have worked with Java based tools in the past that take advantage of dynamic class loading, and it can be a pretty cool and useful feature. However, if you are operating in a Lambda environment I can’t really think of a situation where you would use this feature or if you even could. Also dynamic class loading only really makes sense for a runtime that you want to modify without shutting down, which by definition, is an execution environment that runs for a long time and Lambda definitely isn’t that. For this reason, I won’t count this limitation as a minus in the Lambda context.</p><p>This guide published by the Quarkus team goes over a few of the other gotchas you have to consider when using the native image feature with Lambda. This link takes you to closer to the end where they discuss the modifications needed for TLS.</p><p><a href="https://quarkus.io/guides/amazon-lambda#https">Quarkus - Amazon Lambda</a></p><p>If you want to use native image for many of the Lambda services you’d want to interact with you can’t use the SDK at out of the box and have to swap out the default http client.</p><p>Another gotcha that they don’t call out, is the amount of time it takes to build the native images. It took me between 4 and 5 minutes just to build the simple hello world Lambda. I imagine it might take a lot longer with a bigger more complicated app. Even though 4–5 minutes is not a super long time, I think it adds up when you are deploying frequently. Many of us are used to being able to build, package, and deploy our code to some sort of dev environment in well under a minute. In the case of Lambda, you can redeploy new code and have it ready to execute in a few seconds. Often the only way to test or debug a piece of functionality is to push changes over and over in a short span of time. This would get old if you had to wait for the native-image build every time.</p><p>The way I would overcome this problem would be to not deploy the native image in lower environments like dev. We can just as easily run the code with Amazon’s JRE. It’s no issue at all if we face cold starts in dev, so we need not deploy a native image there. I would however recommend using the native image in QA + TEST environments. You have to be careful about letting your non-prod environments become different from your production environments. It’s very possible that your code would behave one way running in the JVM and behave another when built as a native image.</p><p>None of these gotchas and limitations are too major but they are worth noting. When I’ve been tasked to build an application for a business they just want it done as fast as possible with as few bugs. As developers we have to ask ourselves if its really worth creating extra hurdles for ourselves when the outcome is subtle, and might not even be appreciated by the business or end users. How much of an impact adopting Quarkus will make depends on a number of factors such as the nature of the product you are building and the background and experience level of the developers on your team.</p><h4>Conclusions: when I think you should and shouldn’t use Quarkus with Lambda</h4><p>If you have an existing Spring Boot application that you want to move to Lambda, Quarkus with native image may be a good option. This will allow you to overcome the problem of occasionally having very slow response times due to cold starts. When switching from Spring Boot to Quarkus you will have to do a bit of refactoring. Quarkus offers a number of extensions that make it easy to keep a lot of your Spring code as is. Here is a good article about it</p><p><a href="https://developers.redhat.com/blog/2021/02/09/spring-boot-on-quarkus-magic-or-madness/">Spring Boot on Quarkus: Magic or madness? - Red Hat Developer</a></p><p>If you’re going to go in and refactor your application to run on Lambda anyway you should consider if you even need a framework like Spring or Quarkus. It may not be much more effort to just re-wire your app so that each RESTful route+operation combination makes use of its own Lambda function. By doing that you’ll enjoy the following benefits</p><ul><li>each Lambda function is very simple making it easy to understand and debug</li><li>a bug or venerability in one part of your app won’t effect the rest</li><li>you’re cold start times and memory use will improve drastically without having to do any hacks to the AWS Lambda golden path. (By golden path I mean the standard recommend AWS way)</li></ul><p>Here is an example of how you can build a Serverless Java microservice using just the Serverless framework. In my opinion this is the best way to port your application over to serverless, assuming your are willing to undertake the significant refactoring. Simply put the Serverless framework was designed from the ground up to deploy applications on Lambda, Spring and Quarkus were designed with completely different goals and assumptions.</p><p><a href="https://www.serverless.com/blog/how-to-create-a-rest-api-in-java-using-dynamodb-and-serverless">How to create a REST API in Java using DynamoDB and Serverless</a></p><p>The key distinction is that Serverless is not an application framework it’s a devOps framework. It doesn’t add any overhead to booting your application or impose any conventions on how you write your Java code. In this example multiple lambda functions are part of one code base and can be simultaneously deployed and updated with one deploy command.</p><p>If you are starting 100% greenfield I encourage you to even consider using Node over Java. I don’t think that Node is superior to Java, Java probably has more features and is more powerful in a lot of ways. But from my experience building on Lambda, the devSumer experience is smoother and more enjoyable with Node. I also think Node makes more sense for organizations going forward because Node skills are applicable to both front end and back end development. I’ve experienced and also heard about situations where backend or frontend teams have different workloads or move at different paces and end up waiting on one another so developer bandwidth goes un-utilized. It makes more sense to use a language that allows developers to be cross functional and work on any part of the stack.</p><p>I hope this article has informed you of the benefits and tradeoffs of using Quarkus and the native image functionality in the context of Lambda so that you can apply this knowledge in the context of your team and what your are trying to accomplish.</p><h4>Notes on what I deployed</h4><p>Here are the guides I used to deploy each different Lambda runtime flavor in case you want to try yourself.</p><p><strong>node+express:</strong> <a href="https://mechanicalrock.github.io/2020/01/14/serverless-express-api.html">https://mechanicalrock.github.io/2020/01/14/serverless-express-api.html</a></p><p><strong>spring-boot:</strong> <a href="https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot2">https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot2</a></p><p><strong>Quarkus JVM version + native version:</strong> <a href="https://quarkus.io/guides/amazon-lambda-http">https://quarkus.io/guides/amazon-lambda-http</a></p><p>Here is all the code I used to conduct these experiments on gitHub <a href="https://github.com/bmccann36/lambda-runtime-flavors">https://github.com/bmccann36/lambda-runtime-flavors</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=567a0968a971" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Developers, It’s Time To Give AWS Lambda a Try]]></title>
            <link>https://bmccann.medium.com/java-developers-its-time-to-give-aws-lambda-a-try-c265215603a1?source=rss-172af88a378e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c265215603a1</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Brian McCann]]></dc:creator>
            <pubDate>Tue, 20 Oct 2020 10:49:52 GMT</pubDate>
            <atom:updated>2020-10-20T10:49:52.687Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QKhK5tmrzfr3LqtnbHvr3A.png" /><figcaption>cartoon by Kate Nielsen <a href="https://www.katenielsen.com/">https://www.katenielsen.com/</a></figcaption></figure><p><em>This is the first post of more to come</em></p><p>Everyone has their own definition of what <em>serverless</em> is, here is mine:</p><p><em>Serverless is just the logical next step in the evolution of computers and software following along the trend of adding more and more abstraction on top of the low level processes that actually make hardware and software run. For example it used to be common for programmers to have to allocate and manage memory usage in programs, now most popular languages do it automatically for us. Today it’s common for people to allocate and set up server environments or Kubernetes clusters to run their programs, serverless just means this happens automatically without programmers or operations people thinking about it.</em></p><p>AWS Lambda is the cornerstone of AWS’s serverless product offerings. It offers us <strong>functions as a service, </strong>or in other words, it allows us to run arbitrary bits of code on demand. Initially it had limited use cases and limited capability. People used it for simple background tasks like encoding images or sending notifications. These days people use it for all sorts of compute tasks. We’re getting close to the point that Lambda can do everything that our old mental model of “server-full” computing is capable of. On top of that it often scales up and down better and costs us less. Now that it’s possible to integrate with Elastic File System people are even using fleets of Lambdas as a distributed supercomputer for machine learning.</p><p>Spring Boot is a common way to build microservices with Java, our end goal in this series will be to get an existing RESTful backend web service implemented in Spring Boot running on AWS Lambda. If you’re starting greenfield on a project I wouldn’t necessarily recommend using a framework like Spring Boot because it is not needed in a Serverless environment and actually creates some difficulty. However, I think it’s a good exercise for this series since it will teach you about some of the limitations of Lambda and how the way Lambda executes code is fundamentally different than how our code would run as a traditional long running server process. Once you understand these limitations and differences you’ll be well equipped to make a decision yourself. This post is geared toward Java programmers who are interested in serverless computing, but may be new to AWS Lambda.</p><p>I aim to show that migrating an existing Spring Boot application to a serverless environment may not be as tough as you think, and can offer benefits over the standard “on a server” way. Here is some criteria with which we can evaluate success and decide if its worth doing:</p><ul><li><strong>Performance:</strong> Can it scale? Can it handle lots of concurrent requests?</li><li><strong>Cost:</strong> What kind of cloud bill to expect?</li><li><strong>SDLC:</strong> What is the developer experience? Can it help us be “agile” and adapt to changing requirements quickly?</li><li><strong>Level of effort: </strong>How long does it take to re-tool an existing app? Can we use the skills and workflow we already have?</li></ul><p>This is a lot to talk about and I tend to be pretty detailed so we better break it up into a few posts. This series is the result of me experimenting with Java, AWS Lambda, Spring Boot, and Quarkus (which I’ll talk about in a different post). This post will be all theoretical, I will not get into the mechanics of actually writing code. I plan to dive deep and walk you through the steps in later posts. Here is what you can expect in this post and later posts to come in this series:</p><p><strong>Part 1</strong> (this post)</p><ul><li>What is the point of AWS Lambda, what makes it serverless?</li><li>Should you consider using Spring Boot on Lambda?</li></ul><p><strong>Later Posts</strong></p><ul><li>The basics of writing Java for AWS Lambda with help from the Serverless Framework</li><li>Running a Spring Boot app in a Lambda function. How to optimize performance + deal with cold starts.</li><li>Using Quarkus instead of Spring Boot for best performance and developer experience</li></ul><h3>Spring Boot on Lambda, is it even a good idea?</h3><p>There was a time where I would have answered no to this question. I also used to cringe at the idea of people putting a Node/Express.js application on Lambda. In a nutshell if you’re adding a framework like Spring Boot you’re kind of missing the point of Lambda and not taking full advantage of working in a serverless environment. I’ve since changed my tune since I think it’s ok for people to use tools they already know where possible since overhauling an entire tech stack at once is almost never practical. On top of that, both advances to the Lambda Service, and cool solutions built by clever developers have actually made lifting and shifting a Java or Node microservice to Lambda a fine idea. Both Spring Boot and Express are backend frameworks that were designed to work this way:</p><ol><li><em>Develop your code (and build if its java)</em></li><li><em>Put the deployment package on a server (or container)</em></li><li><em>Start the app and leave it running so it can respond to http requests</em></li></ol><p>AWS Lambda is not a physical or virtual server the way EC2 is. Similar to EC2, the Lambda service falls under the category of on demand compute but it gives us an even higher level of abstraction than EC2 does. Another important distinction is that we don’t tell a Lambda function to “<strong>start running</strong>” when we deploy it. It can be really tough to pin down exactly what “Serverless” means but one key differentiator is that when we deploy traditional workloads that respond to requests, our last step of the deployment process is to start our application running. Serverless doesn’t work like that. AWS Lambda is kind of like a car in that we wouldn’t buy a car, turn it on, and leave it running for years. We start it when we need to go somewhere and turn it off when we arrive (after we’ve invoked it 🤓 ). Actually, a more accurate analogy would be to compare a Lambda function to a modern fuel efficient car that implicitly turns itself off and on. I’ve always owned old crappy cars but I’ve driven newer ones that turn off at stop lights, and back on again when you put your foot on the gas. AWS Lambda works kind of the same way. It will turn off completely and start again many times over the course of an hour or day based on what you ask it to do.</p><p>As a developer when we build for Lambda, our process is like this:</p><ol><li><em>Develop your code (and build it if it’s java).</em></li><li><em>Give criteria to Lambda describing how and when you want it </em><strong><em>invoked </em></strong><em>(foot on gas pedal, foot off gas pedal).</em></li></ol><p>** Some example criteria we could provide to the Lambda service telling it when we want our code to run:</p><ul><li>whenever someone calls /thisEndpoint (API Gateway trigger)</li><li>whenever <em>this</em> database table changes (DynamoDB stream trigger)</li><li>whenever <em>someone uses</em> my Alexa app (Alexa skill trigger)</li></ul><p>As bulleted above, a fun fact you may not know is that most Alexa skills are powered by AWS Lambda. When you talk to an Alexa, the compute environment that processes your request is either a Lambda environment that has only been around a few minutes or one that was <strong>brought into being by your words </strong>🤯. The technology that makes AWS Lambda work was engineered to help Amazon operate at the scale and speed that they do. Amazon / AWS innovates technological solutions that are necessary for them to do business, and they make money again when they provide that technology as a service that implementors like us can use.</p><p>AWS lets Alexa skill builders host their skill’s code right on the AWS platform as Lambda functions. There are roughly 100,000 Alexa skills. AWS isn’t going to pay its dev-ops team to keep 100,000 servers running or even 100,000 containers. Instead, AWS came up with the genius solution of Lambda, which allows the user to run their application logic in a temporary runtime environment. When someone wants to use an Alexa skill the runtime will be provisioned in milliseconds and de-commissioned quickly after. You can think of the Lambda service as an infinite amount of lightweight micro servers that <strong>only run one application</strong> each, with millions starting up and shutting down every second. I should note that AWS was not the first to come up with this concept, they were just able to engineer it in a way that is much faster, more user friendly, and cheaper than predecessors. This was no small engineering feat, if you’re curious to hear about it check out <a href="https://lnns.co/qb6S0iwPo1K/445">this podcast at the 7:20 mark</a>.</p><p>I got sidetracked there, but what I meant to get across is that Lambda is completely unconcerned and decoupled from the job of listening for http requests and responding to them or even using the http protocol. For the nitpickers out there, yes there is http involved but as a user of the service you don’t worry about any of the details of it. I could run this javascript code on my computer to invoke my Lambda</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2f7d0b7a44d901d1a64bc3931ab7b6f/href">https://medium.com/media/e2f7d0b7a44d901d1a64bc3931ab7b6f/href</a></iframe><p>I can invoke a Lambda from my computer’s terminal too.</p><pre>AWS lambda invoke \ <br>--function-name my-function \ <br>--payload &#39;{ &quot;name&quot;: &quot;Bob&quot; }&#39; \ <br>response.json</pre><p>I can also invoke my lambda via a REST API call if I connect it with an API gateway.</p><p><a href="https://yvyfo4mmd0.execute-api.us-east-1.amazonaws.com/dev/MYROUTE">https://yvygb4mmd0.execute-api.us-east-1.amazonAWS.com/dev/&lt;MYROUTE</a>&gt;</p><h3>So what’s wrong with using Express.js or Spring Boot?</h3><p>There is nothing wrong with it, it’s just that it’s a bit redundant to use one of these frameworks with Lambda. Lambda already provides many nice interfaces we can use to interact with it, therefore it is not necessary to add a framework whose core purpose is to help you expose a REST interface that interacts with backend code. The most common and probably simplest way to build a RESTful backend with Lambda is to use AWS API gateway. There is nothing stopping you from hooking a Lambda function up to another gateway product like Apigee, IBM API connect, or your own homespun gateway. In most scenarios AWS API gateway takes the responsibility of staying turned on and “<strong>always listening</strong>”. The client who wants to use our REST API calls API gateway and API gateway triggers our lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AMYsANbs_j6FIyBF2TsoqA.png" /></figure><p>Here is another analogy that may be helpful. Small towns have volunteer fire departments. A firefighter might be home sleeping and get woken up if he or she is on call to respond to fires. If I live in the town and my house catches fire, I don’t call each firefighter individually, I call 911. The 911 line is manned by a “dispatcher” who is awake and waiting at the phone and who also has the capability to alert all the volunteer firefighters at once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*Yn7_aYk9_yDF4Mu00bUp4g.png" /></figure><p>Similarly we can think of an API gateway as a dispatcher. The dispatcher <strong>decouples the request </strong>to put a fire out from the actual resources that do the fire fighting. The dispatcher may choose not to send the entire volunteer department depending on the severity of the fire. Similarly API gateway can “wake up” as many concurrent Lambda functions as is necessary to handle the amount of traffic.</p><p>Just like the sleeping volunteer firefighters our Lambda code is dormant. It’s only some code sitting in an s3 bucket somewhere. When API gateway needs it to process a request, then and only then will the Lambda service spin up a container, create whatever runtime environment our code runs in (node, JVM, python etc…) and execute the code we’ve given it. The output of the Lambda function will be passed back to API gateway and API gateway will pass it back to the client. When it’s all over, the firefighters will go home and go back to sleep, our Lambda execution environment will cease to exist. Sometime in the future it may be cloned and resurrected but it will have no memory of its past life. For the cloning and resurrection part the firefighter analogy does not run parallel to the lambda scenario :).</p><h3>Serverless framework VS alternatives</h3><p>I am accustomed to using <a href="https://www.serverless.com/">The Serverless Framework</a> which is a popular option for building REST APIs in a serverless way. The Serverless Framework is an open source tool that helps you go beyond just publishing serverless functions to build complete applications. It works with multiple cloud providers as well as open source Serverless solutions such as knative and fn. There are many other ways to work with Lambda but this is what I like to use. All of this content is relevant regardless of what framework (if any) you choose for working with AWS Lambda. You can build REST APIs on Lambda without any framework just like you can build a REST API with just Java and no Spring Boot. The Serverless framework just makes it faster and more straightforward to continuously deploy code and connect Lambda functions to specific REST endpoints in API gateway (and do other things outside of the scope of this post). We can declare an API endpoint, spin up a gateway service, and point it to function code with a few lines of yaml.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7a2d5728f42f5fc4af102cbc62bcb88/href">https://medium.com/media/a7a2d5728f42f5fc4af102cbc62bcb88/href</a></iframe><p>As you can see above, we can tie each rest endpoint to a different Lambda function. If we want to get really granular with our Lambdas we can delegate a different Lambda function to POST, GET, and DELETE respectively all under one resource path. Since we have the ability to do this there isn’t a need for a Controller class with @Post, @Get, and other annotations we would traditionally use in Spring. If we were using Express.js we would do the request routing in one or multiple router files and register them all to a main router. This request routing logic that exists in both Node and Spring is not needed when using the Serverless framework + Lambda.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Be-aRu1e71bT9UWf3zjOQw.png" /><figcaption>we don’t have to do this routing logic when working with AWS Lambda</figcaption></figure><p>If we do want to use a backend framework like Express or Spring Boot, then we won’t use a different lambda handler for different routes and REST operations. Instead we can route all http requests to <strong>one single Lambda </strong>function that handles routing requests to /thispath over /thatpath as well as business logic. If we set up our Lambda this way, we do need to include the standard request routing logic (pictured above) that we are used to, since all requests will be sent to one runtime vs many. In this scenario Spring will be responsible for examining the URL and operation that the client used and routing the request to the corresponding controller method. This pattern is basically the same as how we would do things if we packaged our Spring Boot microservice as a Docker image and ran it on Kubernetes.</p><p><em>Non Lambda Monolith way</em></p><p>POST /book request =&gt; goes to createUser Lambda Function</p><p>GET /book request =&gt; goes to getUser Lambda Function</p><p><em>Lambda Monolith way (Entire app lives in one Lambda Function)</em></p><p>POST /book request =&gt; goes to bookStoreApp Lambda Function</p><p>GET /book request =&gt; goes to <strong>same</strong> bookStoreApp Lambda Function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b5f682191f34895687f95ff667b123b/href">https://medium.com/media/1b5f682191f34895687f95ff667b123b/href</a></iframe><p>At this point this is probably all seeming a bit abstract. In my next post I’ll get in to the mechanics of how we actually author, build, and deploy Lambda functions. To sum up we talked about how the “always listening / always running” model we’re used to differs from how Lambda operates. We also discussed what frameworks like Spring Boot and Express accomplish and questioned if they are really necessary when building a backend on AWS Lambda. In the next post I’ll show the basics of working with the Serverless framework both locally and in the cloud from a Java Developer perspective.</p><p><em>I’m a Developer </em><a href="https://twitter.com/CedrusDigital"><em>@CedrusDigital</em></a><em> who enjoys writing and learning about serverless among other things. Find me on </em><a href="https://www.linkedin.com/in/brianmccann01/"><em>Linkedin</em></a><em> and twitter: </em><a href="https://twitter.com/fun_with_lazers"><em>@fun_with_lazers</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c265215603a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cleaner Microservice Orchestration With Zeebe+Lambda]]></title>
            <link>https://medium.com/swlh/cleaner-microservice-orchestration-with-zeebe-lambda-b8ea673305cc?source=rss-172af88a378e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8ea673305cc</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[mpb]]></category>
            <category><![CDATA[zeebe]]></category>
            <dc:creator><![CDATA[Brian McCann]]></dc:creator>
            <pubDate>Sat, 18 Jul 2020 17:19:56 GMT</pubDate>
            <atom:updated>2020-07-22T01:18:45.100Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post I’ll talk about Zeebe. Zeebe is a source available workflow engine that helps you define, orchestrate, and monitor business processes across microservices. I’ll show you how to quickly get a full application that leverages Zeebe and Lambda running on AWS. I’m piggybacking off a post by the company’s co-founder in which he showed how you can <a href="https://blog.bernd-ruecker.com/orchestrate-aws-lambda-using-camunda-cloud-8d27dc640f69">use Zeebe with Lambda</a>. You may want to start with that one first for a general overview of Zeebe and how it fits in with Serverless, then if you’re interested in quickly getting all the components running on AWS this post will show you how.</p><p>If you embrace AWS Lambda or are considering adopting it you may see Lambda as an alternative to Kubernetes and prefer the simplicity, reliability, and out of the box scaling that the Serverless way offers. I was motivated to write this for that type of developer. For Zeebe to work we need something running all the time so we can’t be fully “serverless”. My concession is to use ECS to bridge the gap. ECS is a simpler and cheaper alternative to Kubernetes when you’re getting started with containers. If you are a serverless first developer you or your organization might not want to take on the overhead of running and learning k8s if almost all your workloads work fine on Lambda anyway. Zeebe is a super powerful tool that allows you to compose your Lambda functions to build arbitrarily complex stateful applications. Today I’ll show how to get up and running quick with Zeebe and Lambda using ECS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jk_WMLZvs42audH8ZHONrA.png" /><figcaption>This is what we’ll make</figcaption></figure><h4>Use Case?</h4><p>In case you don’t know about Zeebe I’ll try to describe what it does by describing a use case. A little while ago I was working on a backend that would allow customers to put a down payment on a vehicle then go pick it up at a dealership. The whole process wasn’t too complicated but did involve 5–6 discreet steps involving external API calls. Any of those steps had a number of potential failure paths and based on the outcome of each step you would want to take a different action. On top of that there are different types of errors. There are errors due to conditions in the physical world like a customer putting their address in wrong and there are technical errors like network outages or a bug in the code. You can imagine how the number of scenarios grows exponentially each time you add a step. General purpose programming languages on their own are great at a lot of things, Orchestrating a complicated sequence of steps is not one of them. Using event driven architecture can help us manage emerging complexity by separating business logic into individual microservices whose isolated behavior is simpler to reason about. What we lose is end to end visibility of the business process, so that debugging is a challenge and refactors are scary. This is where a tool like Zeebe, or its predecessor Camunda can help. These tools let us represent our processes as diagrams that are executable. Here is an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yS-nDo5vX_JtcJOYqCBf-w.png" /></figure><p>One of the main advantages is that our business logic is now organized into manageable and isolated components. In addition, and in my opinion most importantly, this strategy separates the concern of <strong>Orchestration </strong>from everything else. This allows us to write functional style microservice components that are easy to read and refactor. All of our orchestration is managed by a dependable and tested framework, and the orchestration logic is cleanly separated as opposed to peppered throughout our microservices (as tends to happen). The boxes with gears are “service tasks” which means they represent pieces of code external to Zeebe that execute. The process engine (Zeebe) is responsible for executing the instructions and will invoke the code we’ve written where specified. In today’s example the <strong>service tasks </strong>(little boxes with gears ) will be implemented as Lambda functions. There are a lot of other powerful features exposed by BPMN (business process modeling notation), the ones pictured above are just a few.</p><p>We need a way for Zeebe to trigger the Lambda functions because Lambda functions by design are dormant until you trigger them. We will use the code provided by the <a href="https://github.com/zeebe-io/zeebe-lambda-worker">zeebe-lambda-worker</a> to create a link between the orchestrator (Zeebe) and the business logic (Lamba). The worker will listen for events on the Zeebe broker, pick up work tasks as they come in, and forward the payload to Lambda. The <a href="https://blog.bernd-ruecker.com/orchestrate-aws-lambda-using-camunda-cloud-8d27dc640f69">original post</a> covers how all this works. Here is what I’m adding</p><ul><li>How to spin up an ECS cluster and run the zeebe-lambda-worker on it</li><li>How to use an IAM role for authorization instead of AWS credentials</li></ul><p>Here are the steps involved in this walkthrough:</p><ol><li><strong>Get set up with Camunda Cloud</strong></li></ol><ul><li>Sign up for a Free Camunda Cloud trial account</li><li>Launch a Zeebe instance</li></ul><p>2. <strong>Use the Serverless Framework to deploy several Lambda functions and an IAM role</strong></p><p>3. <strong>Get set up on ECS</strong></p><ul><li>Create an ECS cluster using a setup shell script</li><li>Deploy the zeebe-lambda-worker to ECS</li></ul><p>4. <strong>Test that everything works end to end</strong></p><h4>Sign up for Camunda Cloud</h4><p>Camunda and Zeebe are the same company. Zeebe is their newer product and Camunda Cloud is their managed cloud offering which happens to run on the newer Zeebe engine. It’s confusing, I know, probably has something to do with marketing as Camunda is an established and fairly well known brand.</p><p>Getting set up with a development Zeebe instance is fairly straightforward. <a href="https://zeebe.io/blog/2019/09/getting-started-camunda-cloud/">This post from the zeebe blog</a> walks you through the steps. The whole thing is a good read but <strong>you can skip </strong>everything after the create a client part if you just want to get up and running. We’ll need the broker address information and the client information later. Once we’re set up with a free Zeebe instance we can deploy the Serverless framework project.</p><h4>Deploy the serverless project</h4><p><em>prerequisite: </em>You need to have an AWS account + IAM user set up with admin privileges. This is a <a href="https://serverless-stack.com/chapters/create-an-aws-account.html">great guide </a>if you need help.</p><p>clone the repo <a href="https://github.com/bmccann36/trip-booking-saga-serverless">https://github.com/bmccann36/trip-booking-saga-serverless</a></p><p>cd into this directory trip-booking-saga-serverless/functions/aws</p><p>In the serverless.yml file update the region property If you’d like to deploy to a region other than us-east-1.</p><p>I have made barely any changes to this from the original <a href="https://github.com/berndruecker/trip-booking-saga-serverless">original forked repository</a>. I removed the http event triggers from the functions since we won’t need them for this. This will make the project deploy and tear down faster since there are no API gateway resources. I also defined an IAM role that will give our zeebe-lambda-worker (which we have yet to deploy) permission to invoke the Lambda functions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2caa25f07cd75fd1a4c97c1b77251a1/href">https://medium.com/media/a2caa25f07cd75fd1a4c97c1b77251a1/href</a></iframe><p>Run the command sls deploy -v to deploy the Lambda functions (the -v gives you verbose output).</p><h4>Connecting Lambda + Zeebe with ECS</h4><p>The last step to get our demo application working end to end is to deploy the zeebe-lambda-worker. The source code can be found <a href="https://github.com/bmccann36/zeebe-lambda-worker">here</a>. I also forked this from Zeebe and made a small change which was to add support for IAM role authorization. Since our ECS task will assume a role that gives it permission to invoke the Lambda functions it needs to, we do not need to supply AWS credentials to the worker code. I added an if / else statement so that a role will be used if no AWS credentials are supplied. This works because the AWS sdk <a href="https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html">sources credentials hierarchically</a>. The role referred to in this snippet is the one we created earlier when we deployed the Serverless framework project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b73b3c44a372cb40b8a57fa9b560fd59/href">https://medium.com/media/b73b3c44a372cb40b8a57fa9b560fd59/href</a></iframe><p>If you prefer to use accessKey/secretKey make sure those keys are not the same keys you use as an admin user to work with AWS. You should create a role or user with credentials that allow the least permission possible. In this case we only need permission to invoke a few specific Lambda functions.</p><p>I have already packaged the zeebe-worker as a Docker image and pushed to a <a href="https://hub.docker.com/repository/docker/chylomicronman/zeebe-lambda-worker">public repo</a>. The ECS setup which we will get to in a moment will pull this image. If you want you can modify the worker source code and/or build the image yourself and publish to your own repository. You’ll need to package it as a .jar first as it is Java code.</p><p><em>Prerequisite: </em><strong>ecs-cli</strong> installed on your machine. You can get it with <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI_installation.html">aws binary</a> or <a href="https://formulae.brew.sh/formula/amazon-ecs-cli">homebrew</a></p><p>If you run into issues at any point look at the <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-cli-tutorial-ec2.html">AWS walkthrough</a> for reference. I mostly followed the steps outlined there to do this with a few minor modifications. I have chosen to use a launch type of EC2.</p><h4>Fill in some configuration</h4><p>To make it easy to configure your ECS cluster I’ve included some configuration template files, all of which have the word “SAMPLE” in the file name. To use them, cd into zeebe-event-adapter/ in the trip-booking-saga repo. Then copy all the files with the word SAMPLE in front and save them with “SAMPLE” removed from the file name. This will cause them to be ignored by git. I’ve configured the .gitignore to ignore these files so that you or I don’t accidentally commit sensitive credentials to source control. Next, populate the values in each file as outlined below.</p><pre>(file) aws.env <br>AWS_REGION=&lt;FILL IN&gt;</pre><pre>---<br>(file) Camunda.env<br>ZEEBE_CLIENT_CLOUD_CLUSTERID=&lt;FILL IN&gt;<br>ZEEBE_CLIENT_CLOUD_CLIENTID=&lt;FILL IN&gt;<br>ZEEBE_CLIENT_CLOUD_CLIENTSECRET=&lt;FILL IN&gt;</pre><pre>--- <br>(file) ecs-params.yml<br>...<br># modify this line <br>task_role_arn: arn:aws:iam::&lt;YOUR AWS ACCOUNT ID&gt;:role/zeebe-lambda-worker-role<br>...</pre><p>The values we supply in Camunda.env will be used by the zeebe-lambda-worker to connect to the Camunda Cloud Zeebe instance we created in the first step.</p><p>Once we’ve filled in the values in each of these files we’re ready to deploy. I’ve combined all the steps into one bash script so everything can be deployed with one command. Just run the setupEcs.sh script and supply your region as the only argument.</p><p>i.e. bash setupEcs.sh us-east-1</p><p>If you run into problems at any step you may want to try running the commands in the script one by one manually, or refer back to the <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-cli-tutorial-ec2.html">AWS tutorial.</a></p><p><em># note </em>you may get this warning INFO[0010] (service aws) was unable to place a task because no container instance met all of its requirements.Don’t get impatient and kill the process, this just means your infra isn’t quite ready yet, it should resolve on its own.</p><p>If you are used to working with Kubernetes the ECS terms will be confusing. An ECS service is not the same as K8s service at all and has nothing to do with networking. Instead in ECS a service just defines that you want to keep a “task” (which is basically a container with some config attached) running. It’s the same idea as a service you’d set up on a Linux server.</p><h4>Test that it works</h4><ul><li><em>*disclaimer </em>The main purpose of this post is to show how to easily deploy the zeebe-lamba-connector to work with Lambda functions so I won’t cover Zeebe usage much. If you want to learn more about Zeebe check out <a href="https://medium.com/u/41646ef41593">Bernd Rücker</a>’s posts or try the <a href="https://docs.zeebe.io/introduction/quickstart.html">zeebe quickstart</a>.</li></ul><p>Probably the simplest way to deploy and start the workflow is with the Zeebe Modeler tool which you can download <a href="https://github.com/zeebe-io/zeebe-modeler/releases">here </a>. You can also use the command line tool zbctl. Once you have the modeler downloaded, just open the trip-booking.bpmn file (in zeebe/aws directory) in the zeebe modeler. Use the upload and play buttons to upload the workflow to the cluster and start an instance of the process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*P9TTLa4_GLu6SjIeC9eDpw.png" /></figure><p>If the process instance worked successfully end to end you will see the completed instance in the operate console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5gLVRFASNbkrplpbcA4dgQ.png" /></figure><p>If we navigate to ECS, select the service we’ve deployed and click on logs, we can see the successful results from the Lambda functions being passed back and forth through the zeebe-lambda-worker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GtSaAb7Kw5x9OOWMak5TVw.png" /></figure><p>Also if we navigate to the Lambda console, select one of the Lambdas involved in our workflow then select monitoring → view logs in cloudWatch, we can see the logs of the Lambda function itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUGEa-6WPzxT-i_FMBG80g.png" /></figure><p><strong>Cleaning up ECS resources when you don’t want them anymore</strong></p><p>take down the service ecs-cli compose service rm — cluster-config zb-cfg</p><p>remove the whole cluster ecs-cli down — force — cluster-config zb-cfg</p><h4>Closing thoughts</h4><p>I am curious to hear what others think about pairing Zeebe with Lambda. Does the combination make sense? What would you do differently? Also for anyone who uses or has used step functions I am curious to hear how this solution compares.</p><p>I had not used ECS much before this and I was pleasantly surprised by how easy it was to provision and use. It seems like they’ve added a lot of features since the last time I looked at it to try to keep pace with Kubernetes. I also like how they use a docker-compose file and docker like commands so you can work with your containers in the cloud more or less the same way you would locally. My one big concern and hesitation on getting good at ECS is that its clearly not the industry standard. Practically as engineers it just makes way more sense to use what everyone else is using because thats what everyone already knows.</p><p>I think Zeebe is a very promising new product, I also think they have their work cut out for them because there are a lot of competitors in this space. Some popular tools that fill the same Niche are Netflix’s Conductor and AWS’s own Step Functions. They face competition not just from competitor frameworks but also homespun orchestration solutions using event buses and other lower level orchestration/choreography tools. I think that a lot of orgs and developers don’t even realize that there is a tool that can help them glue together or orchestrate microservices. In a lot of cases people tend to write this code themselves. In many cases it is a conscious decision because they feel that adding in another Library just creates additional complexity, makes their app harder to understand for new developers, or perhaps even limits what they can do. I totally get that concern as I’ve had these problems myself. For my personal development and collaboration style I think Zeebe makes a lot of sense for a broad range of tech problems.</p><p>I hear about a lot of people reaching for Kafka to achieve EDA. I have nothing against Kafka and I think it is a technically impressive piece of engineering. An experienced dev can probably get up and running with it in a day but they definitely won’t be using it optimally or even getting benefits from it for a long time because it is so complicated with tons of use case specific config required. Kafka is more low level than Zeebe and therefore applies to a broader range of use cases. However I think that if you are just using Kafka as an event bus to drive a collection of choreographed microservices, Zeebe may offer a simpler and actually more powerful solution. With Kafka things like event replay, retry strategies, and monitoring solutions at a business process level, are capabilities we need to build ourselves. Zeebe is appealing to me because they’ve found a way to generalize these needs. This allows us as developers to simply use their API to endow our apps with these advanced features and ultimately solve a business problem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8ea673305cc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/cleaner-microservice-orchestration-with-zeebe-lambda-b8ea673305cc">Cleaner Microservice Orchestration With Zeebe+Lambda</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>