<?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: Ak</title>
    <description>The latest articles on DEV Community by Ak (@ashok6266).</description>
    <link>https://dev.to/ashok6266</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%2F85103%2F5e01aa70-9f94-419b-9c5f-e045d1bf5ac6.jpeg</url>
      <title>DEV Community: Ak</title>
      <link>https://dev.to/ashok6266</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashok6266"/>
    <language>en</language>
    <item>
      <title>Unveiling the Mystery: Decoding the Dilemma of Lambda Deployment in Private Subnets</title>
      <dc:creator>Ak</dc:creator>
      <pubDate>Wed, 01 May 2024 08:12:38 +0000</pubDate>
      <link>https://dev.to/ashok6266/some-title-5c8b</link>
      <guid>https://dev.to/ashok6266/some-title-5c8b</guid>
      <description>&lt;p&gt;This article originally published &lt;a href="https://medium.com/@Cloud-DevSecOps/unveiling-the-mystery-decoding-the-dilemma-of-lambda-deployment-in-private-subnets-aafb70fe878c"&gt;here&lt;/a&gt;. In this demonstration, we see why we are getting a timeout error when deploying a lambda functions to a public subnet.&lt;/p&gt;

&lt;p&gt;I will deploy a VPC with an Internet gateway to demonstrate this error I am not going to deploy any resources in a private subnet, so for the moment I will not create a NAT gateway. After deploying, my VPC belongs as below.&lt;/p&gt;

&lt;p&gt;I will deploy a sample Lambda function with role created by default in the vpc-1 in public subnet and I added necessary lambda layers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxticweuhor60a7jmniql.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxticweuhor60a7jmniql.png" alt="Image description" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import requests

