<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Suyash Muley</title>
    <description>The latest articles on DEV Community by Suyash Muley (@suyashmuley).</description>
    <link>https://dev.to/suyashmuley</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F870136%2Fd2e6faf9-e475-4ec2-b407-ed5b9c99f6f5.jpeg</url>
      <title>DEV Community: Suyash Muley</title>
      <link>https://dev.to/suyashmuley</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/suyashmuley"/>
    <language>en</language>
    <item>
      <title>Creating an SQL Agent Using OpenAI and Python</title>
      <dc:creator>Suyash Muley</dc:creator>
      <pubDate>Wed, 11 Dec 2024 06:50:07 +0000</pubDate>
      <link>https://dev.to/suyashmuley/creating-an-sql-agent-using-openai-and-python-13if</link>
      <guid>https://dev.to/suyashmuley/creating-an-sql-agent-using-openai-and-python-13if</guid>
      <description>&lt;p&gt;In today’s data-driven world, accessing databases and retrieving information efficiently is crucial. However, not everyone is proficient in SQL. That’s where SQL agents come in. These tools bridge the gap between natural language and SQL, making data access more intuitive for everyone.&lt;/p&gt;

&lt;p&gt;In this blog, we’ll build a SQL agent that takes natural language queries, converts them into SQL using OpenAI’s GPT model, and executes them against a database using SQLAlchemy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Build a SQL AI Agent?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simplify Database Queries: Users don’t need to know SQL to interact with databases.&lt;/li&gt;
&lt;li&gt;Increase Productivity: Reduces the time spent writing SQL queries.&lt;/li&gt;
&lt;li&gt;Expand Access: Enables non-technical users to access and manipulate data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzppgmj6pvy0eltoj4fub.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzppgmj6pvy0eltoj4fub.png" alt="workflow" width="692" height="597"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
The SQL AI agent works in three key steps:&lt;/p&gt;

&lt;p&gt;Interpret the User’s Query: OpenAI’s language model translates the user’s natural language input into SQL.&lt;br&gt;
Execute the SQL Query: The generated SQL is run against an MS SQL Server database using SQLAlchemy.&lt;br&gt;
Display Results: The results of the query are returned to the user in a human-readable format.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;openai&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sqlalchemy&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;create_engine&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;

&lt;span class="c1"&gt;# Set OpenAI API Key
&lt;/span&gt;&lt;span class="n"&gt;openai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;your_openai_api_key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;# Database connection string
&lt;/span&gt;&lt;span class="n"&gt;DATABASE_URI&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;your_db_connection string&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_engine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DATABASE_URI&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;interpret_prompt_with_ai&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;openai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gpt-4o&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;
                &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Convert this user query into an SQL statement for MS SQL Server: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;}],&lt;/span&gt;
            &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;max_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;response_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;
        &lt;span class="n"&gt;sql_query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;```

sql\n(.*?)\n

```&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response_text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DOTALL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sql_query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;sql_query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response_text&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Error interpreting prompt:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;execute_query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sql_query&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sql_query&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchall&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Error executing query:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Welcome! Please specify your query in plain English:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;user_prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;&amp;gt; &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;sql_query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;interpret_prompt_with_ai&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;sql_query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Sorry, I couldn&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;t generate a query from your input.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;

    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;Generated SQL Query:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sql_query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;execute_query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sql_query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Sorry, the query could not be executed.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;

    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;Query Results:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Features&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Natural Language Input: Users can input plain English queries.&lt;/li&gt;
