<?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 Sagi Eliyahu on Medium]]></title>
        <description><![CDATA[Stories by Sagi Eliyahu on Medium]]></description>
        <link>https://medium.com/@sagieliyahu_46946?source=rss-8f419a643c1e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*A7J7gnN_CJpNb4HdqdwhdQ.jpeg</url>
            <title>Stories by Sagi Eliyahu on Medium</title>
            <link>https://medium.com/@sagieliyahu_46946?source=rss-8f419a643c1e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 00:02:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sagieliyahu_46946/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[Unleash Your Serverless Superpowers Using AWS CDK]]></title>
            <link>https://medium.com/cyberark-engineering/unleash-your-serverless-superpowers-using-aws-cdk-cd0fdf2434d7?source=rss-8f419a643c1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd0fdf2434d7</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws-cdk]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Sagi Eliyahu]]></dc:creator>
            <pubDate>Thu, 18 Jun 2020 09:53:11 GMT</pubDate>
            <atom:updated>2020-06-18T09:53:11.946Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pi1PLTFJmLQ6D-10kHgzzQ.jpeg" /></figure><p>Are you still maintaining complicated YAML files for your serverless application?<br> <br> Whether you’re currently researching various serverless development frameworks for a new application or trying to improve your existing serverless deployment strategy, this post is for you.</p><p>There’s a real alternative to the declarative approach for handling serverless deployment (utilized by AWS SAM and Serverless Framework), which we will demonstrate using AWS CDK. In this post we’ll cover:</p><ul><li>The major downsides of the more common, declarative approach for dealing with serverless deployments.</li><li>Show a real-life example, utilizing AWS Step Functions, to illustrate the power of AWS CDK and the imperative approach. We’ll be using Python despite the fact that CDK for Python is not currently well documented.</li></ul><p>It’s important to note that while we will be focusing on AWS serverless platform, but the general concept can be applied to any serverless platform.</p><h3>Downsides of the Declarative Approach</h3><p>Serverless technology is in the process of completely transforming the way we think about software development. Unfortunately, during this transformation period we are faced with unique challenges which arise from its very nature. One of the bigger challenges is the increase of deployment complexity. And it is a big challenge — especially when increasingly complex systems are being developed using serverless technology.</p><p>Thing is, when we’re maintaining our deployment by following a declarative approach, we are constantly violating some of the most basic and timeless software development principles:</p><ul><li>We want to avoid repeating ourselves (aka the DRY principle), but we can’t resolve to even the simplest of practices, such as extracting a method.</li><li>We can’t even start talking about creating abstract constructs within our deployment code by introducing classes etc.</li><li>SOLID principles (such as the open-close principle) are not even in our realm, since our YAML file is not even a real code</li></ul><p>What we’re actually practicing is “Infrastructure as Configuration”, which is maintained as code, rather than actual “Infrastructure as Code”.</p><p>Don’t get me wrong, if your serverless deployment is simple enough (and is not about to change anytime soon), or when your deployment configuration is maintained by non-programmers, the declarative approach will probably work just fine.</p><p>However, when deployment complexity starts raising, you will probably want to look for a better approach. Here are a few examples:</p><p>When your dev team is spending more time automating the deployment of resources in the cloud, than writing business logic code.</p><p>When you start incorporating Serverless Framework plugins, such as the popular <a href="https://www.npmjs.com/package/serverless-plugin-ifelse">“If-Else” plugin</a>.</p><p>All those issues relate to a single quality attribute, which is flexibility. That’s where the imperative approach and AWS CDK come into play.</p><h3>A Real World Example</h3><p>Suppose we wanted to build a system for managing various ops workflows on a production system, like running a backup operation or executing system tests. Let’s also assume that in order to start a backup operation we will integrate with an external backup system. So, we come up with the following design, which implements the <a href="https://docs.aws.amazon.com/step-functions/latest/dg/callback-task-sample-sqs.html">callback pattern</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*-zOZqdTfgT9y7w4qkwnBuA.png" /></figure><p>We make a few adjustments to the original example implementation of the callback pattern as it described by AWS (note that you can skip this design notes section, and still benefit from this post):</p><ul><li>We design the state machine to handle backup operations exclusively, rather than creating a generic state machine for handling all sorts of tasks. The trade-off is to have better visibility of the system by having separate state machines for each type of operation. That way, we can easily inspect state machine executions (which is a great benefit of Step Functions), will benefit from better visibility of usage metrics for each type of operation, and have easier time analyzing AWS costs more granularly.</li><li>We invoke a Lambda function directly from the state machine, instead of using SQS trigger (in which SQS queue serves as an event source for the Lambda function). With this specific use case we don’t require the capabilities which are offered by SQS: there is no point buffering messages on very low throughput (no risk of throttling errors on lambda executions). Also, there is no need for the added resiliency which SQS offers, since we assume that the handling of failed requests is the responsibility of the invoker of the state machine execution.</li><li>We add an additional step — the “Fail” step — in order to make sure that when the backup operation fails, the entire state machine execution will fail as well. It not only makes more sense, but it will also give us the added visibility when we troubleshoot failed executions.</li></ul><p>Let’s look at how we would develop the deployment of this state machine using AWS CDK:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e0585b982889e8167886b1e7072fa69/href">https://medium.com/media/4e0585b982889e8167886b1e7072fa69/href</a></iframe><p>To mix things up, let’s also assume we want to schedule our backup workflow to run nightly. We can do that easily using CDK to deploy a CloudWatch Events rule that will trigger our state machine:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/288d85c4a1f30fe67d8aeb1a7fedaab4/href">https://medium.com/media/288d85c4a1f30fe67d8aeb1a7fedaab4/href</a></iframe><p>When we want to implement additional ops workflows into our system, we create additional state machines - repeating the same callback pattern. For example, a system-test workflow would look very similar to the backup workflow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*yRNW9OrW_N7DZhVBDgfDXQ.png" /></figure><p>Since those are two distinct state machines (“Start Backup” state machine and “System Test” state machine). When we deploy them using a tool that applies a declarative approach, <strong>we would need to duplicate and adjust existing sections within the YAML configuration file</strong> for each additional workflow we introduce into the system.</p><p>With that in mind, let’s look at how we can utilize AWS CDK Custom Constructs to create an abstraction, which we would be able to reuse each time we want to deploy an additional state machine.</p><p>What we currently identify as the elements which varies between those state machines are the following:</p><ul><li>The state machine name</li><li>The lambda function of the actual task</li><li>Whether of not we want to trigger the state machine nightly</li><li>The configured timeout of the state machine execution</li></ul><p>With that in mind, we create a helper class to represent the construct settings:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9344bd74a6f04fef9d158f882e407959/href">https://medium.com/media/9344bd74a6f04fef9d158f882e407959/href</a></iframe><p>Now let’s create our generic workflows construct, which will be configured according to the injected settings:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c46c09fd72fe0a384e00dd3de77ecbe/href">https://medium.com/media/2c46c09fd72fe0a384e00dd3de77ecbe/href</a></iframe><p>So all we have to do, in order to add additional state machines, is to instantiate workflow construct objects.</p><p>For example, in order to deploy the system test state machine, we can do that by simply adding the following lines of code to our stack:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/065cce3b53cc78c2aee3e32bf41c689a/href">https://medium.com/media/065cce3b53cc78c2aee3e32bf41c689a/href</a></iframe><p>Assuming we want to deploy a new ops workflow for rotating passwords and configure it to run nightly, we just add the following lines of code to the stack:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4c316c9e67840646d1140548c8a17fe/href">https://medium.com/media/c4c316c9e67840646d1140548c8a17fe/href</a></iframe><p>We can theoretically evolve our design to enhance our custom construct and create whatever our hearts desire!</p><p>Try to do that with a declarative approach and YAML files manipulation…</p><p>Let’s reiterate on what we just accomplished:<br>We recognized a pattern within deployment logic and were able to create a generic construct within our deployment code. We were now able to use this construct to generate complicated step functions easily, without rewriting similar deployment code repeatedly.</p><p>This is the power of the imperative approach, and it will greatly enhance your serverless deployment capabilities. <br>With this approach you will be able to improve the maintainability of your deployment code, especially as your serverless applications evolve, and your deployment complexity increases.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd0fdf2434d7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cyberark-engineering/unleash-your-serverless-superpowers-using-aws-cdk-cd0fdf2434d7">Unleash Your Serverless Superpowers Using AWS CDK</a> was originally published in <a href="https://medium.com/cyberark-engineering">CyberArk Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>