<?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 Ramakrishna on Medium]]></title>
        <description><![CDATA[Stories by Ramakrishna on Medium]]></description>
        <link>https://medium.com/@Ramakrishna6464?source=rss-416c917cdd7b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*jaybCmWRDLOTIoh82LKzXA.jpeg</url>
            <title>Stories by Ramakrishna on Medium</title>
            <link>https://medium.com/@Ramakrishna6464?source=rss-416c917cdd7b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 15:21:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Ramakrishna6464/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[Python 3.11 — new features and improvements]]></title>
            <link>https://medium.com/@Ramakrishna6464/python-3-11-new-features-and-improvements-e1104c82ed97?source=rss-416c917cdd7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1104c82ed97</guid>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ramakrishna]]></dc:creator>
            <pubDate>Thu, 27 Oct 2022 11:07:02 GMT</pubDate>
            <atom:updated>2022-10-27T11:07:02.860Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python 3.11 — new features and improvements</h3><h4>A quick look at recently released python 3.11 features</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z3xv2t3Ii3wwY8fJ54PaGQ.png" /></figure><p>As we know, Python 3.11.0 released on 24th October 2022 with new features and improvements. In this article, We will cover some of these updates with examples.</p><h4>Performance improvement</h4><p>As per the details given <a href="https://docs.python.org/3.11/whatsnew/3.11.html?utm_source=pocket_mylist#whatsnew311-faster-cpython">here</a>, python 3.11 is 10–60% faster than its predecessor 3.10.</p><h4>Fine-grained error locations in tracebacks</h4><p>Now, the traceback is improved to print the exact error details instead of just pointing to the line</p><p><a href="https://peps.python.org/pep-0657/">PEP 657</a> for detailed info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ort_PsMo791CZZWo6mtRxQ.png" /><figcaption>traceback</figcaption></figure><h4>Add note to exception</h4><p>A note can be added to an exception object rather than using print() or logging explicitly</p><p><a href="https://peps.python.org/pep-0678/"><em>PEP 678</em></a> for detailed info.</p><pre><strong># How to add note to an exception object</strong><br>import logging<br><br>try:<br>    raise ValueError(&#39;Invalid value&#39;)<br>except ValueError as ve:<br>    <strong><em>ve.add_note(&#39;Add Note feature in Python 3.11&#39;)</em></strong><br>    logging.exception(ve, stack_info=True)</pre><p><em>The below traceback contains the note added to an exception object above</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*tWMXmUtxl7PDRbLZDydLEA.png" /><figcaption>Exception details with added note</figcaption></figure><h4><strong>Exception Groups and except*</strong></h4><p>This feature helps us to group multiple exceptions raised in the program with details of each exception.</p><p>The last line in the below code snippet is an example for grouping different types of exceptions</p><pre>def exc_method(num1, num2=None):<br>    try:<br>        int(num1)<br>        num1 / num2<br>    except ValueError as ve:<br>        ve.add_note(&quot;ValueError :: Add Note feature - Python 3.11&quot;)<br>        return ve<br>    except TypeError as te:<br>        te.add_note(&quot;TypeError :: Add Note feature - Python 3.11&quot;)<br>        return te<br>    except Exception as e:<br>        e.add_note(&quot;Exception :: Add Note feature - Python 3.11&quot;)<br>        return e<em><br><br></em><strong><em>raise ExceptionGroup(&quot;ExceptionGroup1&quot;, [exc_method(&quot;a&quot;), exc_method(10, &#39;a&#39;)])</em></strong></pre><p><em>The traceback of Exception Group is added below</em></p><pre>+ Exception Group Traceback (most recent call last):<br>  |   File &quot;C:\python\microservices_fastapi\ch01\test2.py&quot;, line 19, in &lt;module&gt;<br>  |     raise ExceptionGroup(&quot;ExceptionGroup&quot;, [exc_method(&quot;a&quot;), exc_method(10, &#39;a&#39;)])<br>  | ExceptionGroup: ExceptionGroup (2 sub-exceptions)<br>  +-+---------------- 1 ----------------<br>    | Traceback (most recent call last):<br>    |   File &quot;C:\python\microservices_fastapi\ch01\test2.py&quot;, line 6, in exc_method<br>    |     int(num1)<br>    | ValueError: invalid literal for int() with base 10: &#39;a&#39;<br>    | ValueError :: Add Note feature - Python 3.11<br>    +---------------- 2 ----------------<br>    | Traceback (most recent call last):<br>    |   File &quot;C:\python\microservices_fastapi\ch01\test2.py&quot;, line 7, in exc_method<br>    |     num1 / num2<br>    |     ~~~~~^~~~~~<br>    | TypeError: unsupported operand type(s) for /: &#39;int&#39; and &#39;str&#39;<br>    | TypeError :: Add Note feature - Python 3.11<br>    +------------------------------------</pre><p><strong>Use cases:</strong></p><p><em>· Concurrent errors</em></p><p><em>· Multiple failures when retrying an operation etc.</em></p><p><a href="https://peps.python.org/pep-0654/"><em>PEP 654</em></a> for detailed info.</p><h4>TypedDict items as Required or NotRequired — Type hints</h4><p>We have 2 new type qualifiers in typing module: <strong><em>Required[]</em></strong> and <strong><em>NotRequired[] </em></strong>which can be used on individual items of <strong><em>TypedDict </em></strong>to mark them as required and potentially-missing respectively</p><p><a href="https://peps.python.org/pep-0655/">PEP 655</a> for detailed info.</p><pre># <strong>Example</strong></pre><pre>class <strong>MyClass</strong>(TypedDict):<br>   name: str <strong><em>Required[str]</em></strong><br>   version: <strong><em>NotRequired[int]</em></strong><br>   author<strong>:</strong> Optional<strong>[</strong>str<strong>]</strong>  <strong><em># means string|None, not potentially-missing!</em></strong></pre><pre>m1: MyClass = {&quot;name&quot;: &quot;Class1&quot;, &quot;version&quot;: 1}  <em># OK</em><br>m2: MyClass = {&quot;name&quot;: &quot;Class2&quot;}  <em># OK (version is not required)</em><br>m3: MyClass = {&quot;version&quot;: 2022}  <em># ERROR (missing required field name)</em></pre><p>There are other typing features which you might want to look at:</p><ul><li><a href="https://peps.python.org/pep-0646/">PEP 646: Variadic generics</a></li><li><a href="https://peps.python.org/pep-0673/">PEP 673: self type</a></li><li><a href="https://peps.python.org/pep-0675/">PEP 675: Arbitrary literal string type</a></li><li><a href="https://peps.python.org/pep-0681/">PEP 681: Data class transforms</a></li></ul><p>That’s all for now. I hope you found this article helpful</p><p>For more information on python 3.11, please refer the official python documentation <a href="https://docs.python.org/3.11/whatsnew/3.11.html">What’s new in python 3.11</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1104c82ed97" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <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-416c917cdd7b------2</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>