&lt;li&gt;Dynamic SQL Generation: AI generates accurate SQL queries tailored to user requests.&lt;/li&gt;
&lt;li&gt;Database Execution: SQLAlchemy ensures safe and efficient query execution.&lt;/li&gt;
&lt;li&gt;Error Handling: The application gracefully handles errors in AI interpretation or SQL execution.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With Python, OpenAI, and SQLAlchemy, you can create a tool that’s both powerful and user-friendly.&lt;br&gt;
Try it out, and let me know how you plan to extend its functionality! 🚀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Streamlining AWS Resource Provisioning with CloudFormation: A YAML Template Guide</title>
      <dc:creator>Suyash Muley</dc:creator>
      <pubDate>Fri, 29 Dec 2023 07:32:50 +0000</pubDate>
      <link>https://dev.to/suyashmuley/streamlining-aws-resource-provisioning-with-cloudformation-a-yaml-template-guide-44d0</link>
      <guid>https://dev.to/suyashmuley/streamlining-aws-resource-provisioning-with-cloudformation-a-yaml-template-guide-44d0</guid>
      <description>&lt;p&gt;Amazon Web Services (AWS) provides CloudFormation, a powerful Infrastructure as Code (IaC) service that allows users to define and provision AWS infrastructure using a declarative YAML template. In this blog post, we will explore the benefits of using CloudFormation and demonstrate how to set up various resources using a YAML template.&lt;/p&gt;

&lt;p&gt;Why CloudFormation?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Automation and Consistency: CloudFormation enables the automation of infrastructure deployment, ensuring consistency across environments. With a single YAML template, you can define and provision resources, reducing the risk of configuration errors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Version Control: YAML templates can be version-controlled using tools like Git, allowing for easy tracking of changes and rollbacks. This promotes collaboration among team members and helps maintain a reliable version history.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Time and Cost Savings: By automating resource provisioning, CloudFormation saves time and reduces the likelihood of manual errors. This leads to more efficient resource management and cost savings.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Creating a YAML Template&lt;br&gt;
Let's dive into creating a YAML template for setting up AWS resources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AWSTemplateFormatVersion: '2010-09-09'
Description: 'AWS CloudFormation Template for Setting Up Resources'

Parameters:
  EnvironmentName:
    Type: String
    Description: 'Name of the environment'
    Default: 'MyEnvironment'

Resources:
  MyLambdaFunction:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: !Sub '${EnvironmentName}-MyLambdaFunction'
      Runtime: 'nodejs14.x'
      Handler: 'index.handler'
      Role: !GetAtt MyLambdaFunctionRole.Arn
      # Add other Lambda properties as needed

  MyLambdaFunctionRole:
    Type: 'AWS::IAM::Role'
    Properties:
      RoleName: !Sub '${EnvironmentName}-MyLambdaFunctionRole'
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: 'Allow'
            Principal:
              Service: 'lambda.amazonaws.com'
            Action: 'sts:AssumeRole'
      # Add other IAM role properties as needed

  MySQSQueue:
    Type: 'AWS::SQS::Queue'
    Properties:
      QueueName: !Sub '${EnvironmentName}-MySQSQueue'
      # Add other SQS properties as needed

  # Add similar sections for SNS, DynamoDB, CodeBuild, and other resources

Outputs:
  LambdaFunctionArn:
    Description: 'ARN of the created Lambda function'
    Value: !GetAtt MyLambdaFunction.Arn

  # Add outputs for other resources as needed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This template is a starting point and can be customized based on your specific requirements. The Parameters section allows you to provide inputs, such as the environment name. The Resources section defines the AWS resources to be created, and the Outputs section allows you to expose important information for reference.&lt;/p&gt;

&lt;p&gt;Deploying the Template&lt;br&gt;
To deploy the template, you can use the AWS Management Console, AWS Command Line Interface (CLI), or AWS SDKs. Here's an example CLI command:&lt;br&gt;
&lt;code&gt;aws cloudformation create-stack --stack-name MyStack --template-body file://path/to/your/template.yaml --parameters ParameterKey=EnvironmentName,ParameterValue=Production&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;CloudFormation, with its tight integration with AWS services and its Infrastructure as Code approach, offers a robust solution for automating and managing AWS infrastructure.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cloudformation</category>
      <category>iaac</category>
    </item>
    <item>
      <title>Resolving Security Issues Unearthed During a Pen Test</title>
      <dc:creator>Suyash Muley</dc:creator>
      <pubDate>Tue, 12 Sep 2023 09:16:34 +0000</pubDate>
      <link>https://dev.to/suyashmuley/resolving-security-issues-unearthed-during-a-pen-test-20jj</link>
      <guid>https://dev.to/suyashmuley/resolving-security-issues-unearthed-during-a-pen-test-20jj</guid>
      <description>&lt;p&gt;Penetration testing, often referred to as pen testing, is a crucial component of any robust cybersecurity strategy. It allows organizations to uncover vulnerabilities and weaknesses in their applications and systems before malicious actors can exploit them. However, the real value of a pen test lies not just in finding security issues but also in addressing and resolving them promptly. In this blog, we'll explore how to effectively resolve security issues discovered during a pen test, using real-world examples like XSS (Cross-Site Scripting), SQL injection, session timeout etc.&lt;br&gt;