def lambda_handler(event, context):
    url = 'https://swapi.dev/api/people/4/'
    response = requests.get(url)

    if response.status_code == 200:
        return response.json()
    else:
        return {
            'statusCode': response.status_code,
            'body': 'Failed to fetch data from SWAPI'
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;General configuration&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Febyuhni490mt8wmmaypp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Febyuhni490mt8wmmaypp.png" alt="Image description" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;VPC configuration:&lt;br&gt;
Although, the public subnet has a route (0.0.0.0/0)towards internet gateway, the function test will fall into task timed out because the Lambda function itself does not have a publicly accessible IP address.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frsdnqhr5bnk1p6nnzkvm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frsdnqhr5bnk1p6nnzkvm.png" alt="Image description" width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Test python function&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgv4ipxf6p5mc10j80nex.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgv4ipxf6p5mc10j80nex.png" alt="Image description" width="800" height="291"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now I will deploy my function to a private subnet with NAT gateway in the public subnet. In the route table of the private subnet, I will add a route to 0.0.0.0/0 towards my NAT gateway. I will do a test again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fevpvwpaqp58t0us27ct9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fevpvwpaqp58t0us27ct9.png" alt="Image description" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ihpgmi8s4evfehouv2j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ihpgmi8s4evfehouv2j.png" alt="Image description" width="800" height="291"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Private subnet route table&lt;/p&gt;

&lt;p&gt;Test python after private subnet&lt;br&gt;
This is the best practice for a Lambda function to access the resources through internet. In the next article, we will see how to access AWS services (s3,RDS, DynamoDB)from private subnet without NAT.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Securing AWS Infrastructure: How to Safely Connect Lambda Functions to RDS Databases via Secrets Manager</title>
      <dc:creator>Ak</dc:creator>
      <pubDate>Wed, 01 May 2024 08:12:38 +0000</pubDate>
      <link>https://dev.to/ashok6266/some-title-1o9d</link>
      <guid>https://dev.to/ashok6266/some-title-1o9d</guid>
      <description>&lt;p&gt;Here are the 2 prerequisites to test the solution of integrating Lambda with RDS via Secrets Manager on AWS&lt;/p&gt;

&lt;p&gt;AWS Account: You need to have an AWS account to access AWS services. If you don’t have one, you can sign up for an AWS account at aws.amazon.com.&lt;br&gt;
Budget Alarms: Set up budget alarms in AWS Budgets to monitor your AWS spending. This helps you avoid unexpected charges while testing the solution.&lt;/p&gt;

&lt;p&gt;You need to create a VPC with private subnets so that we can run our RDS instance in private subnet&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr234yk5mlnc6ynrrmcrs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr234yk5mlnc6ynrrmcrs.png" alt="Image description" width="800" height="267"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before creating RDS, I will create my DB subnet groups so that when I launch my RDS instance I can select DB subnet group&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fimnf8iwrwx4ht18nqwi0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fimnf8iwrwx4ht18nqwi0.png" alt="Image description" width="800" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am going to launch an RDS MySQL instance within Free tier&lt;br&gt;
Db instance class : db.t2.micro&lt;br&gt;
Db subnet group : : secret-manager-subnet&lt;br&gt;
I will deploy my RDS instance to VPC and RDS db subnet group created in the above steps&lt;br&gt;
I will select passwords to be managed in secrets manager&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp4giz2iohd6ore5hduc8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp4giz2iohd6ore5hduc8.png" alt="Image description" width="800" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will create Lambda function and in our VPC and private subnets. I will leave Role creation by default.&lt;br&gt;
Then I will add all necessary permissions to the role — RDS,EC2(createnetworkinterface), secrets manager&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjwjo4dnwruk9kpp0go19.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjwjo4dnwruk9kpp0go19.png" alt="Image description" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need pyMySQL modules, so the easiest way is to add an AWS layer's to python function. I will add AWSSDKPandas-Python312&lt;br&gt;
The role added to the lambda function should have permissions to read secret manager, so modify the policy to give read permissions to secret manager&lt;br&gt;
I will use the following python code to test the connection using secret manager. In the general configuration, I will add timeout to 1 min 3sec&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pymysql
import json
import boto3

def lambda_handler(event, context):
    # Initialize the Secrets Manager client
    client = boto3.client('secretsmanager')

    # Retrieve the secret value
    secret_name = “&amp;lt;SECRET MANAGER NAME&amp;gt;”
    response = client.get_secret_value(SecretId=secret_name)
    secret = json.loads(response['SecretString'])

    # Extract database credentials
    db_username = secret['username']
    db_password = secret['password']
    db_host = “RDS ENDPOINT“

    # Establish a connection to the database
    try:
        conn = pymysql.connect(host=db_host, user=db_username, password=db_password, connect_timeout=5)
        print("Successfully connected to the database")

        # Perform operations here if needed
        # For example:
        # with conn.cursor() as cursor:
        #     cursor.execute("SELECT * FROM your_table;")
        #     result = cursor.fetchall()
        #     print(result)

    except Exception as e:
        print("Database connection error:", e)

    finally:
        # Close the database connection
        if conn:
            conn.close()

    return {
        'statusCode': 200,
        'body': json.dumps('Database connection successful!')
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will configure a custom test event&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F154fec233qfaakvs9aed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F154fec233qfaakvs9aed.png" alt="Image description" width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have any concerns/doubts/help follow me regarding this post, you can DM on LinkedIn, and also I invite you to my discord server and stay updated on cloud and DevOps.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cloud</category>
      <category>devops</category>
    </item>
    <item>
      <title>What is a MVC pattern?</title>
      <dc:creator>Ak</dc:creator>
      <pubDate>Tue, 11 Sep 2018 16:19:46 +0000</pubDate>
      <link>https://dev.to/ashok6266/what-is-a-mvc-pattern-3k85</link>
      <guid>https://dev.to/ashok6266/what-is-a-mvc-pattern-3k85</guid>
      <description>&lt;h1&gt;
  
  
  MVC - Model view controller
&lt;/h1&gt;

&lt;p&gt;Model view controller(mvc) is the design pattern nowadays used in the production.&lt;br&gt;
&lt;strong&gt;Model&lt;/strong&gt; - It contains the code to manage the databases. For example you can see sql requests like INSERT INTO tasks(id,title,description,creation_date,edition_date)&lt;br&gt;
       values('55','"$_POST['title']"','"$_POST['task']"','"$_POST['date']"','"$_POST['edit_date']"')").&lt;br&gt;
&lt;strong&gt;View&lt;/strong&gt; - From the name itself it implies that it is the view part normally contains HTML codes. Sometimes it has PHP variables and conditions. For example if we want to display a post of a user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Controller&lt;/strong&gt; - Controller has all the decision making codes or else logical parts goes here. It is the intermediate between model and view. For instance : If an user requests for an page the controller invokes the method from the model and gives back it to the view.&lt;/p&gt;

&lt;p&gt;For beginners I have created a directory structure of mvc which you can either git clone or download the zip file and you can extract into the directory where you are going to create your mvc application&lt;/p&gt;

&lt;h2&gt;
  
  
  To clone the structure use the git command :
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/ASHOK6266/myOwnStructure_mvc.git 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I have also added database file to the structure which is a Singleton pattern&lt;/p&gt;

&lt;p&gt;Once you clone the structure you will see the database file in Models/Application/db.php&lt;br&gt;
Database connection is the Singleton pattern which restricts the class instantiation again and again.&lt;br&gt;
Moreover the singleton pattern makes your application faster.&lt;br&gt;
Don't forget to add your dbname,username,password in the db.php file&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP 0:&lt;/strong&gt;&lt;br&gt;
I created database named myOwnStructure_mvc and todolist table with id,title and description.&lt;br&gt;
&lt;strong&gt;STEP 1:&lt;/strong&gt;&lt;br&gt;
Models/Application/App.php &lt;br&gt;
I created class Tasks and method get_task();&lt;br&gt;
The method get_task() will retrieve all the posts from the database.&lt;br&gt;
&lt;strong&gt;STEP 2:&lt;/strong&gt;&lt;br&gt;
Controllers/Application/AppController.php&lt;br&gt;
I created class AppController and method show_tasks ;&lt;br&gt;
The method show_tasks will invoke the model (i.e method get_task) from the  Models/Application/App.php&lt;br&gt;&lt;br&gt;
Don't forget to include model file here include('../../Models/Application/App.php');&lt;br&gt;
&lt;strong&gt;STEP 3:&lt;/strong&gt;&lt;br&gt;
Views/Application/App.php&lt;br&gt;
I just called the controller methods here i.e show tasks.&lt;br&gt;
Normally no logic and security should be in views.&lt;br&gt;
I have also commented inside each file . You can learn from it. I have just given basic documentation. You can start building the application todolist.&lt;br&gt;
If you wish to build application other than todo list. You can just replace the codes. &lt;/p&gt;

&lt;h3&gt;
  
  
  ADDITIONAL INFORMATION
&lt;/h3&gt;

&lt;p&gt;Yes!!!!! We are done with the basics but there are lot to learn. &lt;br&gt;
The Index file in the project is the entry point of the application. To make it as entry point you have configure your server.&lt;br&gt;
.htaccess is the configuration file for web server running on web applications.&lt;/p&gt;

</description>
      <category>mvc</category>
      <category>oop</category>
      <category>php</category>
    </item>
    <item>
      <title>keyword definitions of oops(php)</title>
      <dc:creator>Ak</dc:creator>
      <pubDate>Wed, 05 Sep 2018 22:33:07 +0000</pubDate>
      <link>https://dev.to/ashok6266/keyword-definitions-of-oopsphp-55p9</link>
      <guid>https://dev.to/ashok6266/keyword-definitions-of-oopsphp-55p9</guid>
      <description>

&lt;p&gt;&lt;strong&gt;Class&lt;/strong&gt; -  A class is a user defined data type which has methods and properties. &lt;br&gt;
&lt;strong&gt;Object&lt;/strong&gt; - A object is a instance of a class, Once we define a class we can make many objects or instances.&lt;br&gt;
&lt;strong&gt;Methods&lt;/strong&gt; -     A function inside a class is called as methods &lt;br&gt;
&lt;strong&gt;Properties&lt;/strong&gt;  -  A variable inside a class is called as properties or also called as member variables.&lt;br&gt;
&lt;strong&gt;Inheritance&lt;/strong&gt; - The process of inheriting properties and methods from a base class or parent class is called Inheritance. The class that has inherited all the methods and properties is called as child class or derived class. &lt;br&gt;
&lt;strong&gt;Constructor&lt;/strong&gt; - Special type of function which is automatically called whenever object is formed.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Destructor&lt;/strong&gt; - Special type of function which is automatically called whenever object is formed. The constructor and destructor are also called as magic methods. &lt;br&gt;
&lt;strong&gt;Private&lt;/strong&gt; - A private member can be used only inside a class in which it has been declared. Private members cannot be used inside the inherited classes. &lt;br&gt;
&lt;strong&gt;Protected&lt;/strong&gt; - Protected members can be used inside the same class and class that inherits the parent class. &lt;br&gt;
&lt;strong&gt;Constant&lt;/strong&gt; - The constants are immutable , once it is declared it cannot be changed. It is declared using a keyword const.&lt;br&gt;
&lt;strong&gt;Abstract classes&lt;/strong&gt; - These classes cannot be instantiated instead it can be inherited. &lt;br&gt;
&lt;strong&gt;$this&lt;/strong&gt; - To access a property inside a class $this keyword is used.&lt;br&gt;
&lt;strong&gt;Static&lt;/strong&gt; -  Static methods and properties can be accessed without instantiating a class&lt;br&gt;
&lt;strong&gt;::&lt;/strong&gt; - It is scope resolution operator used to access the static , constant and overridden properties and methods of a class&lt;/p&gt;


</description>
      <category>phpoops</category>
    </item>
  </channel>
</rss>
