<?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 Kostas Gkountakos on Medium]]></title>
        <description><![CDATA[Stories by Kostas Gkountakos on Medium]]></description>
        <link>https://medium.com/@kgoudak?source=rss-e230fce359d0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*XZox4s4oxoiqm3IHO71ZjA.jpeg</url>
            <title>Stories by Kostas Gkountakos on Medium</title>
            <link>https://medium.com/@kgoudak?source=rss-e230fce359d0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 15:39:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kgoudak/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[One-click environment creation with Terraform & Ansible in under 10']]></title>
            <link>https://medium.com/on-the-cloud/one-click-environment-creation-with-terraform-ansible-in-under-10-6e8d9284f60?source=rss-e230fce359d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e8d9284f60</guid>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Kostas Gkountakos]]></dc:creator>
            <pubDate>Mon, 20 Apr 2020 13:54:31 GMT</pubDate>
            <atom:updated>2020-04-20T14:17:59.778Z</atom:updated>
            <content:encoded><![CDATA[<h4>Provision and configure an infrastructure in AWS and deploy applications in one go</h4><p>When it comes to managing infrastructure, there are many options out there for provisioning, configuration, orchestration &amp; application deployment, as well as a plethora of technologies and tools someone could use for each of those tasks.</p><p>From the above list, two of the most popular technologies (probably the leading ones right now) that provide the ability to provision and configure infrastructure, are <strong>Terraform</strong> and <strong>Ansible</strong>. Both of them are powerful enough to perform both tasks. At the same time though, each one exceeds in one of them. Terraform is a great tool when it comes to provisioning infrastructure, while Ansible is a excellent choice for orchastrating the configuration of our infra resources.</p><p>In this post, we are going to see how we can combine them, in order to create a new environment, in our case at <strong>AWS</strong>. To make things a bit more interesting, after the creation and during the configuration of our servers, we are going to deploy a Web and a REST API application (we’ll use Ansible for the deployment), just to be able to see an end result after the whole process finishes.</p><h3>Before we get started</h3><p>If you would like to follow along, you need to set up/install a few things first.</p><h4>Install Terraform</h4><p>The installation of Terraform is pretty straight forward. You just need to find the appropriate package for your system, download it, extract it and add the binary’s location to PATH. For more details, you can check this link:</p><p><a href="https://learn.hashicorp.com/terraform/getting-started/install.html">Install Terraform | Terraform - HashiCorp Learn</a></p><h4>Install Ansible</h4><p>There are more than one way to install Ansible, with the official documentation having detailed instructions for each one of them.</p><p><a href="https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html">Installing Ansible - Ansible Community Documentation</a></p><p>Personally, I preferred the option of using pip to do the installation (although following the specific way, will not create the ansible.cfg file, something that doesn’t cause any issues, at least for this demo).</p><h4>Create an AWS Account</h4><p>Finally, you need to either have or create an AWS account, as this is the cloud provider that we’ll be using to create our infrastructure. Instructions on how to do that can be found on the following link:</p><p><a href="https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/">Create and activate an AWS account</a></p><p>You will also have to <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html">create a new key-pair file</a> at the region you want to build the infrastructure.</p><h3>What we will build</h3><p>As mentioned above, in this example we go from resources provisioning, to server configuration and application deployment. From an infrastructure perspective, we’ll try to keep things simple and build a similar stack we created in a previous <a href="https://medium.com/on-the-cloud/aws-write-infrastructure-as-code-using-cloudformation-f416da22c155">post</a> (<em>when we had a look of how to create AWS infra with Cloudformation</em>). The end result will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*vbrobUmwkNvMzNQKIMz0mA.png" /><figcaption>Figure 1: Our AWS infrastructure</figcaption></figure><p>After the creation and configuration of the servers has been completed, we’ll deploy to them, two different applications:</p><ul><li>the <strong>Latest News API: </strong>it will be deployed at the EC2 instances located at our <em>private</em> subnets, and it is a simple API written using Java/Spring Boot. The app is determining the caller’s country based on their IP, and calls <a href="https://newsapi.org/"><strong>News API</strong></a>, a free, JSON-based API to get the news for that specific country.</li><li>and a <strong>Latest</strong> <strong>News website:</strong> it will be deployed at the EC2 instances located at a <em>public</em> subnet. The web page calls our <em>Latest News API</em> to get the data it will display. It consists of a simple HTML5 page and a JS script.</li></ul><blockquote>The reason that we’re placing the web app in the public subnet, is to show the difference on the invocation of Ansible playbooks, depending on the subnet that the EC2 is located.</blockquote><p>The code for the <em>Latest News API</em>, can be found in <a href="https://github.com/kgoudak/latest-news-api">this</a> repository, while the <em>Latest News Website</em> files are included in the <a href="https://github.com/kgoudak/terraform-ansible">repository</a> contaning all the Ansible and Terraform code for this demo.</p><h3>How the whole thing works</h3><p>One of the advantages of using Terraform &amp; Ansible, is that they can invoke each other, so we can fully automate the process at hand and have one big task that we can run with one click.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x4TscxA6uaN3asAreNg6yw.png" /><figcaption>Figure 2: Ansible &amp; Terraform invoking each other in the same flow</figcaption></figure><p>Ansible has a <a href="https://docs.ansible.com/ansible/latest/modules/terraform_module.html">module</a> for Terraform, which we can use in order to provision our resources. On the other hand, although Terraform does not have an explicit provisioner for Ansible (as it has for <strong>Chef</strong> or <strong>Salt</strong>), we can make use of the <a href="https://www.terraform.io/docs/provisioners/remote-exec.html"><strong>remote-exec</strong></a> &amp; <a href="https://www.terraform.io/docs/provisioners/local-exec.html"><strong>local-exec</strong></a> provisioners to invoke our Ansible scripts at the time of server creation.</p><p>In the above diagram, we can visualize such a flow, with Ansible calling Terraform code, which in turn runs a different set of Ansible playbooks to configure our servers.</p><p>To understand this better, let’s start diving into the code and see how each part play their role.</p><h4>Our base Ansible script</h4><p>At the root level of our demo project, we can see the following structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*3kWfDUak96RVmKc2bFrZHw.png" /></figure><p>The <strong>create-staging.yml</strong> file is our base Ansible script, which will run a few tasks locally before it runs the Terraform code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1cc5ba5eaef90764b1d7cc1b7e9dcdc/href">https://medium.com/media/c1cc5ba5eaef90764b1d7cc1b7e9dcdc/href</a></iframe><p>What it’s basically doing, is creating an .ansible.cfg file which we use to point to a custom ssh config file. We do that, because in our demo we want to avoid <strong>StrictHostKeyChecking</strong> when we will be connecting using ssh to our newly created servers, and we don’t want to modify our ~/.ssh/config file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b390decde3cc5286e57d8c0c8eeeefc/href">https://medium.com/media/1b390decde3cc5286e57d8c0c8eeeefc/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7edd58f211d8f0129222f7178ae797fa/href">https://medium.com/media/7edd58f211d8f0129222f7178ae797fa/href</a></iframe><p>The terraform init task is needed in order for the appropriate provider to be downloaded locally (in our case the AWS provider), which will be used by Terraform to provision our resources. The last task is the call to the Terraform module.</p><h4>Our Terraform files</h4><p>There are a few files that we’ll be using in order to run our Terraform code. Those can be found in the terraform folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*zQNcAzm0J03e3G9TIUnc_Q.png" /></figure><p>These are:</p><ol><li>The variables.tf file, which contains some variables. Some of them are already initialized, while others will get their values either from the user when the script will be run (prompt), or from the terraform.tfvars file.</li><li>The outputs.tf which list certain values to be outputted after the completion of the main.tf script.</li><li>The terraform.tfvars file which initializes all of the variables declared at the variables.tf file that the user would be prompted to initialize (in order to fully automate the process).</li><li>The main.tf file, which as the name imples, is our main code file, containing all resource definitions.</li></ol><p>The terraform.tfstate is a file that is produced after the execution of the Terraform code, and in our case is stored locally.</p><h4>The “<strong>variables.tf”</strong> file</h4><p>In our example, <em>variables</em> include the region that the infrastructure will be created at, the VPC CIDR, the private key-pair file name and location, the EC2 family type to be used, etc.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/878f3beda771510e13cd414e5aa014b7/href">https://medium.com/media/878f3beda771510e13cd414e5aa014b7/href</a></iframe><h4>The “outputs.tf” file</h4><p>We’ll use this file to print the DNS name of the Application Load Balancer, as well as the public DNS of the Latest News website app, at the end of our code execution.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3b88a894ff9bada9ef68fbbdc728b5e/href">https://medium.com/media/a3b88a894ff9bada9ef68fbbdc728b5e/href</a></iframe><h4>The “terraform.tfvars” file</h4><p>At this file, we’ll define the region, the IP from which we’ll access the bastion host and the website, as well as the name and location of our private key.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1468ca52907b9829c19fa547441cceb/href">https://medium.com/media/d1468ca52907b9829c19fa547441cceb/href</a></iframe><h4>The “main.tf” file</h4><p>In the beggining of the file, we declare information about the provider to be used, such as its name and optionally the credentials that we’ll use to connect to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/082b37dff0f0a3fa6952052d5ee8ad97/href">https://medium.com/media/082b37dff0f0a3fa6952052d5ee8ad97/href</a></iframe><p>When I run this locally though, I don’t declare the latter, as they’re saved at ~/.aws/credentials file that I have created locally:</p><pre>[default]<br>aws_access_key_id=YKRAXU45ALKEWJWDVQT9<br>aws_secret_access_key=1TRE/p+NIg54MYG32veqxEU4OeGvFMf0hPOO2BXS</pre><p>We then move on with the provisioning of our infrastructure resources, starting from the <strong>VPC</strong> and the <strong>Internet Gateway.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19d7294817d3726955750aff6aa7349d/href">https://medium.com/media/19d7294817d3726955750aff6aa7349d/href</a></iframe><p>We declare our <strong>subnets, </strong>creating 2 in each Availability Zone and using the <a href="https://www.terraform.io/docs/configuration/functions/cidrsubnet.html">cidrsubnet</a> funtion to determine dynamically the subnet’s CIDR.</p><blockquote>The way that the specific function works might be a bit hard to understand, but I found a nice <a href="https://medium.com/@ntwobike/how-cidrsubnet-works-in-terraform-f6ccd8e1838f">article</a> that explains things in more details.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67c346e9076faac03f5d1ca05bef49b8/href">https://medium.com/media/67c346e9076faac03f5d1ca05bef49b8/href</a></iframe><p>We move on with the creation of <strong>Elastic IPs</strong> and <strong>NAT Gateways</strong>…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b45cd4b702502717708d44596d5c7774/href">https://medium.com/media/b45cd4b702502717708d44596d5c7774/href</a></iframe><p>…our <strong>Route Tables</strong> and their <strong>associations</strong> with subnets…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d14e1232eda17b4ec2e578cd5f857b2e/href">https://medium.com/media/d14e1232eda17b4ec2e578cd5f857b2e/href</a></iframe><p>…and our <strong>Security Groups</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/631d8d8e802f80eccb804ea6bbdd946b/href">https://medium.com/media/631d8d8e802f80eccb804ea6bbdd946b/href</a></iframe><p>At this point, we have all needed resources ready in order to start coding our EC2 instances definitions.</p><p>The first one, which will be our bastion host, will be fairly simple as we don’t need to do any configuration after its creation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce9491f7c8216ae25e8f3950336a98c0/href">https://medium.com/media/ce9491f7c8216ae25e8f3950336a98c0/href</a></iframe><p>For the other EC2 instances though (the API and the website ones), we want to invoke the configuration part as soon as the server has been created.</p><p>To do that, we’ll use Terraform’s <strong>local-exec</strong> provisioner, through which we’ll call the appropriate Ansible’s playbooks to be run. The syntax of the ansible-playbook command is a bit different depending on whether our targeted EC2 instances reside at a private or a public subnet.</p><p>Let’s start by examing how this is accomplished for the EC2 instances that we’ll deploy our Latest News API (private subnets).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c518e13fda6f17c6c87dd22957cc7b1/href">https://medium.com/media/5c518e13fda6f17c6c87dd22957cc7b1/href</a></iframe><p>In this case, when we run the ansible-playbook command, we are using the --ssh-common-args and we pass theProxyCommand option, since our instance is behind a jump server (bastion host).</p><p>Terraform will try to run the code inside <em>local-exec</em> at our server, as soon as it has been created. The issue is that at that point, our server won’t be ready to accept ssh connections which are needed in order for Ansible to run. Therefore, local-exec code will exit, and the playbook won’t run.</p><p>For that reason, we delay <em>local-exec</em> execution by adding a <strong>remote-exec</strong> block, which will try to ssh to our remote server in order to perform a task (<em>in our case just echo something</em>). The <em>remote-exec</em> provisioner will keep trying to connect until an ssh connection has been established, giving time to local-exec code block to be executed after everything is ready.</p><blockquote>In case the private key you’re using to connect to your EC2 instances is saved at your ssh-agent, you can remove the -i ${var.private_key_file_path} from the ProxyCommand.</blockquote><p>Note that since we’re using bastion’s host public IP to connect to our private EC2 instances, our server creationdepends_on = [aws_instance.bastion].</p><p>When it comes to configuring our public EC2 instances, the code is pretty much the same, with the main difference being the missing --ssh-common-args option, as this time we can ssh directly to our server using its public IP.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a2e95c5c73a7fd34343bec2a9e61cd2/href">https://medium.com/media/2a2e95c5c73a7fd34343bec2a9e61cd2/href</a></iframe><p>The other difference (which applies in our specific example), is that this time we’re passing --extra-vars to our playbook, which contain the <strong>public DNS name</strong> of the Load Balancer that our website will use to call our API. And in order for that info to be available at this point, we make sure that our instance depends_on = [aws_lb.latest_news_api] .</p><p>After the creation of our EC2 instances, we finally create an <strong>Application Load Balancer</strong> for our <em>Latest News API</em>, the <strong>ALB’s Listeners</strong> and the <strong>Target Group</strong> that it will forward the requests to.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dcf1930e6960226b3a9de3e523724765/href">https://medium.com/media/dcf1930e6960226b3a9de3e523724765/href</a></iframe><h4>Our Ansible playbooks</h4><p>Before we run our code, let’s have a quick look on the Ansible playbooks that are called from our Terraform script. In our ansible folder, we have the backend.yml (for the API) and the frontend.yml (for the website). We also have created a few roles, in order to better structure our code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*xPQoQeULfO7onU7qhHAWaw.png" /></figure><h4>The backend playbook</h4><p>What the playbook for our backend servers does, is simply installing:</p><ul><li>Java 8</li><li>Git (<em>to clone the </em><strong><em>news-api</em></strong><em> repo</em>)</li><li>Maven (<em>to build and install the app</em>)</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9197541c0a208149709b9820024ef20/href">https://medium.com/media/b9197541c0a208149709b9820024ef20/href</a></iframe><p>and then creates the appropriate <strong>systemd unit file</strong>, reloads systemd, and runs the Java app as a service.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/759d2781f20048a4c79c43d1d5826e2b/href">https://medium.com/media/759d2781f20048a4c79c43d1d5826e2b/href</a></iframe><h4>The frontend playbook</h4><p>On the other hand, the playbook for our frontend servers (the website), installs <strong>apache2</strong> web server…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab4cf99267cf154ac57d081dbb8485a8/href">https://medium.com/media/ab4cf99267cf154ac57d081dbb8485a8/href</a></iframe><p>…copies the html, js and css files under its home dir (/var/www/html ), and restarts the web server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e210066dc61817b6908daf19edd75fce/href">https://medium.com/media/e210066dc61817b6908daf19edd75fce/href</a></iframe><h3>Running our code</h3><p>Now that we have seen how our Terraform code is structured and what it does, it’s time to put it to the test. Altough we can just run everything with just one click, by executing our main Ansible script (create-staging.yml), we’ll comment out its last part (where it executes the Terraform code) and run Terraform using its CLI. This way we can have a better look on the logs that Terraform prints during the execution of the code.</p><pre>...<br>- name: init terraform<br>  shell: terraform init<br>  args:<br>    chdir: terraform/</pre><pre># - name: apply terraform script<br>#   terraform:<br>#     project_path: terraform/<br>#     state: present</pre><h4>Running our main Ansible play</h4><p>At our project’s root level, we invoke create-staging.yml (with no inventory passed)</p><pre>$ ansible-playbook create-staging.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*lCDpB2v2EAWAFS1QfKoTgA.png" /></figure><p>Then, we cd to the terraform folder and just before we run the code, we can validate it and see the plan of execution.</p><pre>$ terraform validate<br>$ terraform plan</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*XNQGHcSOyb3yqWDA12V3oA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*EFNs7yykHZErYMCYHYn1cQ.png" /></figure><p>After the plan has been evaluated, you’ll be able to see the resources to be created, changed and deleted, when the code will be executed.</p><p>Finally we run our Terraform code, using</p><pre>$ terraform apply --auto-approve</pre><p>at which point Terraform starts provisioning the resources…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*dU3s4fB-F_eQ7g0JR4q_sQ.png" /></figure><p>…connects to the created instances using the <strong>local-exec</strong> provisioner…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*tabhC7J8DNB3nB0onNzUxA.png" /></figure><p>…runs the appropriate <strong>Ansible</strong> playbooks on the servers…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*3eGOP0Nxuu0Q65JZ8TsHjQ.png" /></figure><p>…and finally displays the values defined in our outputs.tf file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*z-OyuNS1pBqNAKDsLfUIQA.png" /></figure><h4>Checking the end result</h4><p>All scripts have been ran successfully, and it’s now time to check our website. We copy the <strong>news_website_address</strong> from the <em>Outputs</em> list and paste it in a web browser, and…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*xbHakYX5e0Pi0bZUZh87Eg.png" /></figure><p>Voila! It works!! I’m located in Athens, so when I visit the website, I get to see the latest news from various Greek websites. :)</p><h3>Cleaning up</h3><p>After you get to play/test the website, or ssh to the created servers and check that they are configured as expected, don’t forget to destroy the created environment in order not get charged for resources that you’ll no longer be using, by running:</p><pre>$ terraform destroy</pre><p>After all, you can now re-create a new environment with a single click, whenever you need to do so.</p><p>I hope the above demo is helpful, thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e8d9284f60" width="1" height="1" alt=""><hr><p><a href="https://medium.com/on-the-cloud/one-click-environment-creation-with-terraform-ansible-in-under-10-6e8d9284f60">One-click environment creation with Terraform &amp; Ansible in under 10&#39;</a> was originally published in <a href="https://medium.com/on-the-cloud">On The Cloud</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS : Write Infrastructure as Code using Cloudformation]]></title>
            <link>https://medium.com/on-the-cloud/aws-write-infrastructure-as-code-using-cloudformation-f416da22c155?source=rss-e230fce359d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f416da22c155</guid>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloudformation]]></category>
            <dc:creator><![CDATA[Kostas Gkountakos]]></dc:creator>
            <pubDate>Fri, 03 Apr 2020 09:06:53 GMT</pubDate>
            <atom:updated>2020-04-03T09:22:43.476Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS : Write Infrastructure as Code using Cloudformation</h3><p><em>Create a basic infrastucture in AWS using Cloudformation and deploy a highly available simple website.</em></p><p>In this post, we are going to see step-by-step, how we can model and provision an environment in AWS, by defining all the needed infrastructure components using Cloudformation. Our goal is to be able to host a highly available website, which will be served from EC2 instances located in private subnets (for better security).</p><p>In the described example, in order to write our <em>.template</em> file, we will be using the YAML format . Apart from the required <em>Resources</em> section, we will have a look at some of the optional ones, such as <em>Parameters</em>, <em>Conditions</em>, <em>Mappings</em> and <em>Metadata</em>.</p><p>After we finish writing our script and creating our stack, our infrastructure will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*9g5ovrVuHHy5RIS2d9a62w.png" /><figcaption>Design of our infrastructure and resources</figcaption></figure><blockquote>You can view or download the complete script from my <a href="https://github.com/kgoudak/cloudformation-templates/blob/master/basic-infra-ha.template">Github</a> repo.</blockquote><p>Let’s start by defining the <strong>AWSTemplateFormatVersion</strong> and a short <strong>Description</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d56f83eae85c3c2f705b1a80700ac28/href">https://medium.com/media/9d56f83eae85c3c2f705b1a80700ac28/href</a></iframe><h3>Parameters</h3><p>Next, we are going to define a few <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html"><em>Parameters</em></a>, in order to make our script more generic. The AWS users that will run the template, will have to provide values to those parameters, after they upload the <em>.template</em> file.</p><p>We start, by giving the user the option to define a range of IP addresses from which they can access the b<a href="https://docs.aws.amazon.com/quickstart/latest/linux-bastion/architecture.html">astion hosts</a> we will later create. For example, when I run the template, I’m passing my own IP address <em>(172.58.43.122/32).</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/289564262b2ae8f9f79b4d9169dd4f3b/href">https://medium.com/media/289564262b2ae8f9f79b4d9169dd4f3b/href</a></iframe><p>We also define a parameter for the name of the key-pair file that the user will use to connect to all EC2 instances.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5124e44fc10dfea391a151cb0e7fab0/href">https://medium.com/media/b5124e44fc10dfea391a151cb0e7fab0/href</a></iframe><p>We then try to make the creation of the VPC and Subnets a bit more dynamic, by allowing the user to define the VCP CIDR block they want, as well as the number of subnet bits for every created subnet’s CIDR. We will see how these are going to be used when we’ll later create the corresponding components, making use of the <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-cidr.html">Fn::Cidr</a> function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/876243cfc8a8b93ca8d6845eddf245c4/href">https://medium.com/media/876243cfc8a8b93ca8d6845eddf245c4/href</a></iframe><p>At the end of the Parameters section, we’ll give the option to the user to decide whether they want to create the private resources (EC2 instances, NAT Gateways, Elastic IPs, etc), in case someone wants to remain on the free-tier.</p><blockquote>Please note here that enabling the creation of private resources, will incur a very small cost, as AWS charges $0.045/hour as the Price per NAT gateway.</blockquote><p>At the end of the section, we define a list of EC2 instance types that can be used when creating both the bastion hosts as well as the website instances. We have chosen <em>t2.micro</em> as the default value, as we don’t want to get charged for EC2 resource usage.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44940096afbb89cafd9d7471804700bc/href">https://medium.com/media/44940096afbb89cafd9d7471804700bc/href</a></iframe><h3>Conditions</h3><p><a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html"><em>Conditions</em></a> provides us with the flexibility to control the creation of certain resources in our stack. In our example, we’ll just define a condition, that will take into consideration the value that the user will pass to the <strong>PrivateResourcesCreation</strong> parameter declared above.</p><p>The condition will be used as a check when deciding on whether certain parts of our infrastructure should be built or not.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/486a4da28fbd843f9d85b4c99f24124b/href">https://medium.com/media/486a4da28fbd843f9d85b4c99f24124b/href</a></iframe><h3>Mappings</h3><p>What follows is the <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html"><em>Mappings</em></a> section, at which we have all AMI ids for the Amazon Linux 2 image, and based on the region that the stack will be created at, the script will choose the appropriate AMI for the EC2 instances creation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a3905ece263baa17bdcc82576571699/href">https://medium.com/media/0a3905ece263baa17bdcc82576571699/href</a></iframe><h3>Resources</h3><p>This will be the biggest section of our template file (at least in the specific example), as we are going to define each resource needed for our infrastructure, as well as the associations between some of those.</p><p>We’ll try to write the code based on the order that we want our resources to be created, but that doesn’t play any role in the actual event execution sequence. As a helper tool, we can use the <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html"><em>DependsOn</em></a> attribute, in order to ensure that the creation of a specific resource follows another.</p><h4>VPC</h4><p>We start by the VPC, referencing the <strong>VpcCidrBlock</strong> defined in the <em>Parameters</em> section. We also prefix the <em>Name</em> tag with the stack name given by the user.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f7ae88eae6d300216a6e28905c01d6d/href">https://medium.com/media/0f7ae88eae6d300216a6e28905c01d6d/href</a></iframe><p>Next, we define the <em>Internet Gateway</em> and attach it to the <em>VPC</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/538da69720ac8c51b07835972682ec71/href">https://medium.com/media/538da69720ac8c51b07835972682ec71/href</a></iframe><h4>Subnets</h4><p>In order to have high availability for our resources (both for bastion hosts &amp; for our website app), we are going to set up resources in 2 different Availability Zones.</p><p>We’ll therefore create subnets in both AZs. In each one we’ll build one public subnet…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88db8a0f5d197cec1899b6752da9327f/href">https://medium.com/media/88db8a0f5d197cec1899b6752da9327f/href</a></iframe><p>…and if the <strong>CreatePrivateResources</strong> condition (defined above) is true, we’ll also create 1 private subnet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbcadeb586d549f3594d81472205d9e6/href">https://medium.com/media/dbcadeb586d549f3594d81472205d9e6/href</a></iframe><p>At this point, let’s have a closer look on how:</p><ul><li>the Availability Zone that the subnet will reside is determined</li><li>each subnet’s CIDR block gets assigned</li></ul><p>For the first one, things are pretty simple, as we use Cloudformaation’s <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getavailabilityzones.html">Fn::GetAZs</a> which returns an array with all the AZs for the specific region that we are running the template.</p><p>Regarding the subnet’s CIDR assignment, we are using the <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-cidr.html">Fn:Cidr</a> function, which gives us the option to provide:</p><ul><li>an initial CIDR block (in our case that of the VPC)</li><li>the number CIDRs to generate (we’ll calculate one for every subnet)</li><li>the number of subnet bits for the CIDR (e.g. a value of “8” creates a /24 mask)</li></ul><p>If we have decided to hardcode the subnet CIDR values to the script, we would have to calculate the range of IPs (possibly with the help of a tool like <a href="https://www.ipaddressguide.com/cidr">ipaddressguide.com</a>) and assign them to our subnets. More importantly though, in case we needed to run the same script again (let’s say in order to create the same stack, but for a testing environment) and we wanted a different mask value for our subnets, we would have to find all subnets declarations, re-calculate the IP ranges and manually make all changes to the script.</p><p>By giving the option to the user to decide on the VPC CIDR block range, and by using the <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-cidr.html">Fn:Cidr</a> function, we can dynamically produce the appropriate CIDR ranges for our subnets, based on the mask size provided by the user during passing the <em>Parameters</em> values, and also taking into consideration the <em>CreatePrivateResources</em> flag.</p><p>So, let’s assume that we have a VPC with a CIDR block value of <strong>10.10.0.0/20</strong>, therefore a range of IPs from <strong>10.10.0.0 → 10.10.15.255</strong>.</p><pre>Fn::Cidr:<br>    - 10.10.0.0/20<br>    - 2<br>    - 8</pre><pre>(or)</pre><pre>!Cidr: [ 10.10.0.0/20, 2, 8 ]</pre><p>will automatically create for us the next 2 subnets:</p><ul><li>Subnet A: <strong>10.10.0.0/24</strong> (IP range: <strong>10.10.0.0 → 10.10.0.255</strong>)</li><li>Subnet B: <strong>10.10.1.0/24</strong> (IP range: <strong>10.10.1.0 → 10.10.1.255</strong>)</li></ul><p>while</p><pre>!Cidr: [ 10.10.0.0/20, 4, 6 ]</pre><p>will automatically create for us the next 4 subnets:</p><ul><li>Subnet A: <strong>10.10.0.0/26</strong> (IP range: <strong>10.10.0.0 → 10.10.0.63</strong>)</li><li>Subnet B: <strong>10.10.0.64/26</strong> (IP range: <strong>10.10.0.64 → 10.10.0.127</strong>)</li><li>Subnet C: <strong>10.10.0.128/26</strong> (IP range: <strong>10.10.0.128 → 10.10.0.191</strong>)</li><li>Subnet D: <strong>10.10.0.192/26</strong> (IP range: <strong>10.10.0.192 → 10.10.0.255</strong>)</li></ul><p>We could make things even more dynamic, by giving to the user the option to set the number of subnets they want to create (let’s say a <em>Parameter</em> attribute named <em>NumberOfSubnets</em>) and have the <em>CidrBlock</em> key looking like this:</p><pre>CidrBlock: !Select<br>    - 2<br>    - Fn::Cidr:<br>        - !Ref VpcCidrBlock<br>        - !Ref NumberOfSubnets<br>        - !Ref IPv4MaskSize</pre><h4>NAT Gateways &amp; Elastic IPs</h4><p>In order for the EC2 instances in our private subnets to have access to the internet, we have to create 2 NAT Gateways (1 in each AZ) and the Elastic IPs that will be allocated to them.</p><blockquote>Please note here, that our NAT Gateways will have to reside on our public subnets.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b62b8c27ae7e88c198032f300cea954/href">https://medium.com/media/6b62b8c27ae7e88c198032f300cea954/href</a></iframe><h4>Route Tables</h4><p>We move on by creating Route Tables, adding the appropriate routes to them and finally associate our subnets to each table.</p><p>Initially, we create a public route table and we add a route to the Internet Gateway in case a resource wants to access the internet (0.0.0.0/0).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15c062bac87f9d0db13dea66912e204d/href">https://medium.com/media/15c062bac87f9d0db13dea66912e204d/href</a></iframe><p>We then create 2 private route tables, as we have 2 NAT Gateways and we cannot have a single route (in our case to 0.0.0.0/0) in a route table pointing to more than one NAT Gateways.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d64b64b2388f7ae2df73b37f65fe20a6/href">https://medium.com/media/d64b64b2388f7ae2df73b37f65fe20a6/href</a></iframe><p>Finally, we associate our 2 public subnets to our public route table (so that all of their resources access the internet though the IGW) and each of our 2 private subnets to a private route table (so that their resources access the internet though the NAT GW).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3793966788319a2e0e044b8fdfe972a/href">https://medium.com/media/c3793966788319a2e0e044b8fdfe972a/href</a></iframe><h4>Network Control Access Lists (NACLs)</h4><p>Our next step is to create 2 NACLs for our infrastructure. We are going to keep things simple and have both NACL’s Engress &amp; Ingress rules to <em>ALLOW ALL</em>, but we’ll have the definitions there in case we want to change things in the future.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac31dba8146226016807b05a50ea7ee3/href">https://medium.com/media/ac31dba8146226016807b05a50ea7ee3/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/191fab7569ff9a3b98ba45b67da27f8c/href">https://medium.com/media/191fab7569ff9a3b98ba45b67da27f8c/href</a></iframe><p>We then associate our public subnets to our public NACL and the private subnets to the private one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5aec777795e7f5d303c1242f30c57d7/href">https://medium.com/media/b5aec777795e7f5d303c1242f30c57d7/href</a></iframe><h4>Security Groups</h4><p>The last thing we need to define before we move on with the creation of our EC2 instances, is the security groups that those instances will be using.</p><p>We will define one security group for the EC2 instances that will deployed in our public subnets, and another one for the ones deployed at the private ones.</p><p>Let’s see how we will configure our public security group. We need to be able to SSH into our bastion hosts from the <em>SSHLocation </em>(declared in Parameters), ping them, and we also need to allow HTTP access for the <em>Application Load Balancer</em> we’ll create later on. From within the servers, there will be no limitations as they will be able to use all protocols and ports when reaching the internet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fce3a22fc26e81a7f4d884a84aaa324e/href">https://medium.com/media/fce3a22fc26e81a7f4d884a84aaa324e/href</a></iframe><p>The setup for the private security group will be quite similar, with the only deifference being that CIDR IP range that will accept traffic from, will be the CIDR of the VPC.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d471803f89dee2ef002fa2302f09db8/href">https://medium.com/media/5d471803f89dee2ef002fa2302f09db8/href</a></iframe><h4>EC2 Instances : Bastion Hosts</h4><p>Since we’re building a high availability infrastructure, we’ll create one EC2 instance that will act as a bastion host, in each AZ. The AMI that will be used for those instances to be created, will be retrieved from the predefined <strong>AWSRegionLinux2AMI</strong> list in the <em>Mappings</em> section. Finally, its type will be selected as a value to the <strong>InstanceType</strong> <em>Parameters</em> attribute.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c62ac99801a8260bea2df15ad5a7577/href">https://medium.com/media/2c62ac99801a8260bea2df15ad5a7577/href</a></iframe><h4>EC2 Instances : Website</h4><p>We have finally reached the point where we will declare the definition for our EC2 website instances. Once again, we’ll create one instance in every AZ.</p><p>For our website we will install an Apache HTTP server, which will host a simple web page, that will display a <em>“Hello”</em> message mentioning the hostname of the server and the availability zone that the EC2 is hosted at.</p><p>In order to set everything up along with the creation of our EC2 instances, we’ll provide all the necessary information in the <strong><em>UserData</em></strong> section of our definition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bcfcc7dd4d51d0a96fc22631abd48137/href">https://medium.com/media/bcfcc7dd4d51d0a96fc22631abd48137/href</a></iframe><p>At this point, we have a complete script that we could run and allow us to SSH into our servers, and check that everything have been set up they way they should. For example, we could SSH into our bastion hosts and make a cURL request to any of our website instances to validate the installation of the web server and the correctness of the returned response.</p><p>But, we couldn’t access the content of those websites publicly from a browser.</p><h4>Application Load Balancer</h4><p>For that reason, and also because we want to expose a single endpoint to our end users to access our website servers (and of course balance the load between the instances), we are going to create an <em>Application Load Balancer</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd1f94c9e50d4e8d40a8d07ab8f4f080/href">https://medium.com/media/fd1f94c9e50d4e8d40a8d07ab8f4f080/href</a></iframe><p>We then have to define a <strong>TargetGroup</strong> and provide information about its target types (in our case they are going to be EC2 instances), as well as the health checks that it will do to those types.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f4866c334ca4360c7c5f509c2f5fcb9/href">https://medium.com/media/1f4866c334ca4360c7c5f509c2f5fcb9/href</a></iframe><p>Finally, we have to associate those two, by adding a listener to the <em>Load Balancer</em>, forwarding all requests to the created <em>Target Group</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20f88220650f70bfe0b2ed53872f4c33/href">https://medium.com/media/20f88220650f70bfe0b2ed53872f4c33/href</a></iframe><p>With the addition of the ALB, we can access the content of our application by hitting the DNS name assigned to the ALB, and the load would be balanced between the 2 servers in a round robin mode (we’ll see how we can do this later on).</p><h4>Auto Scaling Groups</h4><p>We want to take things a bit further though, and create an <em>AutoScalingGroup</em> that will be responsible for scaling out/in our application horizontally, based on the criteria that we’ll define.</p><p>To do that, we first need to create a definition for the <strong>LaunchConfiguration</strong> that the ASG will be using to create the instances.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11fd87147e85925598ec76b9c81467b8/href">https://medium.com/media/11fd87147e85925598ec76b9c81467b8/href</a></iframe><p>We’ll then write the code for the <em>AutoScalingGroup</em> itself and have it use the above <em>LaunchConfiguration</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae7e5a9a45b0bf7d6eefd86fbf22079f/href">https://medium.com/media/ae7e5a9a45b0bf7d6eefd86fbf22079f/href</a></iframe><p>As a next step, we define a <em>Scaling Policy</em> for our ASG, which will describe the criteria based on which we want our EC2 instances to scale in or out.</p><p>In the specific example, we’ll be using a <strong>TargetTrackingScaling</strong> policy, checking the number of requests our ALB will be receiving (per target), and scale our target group based on that metric.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/324a24cb87634cc5bc163e3bf441b95e/href">https://medium.com/media/324a24cb87634cc5bc163e3bf441b95e/href</a></iframe><blockquote>Note here, that since from this point onwards the ASG will be responsible for managing the number of website EC2 instances, we no longer need the <strong>WebsiteA</strong> &amp; <strong>WebsiteB</strong> resources defined a bit earlier, and you can either comment them out or completely delete them.</blockquote><blockquote>If you don’t, by the time that the template finishes running, you will see both them plus the 2 new instances that the ASG will create (it does not count already created instances when checking the <strong>DesiredSize</strong> attribute).</blockquote><h3>Metadata</h3><p>A last small piece that we will add to our template file, is the <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html"><em>Metadata</em></a> section. In this part we’ll just group the <em>Parameters</em> we’ve defined in the beggining of our script, so that they are displayed in a specific way on the user interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ff518c26ff2a86fda62bc509921e0ab/href">https://medium.com/media/1ff518c26ff2a86fda62bc509921e0ab/href</a></iframe><p>That’s it, we’re done!</p><p>It is now time to run the above file, monitor the sequence of events as resources are created, and test that everything will be working as expected.</p><h3>Creating the infrastructure</h3><p>Before we run the file we’ve created, we need to decide on the region that we want to create our infrastructure. In this example we’ll use <strong><em>N. Virginia (us-east-1)</em></strong>.</p><h4>Create a KeyPair</h4><p>Our first step is to create <em>key-pair</em> file that we will use, in order to ssh into our EC2 instances. This needs to be done before we start running the file, as its value should be passed in the <em>Parameters</em> section.</p><p>To do that, we need to:</p><ol><li>Go to the <strong>EC2 service page</strong></li><li>Click on <strong>Key Pairs</strong> and then on <strong>Create key pair</strong></li><li>Enter an easy to remember <strong>key pair name</strong> and click <strong>Create</strong></li></ol><blockquote>You need to remember the folder that this key pair file was saved locally, and change the permissions of the file depending on whether you are using Linux, Mac OS or Windows.</blockquote><h4>Run the template file</h4><p>After we finish with the creation of the key pair file, we need to follow the steps described below:</p><ol><li>Go to the <strong>CloudFormation service page</strong></li><li>Click on <strong>Create Stack</strong></li><li>Under <strong>“Specify Template”</strong>, select <strong>“Upload a template file”</strong>, choose the file we’ve created and click <strong>Next</strong></li><li>Enter a name for the stack to be created</li><li>In the <strong>Parameters</strong> section, select the key-pair file previously created and give a value to the SSHLocation field (we can leave the rest with their default values, or change them if we want) and click <strong>Next</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*O58KFIup62LGY1jT4kyWRA.png" /></figure><p>6. We leave <strong>“Configure Stack Options”</strong> and <strong>“Advanced Options”</strong> as is and we click <strong>Next</strong></p><p>7. Finally, we review all information regarding the stack, and click <strong>Create Stack</strong></p><p>We will be redirected to the <em>Stacks</em> page, from which we can monitor the resources being created, the events that trigger their creation, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8lv1OqSa2ngqje0yV1KeOg.png" /><figcaption>We can see the order of events that create our infrastructure’s resources</figcaption></figure><p>After the completion of our stack, we can navigate to different screens and check the resources created (<em>EC2, VPC, Security Groups, Route Tables, etc</em>).</p><p>One thing we want to do, is to go to the <em>Load Balancers</em> section (of the EC2 page), and copy the <strong>DNS name</strong> of the created LB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*61yzZckNd8y1XprJr4SF1A.png" /></figure><p>We can then open a web browser and paste that DNS name and we’ll be able to see the response from one of our web servers!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9zDtqwCq7OiaDihRpzXgxQ.png" /></figure><p>If we keep refreshing the page, we’re able to see that each time we are getting a response from a different web server that is located behind our load balancer.</p><h3>Cleaning up</h3><p>After we examine and we play around with the created infrastructure, we need to always remember to <strong>DELETE</strong> our stack, in order to destroy all created resources! This way we avoid getting charged for resources that we’ll no longer be using.</p><p>Hope the above example is helpful, thank you reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f416da22c155" width="1" height="1" alt=""><hr><p><a href="https://medium.com/on-the-cloud/aws-write-infrastructure-as-code-using-cloudformation-f416da22c155">AWS : Write Infrastructure as Code using Cloudformation</a> was originally published in <a href="https://medium.com/on-the-cloud">On The Cloud</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>