Here we will take a .NET app as a reference.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Site Scripting (XSS)&lt;/strong&gt;&lt;br&gt;
Cross-Site Scripting is a prevalent vulnerability that occurs when a web application allows users to inject malicious scripts into web pages viewed by other users. To resolve XSS issues:&lt;br&gt;
a. Input Validation: Ensure that all user inputs are validated and sanitized before rendering them in HTML or JavaScript.&lt;br&gt;
b. Output Encoding: Implement output encoding to prevent script execution.&lt;br&gt;
c. Security Headers: Employ security headers like Content Security Policy (CSP) to restrict the sources of executable scripts.&lt;br&gt;
d. Regular Updates: Regularly update and patch your web application framework and libraries to mitigate known XSS vulnerabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SQL Injection&lt;/strong&gt;&lt;br&gt;
SQL injection is another critical security concern that arises when an attacker manipulates an application's SQL query to access unauthorized data. To address SQL injection issues:&lt;br&gt;
a. Parameterized Queries: Use parameterized queries or prepared statements to separate user input from SQL queries, making it nearly impossible for attackers to inject malicious SQL.&lt;br&gt;
b. Input Validation: Validate and sanitize user input to detect and block any attempts at injecting malicious SQL code.&lt;br&gt;
c. Escaping Characters: Implement proper escaping of special characters in SQL queries to prevent injection.&lt;br&gt;
d. Principle of Least Privilege: Ensure that database connections have the least privilege required for the application, limiting potential damage if an injection occurs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Session Timeout&lt;/strong&gt;&lt;br&gt;
Session timeout issues can lead to unauthorized access when users leave their sessions unattended. To resolve session timeout problems:&lt;br&gt;
a. Set Reasonable Timeouts: Define appropriate session timeout periods based on the sensitivity of the application. Shorter timeouts for more critical applications, longer for less critical ones.&lt;br&gt;
b. User Notifications: Notify users before their sessions expire and provide an option to extend the session if needed.&lt;br&gt;
c. Implement Idle Timeout: Implement idle session timeouts to automatically log out users after a period of inactivity.&lt;br&gt;
d. Persistent Sessions: Use persistent sessions for users who need to remain logged in for longer periods, but always ensure secure handling of these sessions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Upgrading Libraries in a .NET Application&lt;/strong&gt;&lt;br&gt;
Regularly upgrading libraries and dependencies is crucial to maintaining a secure application. Here's how to tackle this issue in a .NET application:&lt;br&gt;
a. Dependency Scanning: Utilize tools and services that can scan your application for outdated or vulnerable dependencies, such as OWASP Dependency-Check.&lt;br&gt;
b. Version Control: Maintain a version control system to track changes in your application's dependencies.&lt;br&gt;
c. Automated Testing: Integrate automated testing into your development pipeline to identify compatibility issues and vulnerabilities when updating libraries.&lt;br&gt;
d. Patch Management: Develop a patch management process to ensure timely updates and patches are applied when security vulnerabilities are discovered.&lt;/p&gt;

&lt;p&gt;Resolving the issues uncovered during a pen test requires a systematic approach that includes input validation, output encoding, parameterized queries, session management, and diligent library management. By addressing these issues promptly and effectively, you can significantly enhance the security posture of your organization and reduce the risk of data breaches and cyberattacks. &lt;/p&gt;

