<?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[AWS CDK — Infrastructure as Code - Medium]]></title>
        <description><![CDATA[AWS CDK — Infrastructure as Code - Medium]]></description>
        <link>https://medium.com/aws-cdk-infrastructure-as-code?source=rss----7273dabb9815---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>AWS CDK — Infrastructure as Code - Medium</title>
            <link>https://medium.com/aws-cdk-infrastructure-as-code?source=rss----7273dabb9815---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 15:32:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/aws-cdk-infrastructure-as-code" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AWS CDK — Infrastructure as Code]]></title>
            <link>https://medium.com/aws-cdk-infrastructure-as-code/aws-cdk-infrastructure-as-code-e2a1d9799de0?source=rss----7273dabb9815---4</link>
            <guid isPermaLink="false">https://medium.com/p/e2a1d9799de0</guid>
            <dc:creator><![CDATA[Ramakrishna]]></dc:creator>
            <pubDate>Tue, 17 Dec 2019 04:34:10 GMT</pubDate>
            <atom:updated>2024-03-15T06:59:35.142Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DsFsmi_xuQB5u8K_4QaX5A.jpeg" /></figure><p>In 2019, AWS launched CDK (Cloud Development Kit) framework to model and provision cloud resources using a <strong>programming language</strong>. <br>As per the official document <a href="https://docs.aws.amazon.com/cdk/latest/guide/home.html"><strong>here</strong></a>, the supported programming languages are <strong><em>TypeScript, JavaScript, Python, Java, and C#/.Net.</em></strong></p><p>Now, you might be thinking about how this is different from C<strong><em>loudFormation.</em></strong></p><p>Well, the answer is, <em>w</em>e can provision resources programmatically with CDK while in <em>CloudFormation</em>, we create templates using JSON or YAML file.</p><p>Another point to note here is that this framework provisions cloud resources through <em>CloudFormation</em><strong><em>. </em></strong><em>This means that the code you write using CDK will be converted into CloudFormation template. We will discuss this in detail below</em></p><p>In our project, we used <em>CloudFormation </em>templates for configuring <br>AWS Services <strong><em>API Gateway, Lambda, DynamoDB, S3 etc.<br></em></strong>While writing templates, we realized that the more cloud resources you need, the more cumbersome it becomes as the number of lines increases.<br>It had become very difficult for us to track/modify any changes.<br>Now, this problem has been solved by CDK by giving the flexibility to configure cloud resources in a familiar programming language.</p><p>In this blog, we will discuss more about configuring <strong><em>API Gateway, Lambda, DynamoDB</em></strong> resources using AWS CDK.</p><p>Let’s get started to see how we can use this wonderful framework in developing cloud applications.</p><p><strong>Create a sample CDK project in Python</strong></p><p><em>Follow the AWS documentation </em><a href="https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html"><em>here</em></a><strong><em> </em></strong><em>to get started with CDK.<br></em>After installation, run the below<strong> </strong>command to create a <br>sample CDK project in python</p><blockquote><strong><em>cdk init sample-app — language python</em></strong></blockquote><p><strong>Configure AWS Lambda Function and API Gateway</strong></p><p>To configure any of the AWS Services like API Gateway or Lambda Function etc., we need to use CDK Construct libraries.</p><p><strong>What is a Construct Library?</strong></p><p>Construct Library allows us to bundle up a group of services/resources into reusable components. AWS CDK has construct libraries which are divided into modules, one for each AWS service.<br>For Example, to define an API Gateway , we will need to use an API Gateway Construct Library</p><p>To understand more about construct libraries and CDK project in any supported language, please follow the <a href="https://cdkworkshop.com/">CDK Workshop</a> documentation</p><p><strong>Can we create custom Construct Libraries?<br></strong>yes, we can. For example, when we need to count the number of hits to an API and store the result in dynamodb, we can create this as a construct so that this can be attached to any lambda function as a reusable component.<br>This example is clearly explained <a href="https://cdkworkshop.com/30-python/40-hit-counter.html">here</a> with code samples in the <br>AWS documentation.</p><p><strong>Install AWS Lambda and API Gateway Construct Libraries</strong></p><blockquote>pip install aws-cdk.aws-lambda<br>pip install aws-cdk.aws_apigateway</blockquote><p><em>AWS Lambda and API Gateway configuration code in python with CDK</em></p><p>The below code snippet does the following:</p><ol><li><em>Configures Lambda Function with the handler code from s3 bucket.</em></li><li><em>Creates RestApi and integrates with the Lambda Function</em></li></ol><p><strong><em>Note: This code will not work unless you install Construct Library for each AWS Service you configure</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1a8f7d05e3497cd51ad62f7d01fb254/href">https://medium.com/media/e1a8f7d05e3497cd51ad62f7d01fb254/href</a></iframe><p><strong>Configure Dynamodb table</strong></p><p>Install Construct Library for DynamoDB with the below command</p><blockquote>pip install aws_cdk.aws_dynamodb</blockquote><p>Configure the DynamoDB table with indexes using the below code snippet</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a6ea0e19ccdbe75b6441da382997c58/href">https://medium.com/media/9a6ea0e19ccdbe75b6441da382997c58/href</a></iframe><p>Edit the app.py class from sample project as shown below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4aea7e5ae172beb043fa8620d200e526/href">https://medium.com/media/4aea7e5ae172beb043fa8620d200e526/href</a></iframe><p>Before we run the code, make sure of the following</p><ol><li>MyCDKAPIGateway class must exists in file <strong>hello_stack.py</strong> under the package <strong>hello </strong>in sample project created above</li><li>Keep the DynamoDB table configuration in MyCDKAPIGateway class</li></ol><p>Run the command below to generate<strong> </strong>cloudformation template.</p><blockquote><strong><em>cdk synth </em>hello-cdk-1</strong></blockquote><p><em>Note: Here, we used </em><strong><em>synth</em></strong><em> command to convert cdk app into CloudFormation template</em></p><p>Finally, you can run this template or execute <strong>cdk deploy</strong> command to deploy cdk app into AWS environment. <br>Once execution or deployment is successful, a <em>CloudFormation </em>stack with the list of services(configured using CDK) will be created in the selected region of your AWS environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2a1d9799de0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aws-cdk-infrastructure-as-code/aws-cdk-infrastructure-as-code-e2a1d9799de0">AWS CDK — Infrastructure as Code</a> was originally published in <a href="https://medium.com/aws-cdk-infrastructure-as-code">AWS CDK — Infrastructure as Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>