</description>
      <category>pentest</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Creating an Expiration Utility for Automatic User Subscription Deactivation in Azure API Management</title>
      <dc:creator>Suyash Muley</dc:creator>
      <pubDate>Wed, 31 May 2023 13:57:18 +0000</pubDate>
      <link>https://dev.to/suyashmuley/creating-an-expiration-utility-for-automatic-user-subscription-deactivation-in-azure-api-management-4o1i</link>
      <guid>https://dev.to/suyashmuley/creating-an-expiration-utility-for-automatic-user-subscription-deactivation-in-azure-api-management-4o1i</guid>
      <description>&lt;p&gt;Managing subscription expirations and notifying users is essential for an efficient Azure API Management project. By leveraging Azure Functions and an Express Node.js application, you can automate the process of expiring subscriptions and sending notification emails to keep users informed.&lt;/p&gt;

&lt;p&gt;In this blog post, we will explore how to integrate Azure Functions and Express Node.js to create a powerful solution for subscription management in Azure API Management.&lt;/p&gt;

&lt;p&gt;Prerequisites: To follow along with this tutorial, you should have basic knowledge of Azure API Management, Azure Functions, and Express Node.js.&lt;/p&gt;

&lt;p&gt;Step 1: Set Up Azure API Management Ensure that you have an Azure API Management instance set up in your Azure account. This instance will serve as the central hub for managing APIs and subscriptions.&lt;/p&gt;

&lt;p&gt;Step 2: Create an Azure Function Start by creating an Azure Function that will handle the subscription expiration logic. You can use any supported programming language for Azure Functions, but we’ll focus on using JavaScript and Node.js in this tutorial. Inside the function, you will need to:&lt;/p&gt;

&lt;p&gt;Retrieve the list of subscriptions nearing expiration from Azure API Management.&lt;br&gt;
Deactivate the subscriptions by updating their status.&lt;br&gt;
Integrate with an email service to send notification emails to the subscription owners.&lt;br&gt;
Step 3: Set Up an Express Node.js Application Create an Express Node.js application that will handle incoming requests from the Azure Function. This application will provide an API endpoint for the Azure Function to send subscription expiration details.&lt;/p&gt;

&lt;p&gt;Set up the necessary routes and endpoints in the Express application to receive data from the Azure Function.&lt;br&gt;
Implement the logic to send notification emails to the subscription owners using a suitable email service, such as Nodemailer or SendGrid.&lt;br&gt;
Customize the email template to include relevant information, such as API name, subscription end date, and renewal instructions.&lt;br&gt;
Step 4: Integrate Azure Functions with Express Node.js Within the Azure Function, make an HTTP request to the Express Node.js application’s API endpoint, passing the subscription expiration details. Use the appropriate HTTP client library, such as Axios or the built-in http module, to send the request.&lt;/p&gt;

&lt;p&gt;Step 5: Test and Monitor With everything set up, test the solution by creating test subscriptions with short expiration dates. Verify that the Azure Function deactivates the subscriptions and sends the subscription details to the Express Node.js application correctly. Monitor the application logs and Azure Function execution logs to ensure the solution operates as expected.&lt;/p&gt;

&lt;p&gt;This solution simplifies the process of subscription expiration and user communication, ensuring a seamless experience for both API providers and consumers. With Azure Functions and Express Node.js, you can efficiently manage subscription lifecycles and maintain a well-organized API ecosystem in Azure API Management.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>azurefunctions</category>
      <category>apimanagement</category>
      <category>express</category>
    </item>
    <item>
      <title>Excel add-in and custom functions</title>
      <dc:creator>Suyash Muley</dc:creator>
      <pubDate>Mon, 10 Apr 2023 05:10:25 +0000</pubDate>
      <link>https://dev.to/suyashmuley/excel-add-in-and-custom-functions-3aop</link>
      <guid>https://dev.to/suyashmuley/excel-add-in-and-custom-functions-3aop</guid>
      <description>&lt;p&gt;As technology continues to evolve, the tools and platforms that developers use to create applications are also evolving. In this blog, we will explore how to create an Office Add-in with Excel custom functions using the Angular framework and the Yeoman generator.&lt;/p&gt;

&lt;p&gt;The first step is to install the Yeoman generator for Office Add-ins using the following command:&lt;br&gt;
&lt;code&gt;npm install -g yo generator-office&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once the generator is installed, we can create a new Office Add-in project using the following command:&lt;br&gt;
&lt;code&gt;yo office&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command will prompt you to select the type of Office Add-in you want to create. In this case, we will select the Excel Add-in.&lt;br&gt;
Next, we need to choose the framework we want to use to create our add-in. We will select Angular, We could also select React or HTML,CSS only if required based on requirements.&lt;/p&gt;

&lt;p&gt;Once the project is generated, we can navigate to the project directory and run the following command to build and run the add-in:&lt;br&gt;
&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will build the add-in and start a local server where we can test our add-in in Excel.&lt;br&gt;
The build files will be located in under dist folder in the root of the project.&lt;/p&gt;

&lt;p&gt;Now that we have our add-in project set up, we can start creating our Excel custom functions.&lt;/p&gt;

&lt;p&gt;Excel custom functions allow you to create your own functions that can be used in Excel formulas. To create a custom function, we need to open the Functions.ts file under Functions folder &lt;br&gt;
Write the Function code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export function double(input: number): number {
  return input * 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function takes in a number and returns the number multiplied by 2.&lt;/p&gt;

&lt;p&gt;Now we can use this function in Excel formulas like any other built-in function.&lt;br&gt;
&lt;code&gt;=double(A1)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will take the value in cell A1, double it, and return the result.&lt;br&gt;
In conclusion, creating an Office Add-in with Excel custom functions using the Angular framework and the Yeoman generator is a straightforward process. With just a few lines of code, we can create custom functions that can be used in Excel formulas, extending the functionality of Excel to fit our specific needs.&lt;/p&gt;

</description>
      <category>officeaddins</category>
      <category>exceladdin</category>
      <category>customfunctions</category>
    </item>
    <item>
      <title>CI-CD for .NET projects using GitHub actions, AWS s3 and CodeDeploy</title>
      <dc:creator>Suyash Muley</dc:creator>
      <pubDate>Fri, 10 Mar 2023 09:54:33 +0000</pubDate>
      <link>https://dev.to/suyashmuley/ci-cd-for-net-projects-using-github-actions-aws-s3-and-code-deploy-162f</link>
      <guid>https://dev.to/suyashmuley/ci-cd-for-net-projects-using-github-actions-aws-s3-and-code-deploy-162f</guid>
      <description>&lt;p&gt;In the world of software development, continuous integration and continuous delivery - continuous deployment (CI/CD) has become a common practice to ensure that the code is delivered in a timely and reliable manner. GitHub Actions is an integral part of the GitHub platform, provides a powerful, flexible, and easy-to-use framework for implementing CI/CD workflows. &lt;/p&gt;

&lt;p&gt;In this blog post, we'll explore how to use GitHub Actions to build, test, publish, and deploy .NET applications to an EC2 instance running Windows using AWS CodeDeploy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting Up the Environment&lt;/strong&gt;&lt;br&gt;
Before we get started with building the workflow, we need to ensure that we have the necessary tools and services set up.&lt;/p&gt;

&lt;p&gt;Prerequisites&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A GitHub account.&lt;/li&gt;
&lt;li&gt;AWS IAM role for ec2, s3 bucket and CodeDeploy.&lt;/li&gt;
&lt;li&gt;A .NET application hosted on GitHub.&lt;/li&gt;
&lt;li&gt;An AWS account with S3 bucket and CodeDeploy service.&lt;/li&gt;
&lt;li&gt;A Windows EC2 instance running IIS with CodeDeploy agent installed creating the workflow.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;IAM configuration:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to IAM dashboard in AWS console and click on Users.&lt;/li&gt;
&lt;li&gt;Click on "Roles" and then on create role button.&lt;/li&gt;
&lt;li&gt;Choose EC2 as the use case and AWS service as the trusted entity type.&lt;/li&gt;
&lt;li&gt;On the next page add "AmazonS3FullAccess","AWSCodeDeployRole","AmazonEC2RoleforAWSCodeDeploy" in the permission policies and click on create role button. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;AWS S3:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to S3 service in AWS.&lt;/li&gt;
&lt;li&gt;Click on create bucket button.&lt;/li&gt;
&lt;li&gt;Enter the bucket name, region and modify the settings of bucket if required and click on create bucket button.&lt;/li&gt;
&lt;li&gt;Create a folder inside the bucket to hold the published files.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;AWS EC2:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the EC2 service click on launch instance button.&lt;/li&gt;
&lt;li&gt;Enter the name of the instance, select windows as Application and OS Images.&lt;/li&gt;
&lt;li&gt;select the instance type as per the requirements.&lt;/li&gt;
&lt;li&gt;Select the key pair where most commonly used are SSH keys and click on create new key pair.
Note: save the key securely as it is created only once and if it's lost you cannot recover it.&lt;/li&gt;
&lt;li&gt;Configure the necessary Network and Storage settings and finally hit launch instance.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;AWS CodeDeploy:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the CodeDeploy service click on create application.&lt;/li&gt;
&lt;li&gt;Enter the application name and select compute type as EC2/On-premises.&lt;/li&gt;
&lt;li&gt;On the next page click on create deployment group button and enter the name.&lt;/li&gt;
&lt;li&gt;Select the service role which you've created while creating IAM role.&lt;/li&gt;
&lt;li&gt;Select Amazon EC2 instance and enter the key-pair of the EC2 instance where you want to deploy the application.&lt;/li&gt;
&lt;li&gt;After the necessary configurations for CodeDeploy service click on create deployment group.&lt;/li&gt;
&lt;li&gt;Next click on create deployment and select "My application is stored in GitHub".&lt;/li&gt;
&lt;li&gt;Enter the GitHub profile name as token name and connect to GitHub profile, After creating the deployment this would trigger the deployment to EC2 instance.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;GitHub Actions configuration:&lt;/strong&gt;&lt;br&gt;
We'll start by creating a new workflow in our .NET application's GitHub repository. A workflow is a series of steps that define how our code should be built, tested and deployed.&lt;/p&gt;

&lt;p&gt;Go to your GitHub repository and select the Actions tab.&lt;/p&gt;

&lt;p&gt;Click on the "New workflow" button and choose "Set up a workflow yourself".&lt;/p&gt;

&lt;p&gt;Give your workflow a name and add the following YAML code to define the steps:&lt;/p&gt;

&lt;p&gt;yaml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: CI-CD Workflow

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: windows-latest

    steps:
    - name: Checkout Code
      uses: actions/checkout@v2

    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '6.0.x'

    - name: Build and Test
      run: dotnet build &amp;amp;&amp;amp; dotnet test

    - name: Publish
      run: dotnet publish -c Release -o ./publish

    - name: zip publish
      run: Compress-Archive -Path ./publish -DestinationPath ./publish/publish.zip

    - name: Configure AWS credentials from Test account
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: {aws-region}

    - name: Upload to S3
      run: | 
        aws s3 cp ./publish s3://{bucket-name}/{folder-name}/ --recursive

    - name: Deploy to EC2 instance
      run: |
        aws deploy create-deployment --application-name {application-name} --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name {deployment-group-name} --s3-location bucket={bucket-name},key={folder-name}/publish.zip,bundleType=zip


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The workflow consists of the following steps:&lt;br&gt;
Checkout Code: Check out the code from the GitHub repository.&lt;br&gt;
Setup .NET: Set up the .NET runtime on the build machine.&lt;br&gt;
Build: Compile the application in release mode.&lt;br&gt;
Test: Run the unit tests for the application.&lt;br&gt;
Publish: Publish the application to the publish folder.&lt;br&gt;
Zip: Compress the publish folder into a single zip file.&lt;br&gt;
Upload to S3: Upload the zip file to an S3 bucket.&lt;br&gt;
Deploy: Trigger an AWS CodeDeploy deployment using the zip file in the s3 bucket.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this blog post, we've seen how to use GitHub Actions to build, test, publish, and deploy. NET applications to an EC2 instance running Windows using AWS CodeDeploy. By automating the build, test, and deployment process, we can ensure that our application is delivered in a timely and reliable manner. By using the power of AWS services like S3 and CodeDeploy, we can achieve a robust and scalable deployment process for our .NET applications.&lt;/p&gt;

</description>
      <category>cicd</category>
      <category>aws</category>
      <category>githubactions</category>
      <category>dotnet</category>
    </item>
  </channel>
</rss>
