<?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 Bharathy Poovalingam on Medium]]></title>
        <description><![CDATA[Stories by Bharathy Poovalingam on Medium]]></description>
        <link>https://medium.com/@bharathy.poovalingam?source=rss-c4a022688382------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wrTE4pf_LpWGWccSvY5cfg.jpeg</url>
            <title>Stories by Bharathy Poovalingam on Medium</title>
            <link>https://medium.com/@bharathy.poovalingam?source=rss-c4a022688382------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:27:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bharathy.poovalingam/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[Langchain with NodeJS ( Part 1 )]]></title>
            <link>https://medium.com/@bharathy.poovalingam/langchain-basics-with-nodejs-part-1-a0163e463c18?source=rss-c4a022688382------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0163e463c18</guid>
            <dc:creator><![CDATA[Bharathy Poovalingam]]></dc:creator>
            <pubDate>Tue, 02 Sep 2025 07:04:01 GMT</pubDate>
            <atom:updated>2025-09-02T10:31:39.481Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*J7uglfevDkenkpHCiN_y2Q.png" /></figure><h3>LangChain</h3><p><strong>LangChain</strong> is a framework for developing applications powered by large language models (LLMs).</p><p>LangChain simplifies every stage of the LLM application lifecycle:</p><ul><li><strong>Development</strong>: Build your applications using LangChain’s open-source <a href="https://python.langchain.com/docs/concepts/">components</a> and <a href="https://python.langchain.com/docs/integrations/providers/">third-party integrations</a>. Use <a href="https://python.langchain.com/docs/concepts/architecture/#langgraph">LangGraph</a> to build stateful agents with first-class streaming and human-in-the-loop support.</li></ul><h3>BootStrap</h3><p>To bootstrap the NodeJS project, Create Project name with folder say “langchain-spike”</p><p>Run Command : npm init -y</p><p>This will bootstrap the nodejs project with package.json where you can see the list of dependencies ( added in the project )</p><p>To define LLM (LargeLanguageModel ) and invoke it with LangChain, below modules to be installed</p><ul><li>LangChain</li><li>OpenAI</li><li>nodemon ( For Monitoring )</li></ul><p>Above mentioned modules can be installed using NPM ( node package manager ) by running below commands</p><pre>    npm i langchain @langchain/openai<br>    npm i dotenv<br>    npm i nodemon --save-dev</pre><h3>LangChain Blocks</h3><h3>LLM ( Model )</h3><p>To interact with LLM, we need to define a model. This model can be from OpenAI, Claude, Meta etc.</p><p>For instance, let’s say we need to define a model supported by OpenAI , eg ChatOpenAI</p><p>To import this model, need to install dependency ‘@langchain/openai’ by running below command</p><pre>Dependency Install<br>npm i langchain @langchain/openai<br><br>Import Dependency<br>import { ChatOpenAI } from &quot;@langchain/openai&quot;;</pre><p>Then model can be defined by providing the modelName, API Key to access the model and other parameters like temperature ( used to control the generation, varies between 0 to 1 , 1 being more imaginative and 0 being more relevant )</p><pre>const model = new ChatOpenAI({<br><br>    model : &quot;gpt-3.5-turbo&quot;,<br>    openAIApiKey : OPENAI_API_KEY,<br>    temperature : 0.6,<br>    maxTokens : 100,<br>    verbose : false<br>    <br>});</pre><h3>Configure OpenAI Key</h3><p>Navigate to the page : <a href="https://platform.openai.com/api-keys">https://platform.openai.com/api-keys</a> , and after login, we can create key using Create new Secret Key</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EpiLzk5UjWdR8ZGkLkMpNw.png" /></figure><p>Once the key is created, then that key can be used in the model as shown in above section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*nmIrb3lSaczoUqF9m7dMJA.png" /></figure><p>As a good practice, good to have this key copied to .env file in your NodeJS project</p><p>Then same key can be imported using the dotenv module in NodeJS</p><pre>// Install Dependency<br>    npm i dotenv<br>    <br>import * as dotenv from &#39;dotenv&#39;  // import<br><br>// Accessing the value<br>dotenv.config();<br>const OPENAI_API_KEY = process.env.OPENAI_API_KEY;</pre><h3>Invoking the Model</h3><p>Model once configured with model name and providing the API Key, can be invoked via</p><ul><li>invoke method</li><li>batch method</li><li>stream method</li></ul><pre>const model = new ChatOpenAI({<br><br>    model : &quot;gpt-3.5-turbo&quot;,<br>    openAIApiKey : OPENAI_API_KEY,<br>    temperature : 0.6,<br>    maxTokens : 100,<br>    verbose : false<br>    <br>});<br><br>const response = await model.invoke(&#39;What is LLM?&#39;);</pre><h3>Logging</h3><p>Response of invoking the model and by logging</p><pre>const response = await model.invoke(&#39;What is LLM?&#39;);<br>console.log(response);</pre><h3>Prompt Template</h3><p>Instead of hard coding the query/prompt to the model ,as in above example where the question is hardcoded, we can construct the prompt template with placeholders and placeholders can be replaced with the user queries dynamically.</p><p>To configure prompt template , need to import ChatPromptTemplate like below</p><pre>import {ChatPromptTemplate} from &#39;@langchain/core/prompts&#39;</pre><h3>Configure</h3><p>To configure the prompt template, it can be done in two ways</p><ul><li>fromTemplate</li><li>fromMessages</li></ul><pre>const prompt = ChatPromptTemplate.fromTemplate(&#39;You are a tourist guide. Tell me some historical information about place : {input}&#39;);</pre><h3>Invoke</h3><p>We have defined the prompt template as above and keeping the placeholder (input) for user to pass in to get historical information about any place he likes</p><p>For example, he can ask for insights about Melbourne, by passing the input value as below</p><pre>// Construct the Chain<br><br>const chain = prompt.pipe(model);<br><br>// Invoke the chain, passing the prompt value<br><br>const response = await chain.invoke({<br>    input :&#39;Melbourne&#39;<br>});</pre><h3>Output Parsers</h3><p>Ouput Parsers can be configured in the LangChain to format the response in a way its more readable and structured</p><p>Types of Output Parsers</p><ul><li>StringOutputParser</li><li>CommaSeparatedListOutputParser</li><li>StructuredOutputParser</li></ul><pre>// To import the parser<br>import { StringOutputParser,CommaSeparatedListOutputParser } from &#39;@langchain/core/output_parsers&#39;</pre><p>​</p><h3>StringOutputParser</h3><p>Configure the String Output Parser as below and chain it to the prompt as below</p><pre> const prompt = ChatPromptTemplate.fromTemplate(&#39;You are a tourist guide. Tell me some historical information about place {input}&#39;);<br>    / construct the parser<br>    const parser = new StringOutputParser();<br><br>    // Construct the Chain with Parser<br><br>    const chain = prompt.pipe(model).pipe(parser);<br><br>    // Invoke the chain, passing the prompt value<br><br>    return await chain.invoke({<br>        input :&#39;Melbourne&#39;<br>    });</pre><h3>CommaSeparatedListOutputParser</h3><p>If the response from LLM is going to be list of values, and it needs to be formatted properly, then CommaSeparatedListOutputParser can be used,as below</p><pre>const prompt = ChatPromptTemplate.fromTemplate(`<br>        Provide 5 Synonyms for the following word {word}`<br>    );<br><br>    // construct the ListOutputParser<br><br>    const listParser = new CommaSeparatedListOutputParser();<br><br>    // construct the chain with Parser<br><br>    const chain = prompt.pipe(model).pipe(listParser);<br><br>    // Invoke the chain with prompt value<br><br>    return await chain.invoke({<br>        input : &#39;Excellent&#39;<br>    })</pre><h3>StructuredOutputParser</h3><p>This parser can be imported from package : langchain/core/output_parsers and its widely used in Production for formatting the response(JSON)</p><pre>import { StructuredOutputParser } from &quot;@langchain/core/output_parsers&quot;;</pre><ul><li>fromNamesAndDescriptions</li><li>fromZodSchema</li></ul><h4>fromNamesAndDescriptions</h4><p>This structured output parser is used to format the response that has two fields say Name and Description as captured below</p><pre>const prompt = ChatPromptTemplate.fromTemplate(`<br>         Extract information from the following phrase.<br>         Formatting Instructions : {format_instructions}<br>         Phrase : {phrase}<br>        `);<br>    <br>    <br>    const outputParser = StructuredOutputParser.fromNamesAndDescriptions({<br>        name : &quot;The Name of the person&quot;,<br>        age :&quot;Age of the person&quot;<br>    })<br>    <br>    const chain = prompt.pipe(model).pipe(outputParser);<br><br>    return await chain.invoke({<br>        phrase : &quot;Sachin is 40 years old&quot;,<br>        format_instructions : outputParser.getFormatInstructions(),<br>    });</pre><h4>fromZodSchema</h4><p>This parser can be used for formatting the response in a very customized way through Zod Object (z.object({}))</p><pre>// define the prompt<br><br>    const prompt = ChatPromptTemplate.fromTemplate(`<br>         Extract information from the following phrase.<br>         Formatting Instructions : {format_instructions}<br>         Phrase : {phrase}<br>        `);<br>    <br>    <br>    const outputParser = StructuredOutputParser.fromZodSchema(<br>        z.object({<br>            recipe : z.string().describe(&quot;name of recipe&quot;),<br>            ingredients: z.array(z.string()).describe(&quot;ingredients&quot;),<br>        })<br>    )<br>    <br>    const chain = prompt.pipe(model).pipe(outputParser);<br><br>    return await chain.invoke({<br>        phrase : &quot;The ingredients for making Madurai Parotta is Maida flour, salt, butter, oil and ghee&quot;,<br>        format_instructions : outputParser.getFormatInstructions(),<br>    });</pre><h3>References</h3><p><a href="https://python.langchain.com/docs/introduction/?_gl=1*1e1zotc*_gcl_au*OTQxNDE3MjUuMTc1Njc5MzM0Mg..*_ga*MTcxMTA0MTYyMi4xNzU2NzkzMzQy*_ga_47WX3HKKY2*czE3NTY3OTMzNDIkbzEkZzAkdDE3NTY3OTMzNDIkajYwJGwwJGgw">https://python.langchain.com/docs/introduction/?_gl=1*1e1zotc*_gcl_au*OTQxNDE3MjUuMTc1Njc5MzM0Mg..*_ga*MTcxMTA0MTYyMi4xNzU2NzkzMzQy*_ga_47WX3HKKY2*czE3NTY3OTMzNDIkbzEkZzAkdDE3NTY3OTMzNDIkajYwJGwwJGgw</a></p><p>Github Repo <a href="https://github.com/bharathyfsai28/ai_learnings/tree/main/langchain-spike">https://github.com/bharathyfsai28/ai_learnings/tree/main/langchain-spike</a></p><p>Coursera : <a href="https://www.coursera.org/learn/fundamentals-of-ai-agents-using-rag-and-langchain">https://www.coursera.org/learn/fundamentals-of-ai-agents-using-rag-and-langchain</a></p><p>YouTube Material :</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FMaSynwSIty4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMaSynwSIty4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FMaSynwSIty4%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0624ffdc43db79c3bdb8646657d9417f/href">https://medium.com/media/0624ffdc43db79c3bdb8646657d9417f/href</a></iframe><p>#AgenticAI #LangChain #NodeJS #Learning</p><p><a href="https://www.linkedin.com/in/bharathy-poovalingam-09ab681a/">https://www.linkedin.com/in/bharathy-poovalingam-09ab681a/</a></p><p>To be Continued … (Part 2 )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0163e463c18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Employee Service (CRUD API) using NodeJS/Express with Postgres]]></title>
            <link>https://medium.com/@bharathy.poovalingam/employee-service-crud-api-using-nodejs-express-with-postgres-9ee23935acf6?source=rss-c4a022688382------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ee23935acf6</guid>
            <dc:creator><![CDATA[Bharathy Poovalingam]]></dc:creator>
            <pubDate>Fri, 15 Aug 2025 10:24:43 GMT</pubDate>
            <atom:updated>2025-08-15T10:24:43.186Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>This tutorial talks about developing routes/services to do CRUD APIs for employee management using NodeJS/Express having Postgres database for storing/retrieving the employees</p><p><strong>Required Modules</strong></p><p>Below modules to be installed as part of this API development</p><p>To bootstrap the project , create directory say employee-api and run command ‘npm init -y’ — This will bootstrap the NodeJS project with default project structure and with package.json</p><p>To install additional libraries like express, postgres, cors, joi need to run below command</p><pre>npm i express dotenv pg cors joi</pre><p>express — for creating Express App with NodeJS</p><p>pg — for Postgres Module</p><p>dotenv — to load the environment variables</p><p>cors — to support cross origin</p><p>joi — schema validation library for JavaScript</p><p>Once the required modules are installed with above command, package.json should look like below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DFwGPJ5PI1lfTEHr2GXZAg.png" /></figure><p><strong>Setting up the Express Server</strong></p><p>To setup the Express Server, inside index.js</p><pre>const express = require(&#39;express)<br>const port = process.env.PORT || 3001;<br>const app = express();<br>app.listen(port, () =&gt; {<br>    console.log(`nodejs server running on  ${port}`)<br>})</pre><p>This should start up the server and have the server listening to port 3001, <a href="http://localhost:3001/">http://localhost:3001</a></p><p><strong>Setting up Postgres Container</strong></p><p>Download Docker Desktop : <a href="https://docs.docker.com/desktop/setup/install/mac-install/">https://docs.docker.com/desktop/setup/install/mac-install/</a></p><p>Enable the terminal, and run command docker pull postgres</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*so14mFG7TrSnTfCPZhl1RQ.png" /></figure><p>Once the image is pulled, spin up the container with below command</p><pre>docker run --name employee-db -e POSTGRES_PASSWORD=welcome -p 5432:5432 -d postgres</pre><p>give the container name say employee-db and pass on the environment variables like POSTGRES_PASSWORD, PORT and run it in detached mode with command -d. This will bring up the container like below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kPhIkqyE4b2J2yFdCo5jZg.png" /></figure><p>Once the container is up and running, use any DB Client tool to connect to the DB and create database ‘employee-db’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*hqFKQoam_2wFMIAmLNl8cg.png" /></figure><p><strong>Checking up the NodeJS connection to Postgres</strong></p><p>Create folder structure like below with modules for</p><p>router, config, models,middlewares, data, controllers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*G2B6heRAQ0gpJ2aJjPw8pA.png" /></figure><p>Create file called .env to hold the environment variables and have db.js file to create Pool and to connect to the db</p><pre>### .env file<br>PORT=5001<br>DB_USER=&quot;postgres&quot;<br>DB_PWD=&quot;welcome&quot;<br>DB_PORT=5432<br>DB_NAME=&quot;employee-db&quot;<br><br><br>### db.js file<br>const pkg = require(&#39;pg&#39;)<br>const { Pool } = pkg;<br>const dotenv = require(&#39;dotenv&#39;).config()<br><br>const pool = new Pool ({<br>    user: process.env.DB_USER,<br>    host : process.env.DB_HOST,<br>    password : process.env.DB_PWD,<br>    database : process.env.DB_NAME,<br>    port : process.env.DB_PORT<br><br>})<br><br>pool.on(&quot;connnect&quot; , ()=&gt;{<br>    console.log(&quot;Connection Pool established with DB&quot;)<br>})<br>module.exports = pool<br><br><br>### index.js file , import this db.js file in index.js<br><br>const dotenv = require(&#39;dotenv&#39;).config()<br>const pool = require(&#39;./config/db.js&#39;)<br><br>app.get(&quot;/&quot;, async (req,res)=&gt; {<br>    result = await pool.query(&quot;SELECT current_database()&quot;)<br>    res.send(` The database name is :${result.rows[0].current_database}`)<br>    console.log()<br>})<br></pre><p>In index.js file, import the db.js file and the env file can be accessed through loaddotenv module and have the simple route (app.get(‘/’)) to test the connection, and run the query using Pool libray as shown above and send the database name in the response and hit the below endpoint</p><p>Then hit on <a href="http://localhost:5001/">http://localhost:5001</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*XN8cGtCumAzHuSet_36SqA.png" /></figure><p>this shows the app got connected to db successfully, now lets get into the real meat of configuring the models, routes and controllers to create an employee, fetch an employee by id, get all employees, update employee and delete one.</p><p>To create table, on application startup , have one js file called createEmployeeTable.js , this will create the table employees</p><pre>import pool from &quot;../config/db.js&quot;;<br><br>export const createEmployeeTable = async() =&gt; {<br>    const queryText = `CREATE TABLE IF NOT EXISTS employees (<br>    id SERIAL PRIMARY KEY,<br>    name VARCHAR(100) NOT NULL,<br>    email VARCHAR(100) UNIQUE NOT NULL,<br>    created_at TIMESTAMP DEFAULT NOW()<br>)`;<br>    try {<br>        pool.query(queryText);<br>        console.log(&quot;Employee table created if not exists&quot;)<br>    } catch (error) {<br>        console.log(&quot;Exception in creating employee table&quot;)<br>    }<br>};</pre><p>Inside model directory, create file called employeeModel.js and have the queries constructed for doing CRUD operation</p><pre>import pool from &quot;../config/db.js&quot;;<br>export const getAllEmployeesService = async() =&gt; {<br>    const result = await pool.query(&quot;SELECT * from employees&quot;)<br>    return result.rows;<br><br>};<br><br>export const getEmployeeByIdService = async(id) =&gt; {<br>    console.log(&quot;Getting employee by id&quot;,id)<br>    const result = await pool.query(&quot;SELECT * from employees where id=$1&quot;,[id])<br>    return result.rows[0];<br>};<br><br>export const updateEmployeeByIdService = async(id,name, email) =&gt; {<br>    const result = await pool.query(<br>        &quot;UPDATE employees set name=$1, email=$2 where id=$3) RETURNING *&quot;, [name,email,id]<br>    );<br>    return result.rows[0]<br>};<br><br>export const deleteEmployeeByIdService = async(id) =&gt; {<br>    const result = await pool.query(<br>        &quot;DELETE FROM employees where id=$1 RETURNING *&quot;, [id]<br>    );<br>    return result.rows[0]<br>};<br><br>export const createEmployeeService = async(name, email) =&gt; {<br>    const result = await pool.query(<br>        &quot;INSERT INTO employees(name,email) VALUES($1, $2) RETURNING *&quot;, [name,email]<br>    );<br>    return result.rows[0]<br>};<br><br></pre><p>And have the routes configured in employeeRoutes.js under routes directory for below endpoints</p><p>/employees — GET, /employees/:id(employees get by id), /employees/:id (PUT), /employees/:id(DELETE), /employees(POST)</p><pre>const express = require(&#39;express&#39;)<br>const router = express.Router()<br>const { createEmployee, getAllEmployees, getEmployeeById, updateEmployee, deleteEmployeeById } = require(&#39;../controllers/employeeController.js&#39;);<br><br>router.post(&quot;/employees&quot;, createEmployee);<br>router.get(&quot;/employees&quot;,getAllEmployees);<br>router.get(&quot;/employees/:id&quot;, getEmployeeById);<br>router.put(&quot;/employees/:id&quot;, updateEmployee);<br>router.delete(&quot;/employess/:id&quot;, deleteEmployeeById);<br><br><br>module.exports = router</pre><p>Configure controllers to do orchestration for the endpoints configured in routes as below</p><pre>// standardized response function<br><br>import { createEmployeeService, deleteEmployeeByIdService, getAllEmployeesService, getEmployeeByIdService, updateEmployeeByIdService } from &quot;../models/employeeModel.js&quot;;<br><br><br>const handleResponse = (res,status, msg, data =null)=&gt; {<br>    res.status(status).json({<br>        status,<br>        msg,<br>        data,<br>    });<br>};<br><br>export const createEmployee = async(req,res, next) =&gt; {<br>    const { name, email} = req.body;<br>    try {<br>        const newEmployee = await createEmployeeService(name, email);<br>        handleResponse(res, 201, &quot;Employee Created Successfully&quot;, newEmployee)<br>    } catch (error) {<br>        next(error);<br>    }<br>};<br><br>export const getAllEmployees = async(req,res, next) =&gt; {<br>    try {<br>        const employees = await getAllEmployeesService();<br>        handleResponse(res, 200, &quot;Employees Retrieved Successfully&quot;, employees)<br>    } catch (error) {<br>        next(error);<br>    }<br>};<br><br>export const getEmployeeById = async(req,res, next) =&gt; {<br>    try {<br>        const id = req.params.id;<br>        const employee = await getEmployeeByIdService(id);<br>        if(!employee) return handleResponse(res,404, &quot;Employee not found&quot;)<br>        handleResponse(res, 200, &quot;Employee Retrieved Successfully&quot;, employee)<br>    } catch (error) {<br>        next(error);<br>    }<br>};<br><br>export const deleteEmployeeById = async(req,res, next) =&gt; {<br>    try {<br>        const id = req.params.id;<br>        const deletedEmployee = await deleteEmployeeByIdService(id);<br>        if(!deleteEmployee) return handleResponse(res, 404, &quot;Employee not found&quot;)<br>        handleResponse(res, 200, &quot;Employee deleted Successfully&quot;, deletedEmployee)<br>    } catch (error) {<br>        next(error);<br>    }<br>};<br><br>export const updateEmployee = async(req,res, next) =&gt; {<br>    try {<br>        const id = req.params.id;<br>        const { name, email} = req.body<br>        const updatedEmployee = await updateEmployeeByIdService(id,name, email);<br>        if(!employee) return handleResponse(res,404, &quot;Employee not found&quot;)<br>        handleResponse(res, 200, &quot;Employee updated Successfully&quot;, updatedEmployee)<br>    } catch (error) {<br>        next(error);<br>    }<br>};</pre><p>And have the middleware configured in middleware directory , middleware.js to handle errorHandling</p><pre>// Simple Centralized Error Handler<br><br>const errorHandling = (err,req,res, next)=&gt; {<br>    console.log(err.stack);<br>    res.status(500).json({<br>        status: 500,<br>        message:&quot;Something went wrong&quot;,<br>        error: err.message<br>    })<br>}<br><br>module.exports = errorHandling</pre><p>Then the complete index.js file would look like below</p><pre>const express = require(&#39;express&#39;)<br>const cors = require(&#39;cors&#39;)<br>const dotenv = require(&#39;dotenv&#39;).config()<br>const pool = require(&#39;./config/db.js&#39;)<br>const employeeRoutes = require(&#39;./routes/employeeRoutes.js&#39;)<br>const errorHandling = require(&#39;./middlewares/errorHandler.js&#39;)<br>const { createEmployeeTable } = require(&#39;./data/createEmployeeTable.js&#39;)<br><br>const app = express();<br>const port = process.env.PORT || 3001;<br>const db_name = process.env.DB_NAME <br>const db_port = process.env.DB_PORT <br>const db_user = process.env.DB_USER<br>const db_pwd = process.env.DB_PWD<br><br>// middleware<br><br>app.use(express.json())<br>app.use(cors())<br>app.use(errorHandling)<br><br>// bootstrap the db<br>createEmployeeTable()<br><br><br>// setting up the routes<br>app.use(&quot;/api&quot;, employeeRoutes)<br><br>app.get(&quot;/&quot;, async (req,res)=&gt; {<br>    result = await pool.query(&quot;SELECT current_database()&quot;)<br>    res.send(` The database name is :${result.rows[0].current_database}`)<br>    console.log()<br>})<br>// starting up the server<br><br>app.listen(port, () =&gt; {<br>    console.log(db_pwd)<br>    console.log(`nodejs server running on  ${port}`)<br>})</pre><p>Test the endpoints using Postman as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y1KBDRCp_DIlDTZQhF6cKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tci7-Ev5ggQOukw7uk6Fog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3dFCn0xeFLJqxK7MU-LzAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3dFCn0xeFLJqxK7MU-LzAg.png" /></figure><p>Bharathy Poovalingam</p><p><a href="https://www.linkedin.com/in/bharathy-poovalingam-09ab681a/">https://www.linkedin.com/in/bharathy-poovalingam-09ab681a/</a></p><p>References:</p><p><a href="https://github.com/bhanikki28/NodeJS_Learning/tree/master/employee-api">https://github.com/bhanikki28/NodeJS_Learning/tree/master/employee-api</a></p><p>#NodeJS #PostgreSQL #Express #AsyncProcessing #Middleware #Postman</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ee23935acf6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Series : Machine Learning/GenAI with Python]]></title>
            <link>https://medium.com/@bharathy.poovalingam/series-machine-learning-genai-with-python-e46290460455?source=rss-c4a022688382------2</link>
            <guid isPermaLink="false">https://medium.com/p/e46290460455</guid>
            <category><![CDATA[gen-ai-tools]]></category>
            <category><![CDATA[machine-learning-python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Bharathy Poovalingam]]></dc:creator>
            <pubDate>Wed, 23 Apr 2025 11:26:14 GMT</pubDate>
            <atom:updated>2025-04-23T11:26:14.042Z</atom:updated>
            <content:encoded><![CDATA[<h3>Series : Machine Learning/GenAI with Python</h3><h3>Introduction to Machine Learning</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W1K4i0tGZytRXOySn82WgA.png" /><figcaption>Machine Learning Overview</figcaption></figure><p>Machine learning (ML) is a branch of artificial intelligence (AI) that focuses on building systems that can learn from data and improve their performance over time without being explicitly programmed.</p><h3>In Simple Terms:</h3><p>Machine learning is about teaching computers to <strong>learn patterns from data</strong> so they can make decisions or predictions without being manually coded for every scenario.</p><h3>Supervised Learning</h3><p>Supervised learning is a type of machine learning where the model is trained on a labeled dataset. In this context, “labeled” means that each training example is paired with an output label or value. The goal of the model is to learn a mapping from inputs to outputs, so it can accurately predict the output for new, unseen data.</p><h3><strong>Key Concepts</strong></h3><p><strong>Input (Features)</strong>: The data you give the model (e.g., age, income, education level).</p><p><strong>Output (Labels)</strong>: The correct result you want the model to learn to predict (e.g., whether someone buys a product or not).</p><p><strong>Training</strong>: The process of feeding input-output pairs to the model so it can learn the relationship between them.</p><h3>Types of Supervised Learning:</h3><p><strong>Classification</strong>: The output is a category or class.</p><ul><li>Example: Spam detection (spam vs. not spam)</li><li>Algorithms: Logistic Regression, Decision Trees, Support Vector Machines, Neural Networks</li></ul><p><strong>Regression</strong>: The output is a continuous value.</p><p>Example: Predicting house prices</p><p>Algorithms: Linear Regression, Ridge Regression, SVR, Random Forest Regression</p><h3>Advantages:</h3><ul><li>Model learns from known data, so performance can be measured.</li><li>It’s easier to evaluate and tune models when correct answers are known.</li></ul><h3>Disadvantages:</h3><ul><li>Requires a large amount of labeled data, which can be expensive or time-consuming to obtain.</li><li>May not generalize well to unseen data if the training set isn’t diverse enough.</li></ul><h3>UnSupervised Learning</h3><p>Unsupervised learning is a type of machine learning where the model learns patterns from <strong>unlabeled data</strong> — meaning the data has <strong>no predefined outputs or categories</strong>. The goal is to explore the structure of the data to find hidden patterns or groupings.</p><p><strong>Clustering</strong></p><ul><li>Group similar data points together.</li><li>Example: Segmenting customers into different groups based on purchase behavior.</li><li>Algorithms: K-Means, DBSCAN, Hierarchical Clustering</li></ul><p><strong>Dimensionality Reduction</strong></p><ul><li>Simplify data by reducing the number of features while preserving essential patterns.</li><li>Example: Visualizing high-dimensional data in 2D or 3D.</li><li>Algorithms: PCA (Principal Component Analysis), t-SNE</li></ul><p><strong>Association Rule Learning</strong></p><ul><li>Find interesting relationships or patterns between variables.</li><li>Example: Market basket analysis (people who buy bread also buy butter).</li><li>Algorithms: Apriori, Eclat</li></ul><h3>Machine Learning Libraries in Python</h3><p>Python has a <strong>rich ecosystem</strong> of machine learning libraries that make it a top choice for ML development. Here’s a list of the most popular and widely used ones:</p><p><strong>Scikit-learn</strong></p><ul><li>Best for: Classical ML algorithms (regression, classification, clustering)</li><li>Features: Easy-to-use, great for beginners and prototyping</li><li>Link: <a href="https://scikit-learn.org/">scikit-learn.org</a></li></ul><p><strong>TensorFlow</strong></p><ul><li>Best for: Deep learning and neural networks</li><li>Developed by: Google</li><li>Features: Highly scalable, production-ready</li><li>Link: <a href="https://www.tensorflow.org/">tensorflow.org</a></li></ul><p><strong>PyTorch</strong></p><ul><li>Best for: Deep learning, research, dynamic computation graphs</li><li>Developed by: Facebook AI Research</li><li>Features: More “pythonic” and intuitive for debugging</li><li>Link: <a href="https://pytorch.org/">pytorch.org</a></li></ul><h3>📊 Data Handling and Preprocessing</h3><p><strong>NumPy</strong></p><ul><li>Fast array computations</li><li>Foundation of many ML libraries</li></ul><p><strong>Pandas</strong></p><ul><li>Data manipulation and analysis</li><li>Great for tabular data (like spreadsheets or CSVs)</li></ul><p><strong>Matplotlib / Seaborn / Plotly</strong></p><ul><li>For data visualisation</li></ul><h3>🤖 Specialised or Advanced Libraries</h3><p><strong>XGBoost / LightGBM / CatBoost</strong></p><ul><li>Gradient boosting libraries for structured/tabular data</li><li>Known for high performance in competitions (like Kaggle)</li></ul><p><strong>Keras</strong></p><ul><li>High-level API for building neural networks</li><li>Runs on top of TensorFlow (now fully integrated into it)</li></ul><p><strong>Hugging Face Transformers</strong></p><ul><li>Pre-trained models for NLP (BERT, GPT, etc.)</li><li>Easy-to-use interface for text classification, translation, etc.</li><li>Link: <a href="https://huggingface.co/">huggingface.co</a></li></ul><p><strong>spaCy / NLTK / Gensim</strong></p><ul><li>Natural Language Processing (NLP) libraries</li><li>Used for tokenization, parsing, topic modeling, etc.</li></ul><p>Keep Learning and keep in touch @ <a href="https://www.linkedin.com/in/bharathy-poovalingam-09ab681a/">https://www.linkedin.com/in/bharathy-poovalingam-09ab681a/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e46290460455" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[API Gateway Integration with SQS]]></title>
            <link>https://medium.com/@bharathy.poovalingam/api-gateway-integration-with-sqs-6ac157e040f5?source=rss-c4a022688382------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ac157e040f5</guid>
            <category><![CDATA[api-gateway-pattern]]></category>
            <dc:creator><![CDATA[Bharathy Poovalingam]]></dc:creator>
            <pubDate>Sat, 03 Jun 2023 05:04:53 GMT</pubDate>
            <atom:updated>2023-06-03T05:04:53.565Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ENClbXaEJq3FjD4HgDVSAg.png" /></figure><p>To have a micro-service, say OrderService to push event to SQS via API-Gateway, need to have the configuration as below using CloudFormation template</p><p>Components/Resources Involved for this usecase</p><ol><li>API Gateway</li><li>SQS</li><li>AWS WAF</li><li>AWS IAM Role to define policy</li><li>Cloudwatch Alarms ( to alert on failure )</li></ol><h3>APIGateway Configuration</h3><blockquote><em>Need to define a resource of Type:AWS::ApiGateway::RestApi to have API created in AWS Console</em></blockquote><pre>APIGateway<br>  Properties:<br>    EndpointConfiguration:<br>      Types:<br>        - REGIONAL<br>    Description: API Endpoint to process order events and push to SQS<br>    Name: !Sub order-service-api<br>  Type: AWS::ApiGateway::RestApi:</pre><h3>Policy Configuration</h3><p>AWS IAM Policies can be defined to allow API Gateway to push message to SQS</p><p>Note : OrderService-Policy is defined with pre-requisite access to required aws resources for OrderService</p><blockquote><em>Need to define a resource of Type:AWS::IAM::Role to have policies defined to allow API Gateway to access AWS Resource like SQS</em></blockquote><pre>ApiGatewayToSQSRole<br>  Type: AWS::IAM::Role<br>  Properties:<br>    Path: /basic/<br>    PermissionsBoundary: !Sub arn:aws:iam::${AWS::AccountId}:policy/OrderService-Policy<br>    MaxSessionDuration: 3600  # 1 hour<br>    AssumeRolePolicyDocument:<br>      Version: &#39;2012-10-17&#39;<br>      Statement:<br>        - Effect: Allow<br>          Principal:<br>            Service:<br>              - apigateway.amazonaws.com<br>          Action:<br>            - sts:AssumeRole<br>    RoleName: !Sub &quot;order-apigateway-to-sqs&quot;<br>    Policies:<br>      - PolicyName: ApiGatewayLogsPolicy<br>        PolicyDocument:<br>          Version: &#39;2012-10-17&#39;<br>          Statement:<br>            - Action: sqs:SendMessage<br>              Effect: Allow<br>              Resource: !GetAtt &#39;OrderEventQueue.Arn&#39;<br>            - Action:<br>                - logs:CreateLogGroup<br>                - logs:CreateLogStream<br>                - logs:DescribeLogGroups<br>                - logs:DescribeLogStreams<br>                - logs:PutLogEvents<br>                - logs:GetLogEvents<br>                - logs:FilterLogEvents<br>              Effect: Allow<br>              Resource: &quot;*&quot;<br>            - Action:<br>                - &#39;kms:Decrypt&#39;<br>                - &#39;kms:GenerateDataKey&#39;<br>                - &#39;kms:Encrypt&#39;<br>              Effect: Allow<br>              Resource: &quot;*&quot;:</pre><p>And on the SQS side, need to have policy defined to receive message from API</p><pre>OrderServiceQueuePolicy<br>  Type: AWS::SQS::QueuePolicy<br>  Properties:<br>    Queues:<br>      - !Ref OrderEventQueue<br>    PolicyDocument:<br>      Version: &#39;2012-10-17&#39;<br>      Statement:<br>        - Sid: order-api-send-msg-sqs<br>          Effect: Allow<br>          Principal:<br>            Service: &quot;apigateway.amazonaws.com&quot;<br>          Action:<br>            - SQS:SendMessage<br>            - logs:CreateLogGroup<br>            - logs:CreateLogStream<br>            - logs:DescribeLogGroups<br>            - logs:DescribeLogStreams<br>            - logs:PutLogEvents<br>            - logs:GetLogEvents<br>            - logs:FilterLogEvents<br>          Resource: !GetAtt OrderEventQueue.Arn:</pre><h3>API Method Configuration</h3><p>Configuring the API to refer to SQS Policy and wiring the Rest Call to SQS</p><p>And specifying the Content-Type and Mapping Template json</p><blockquote><em>Content-Type on Http-Headers should be ‘application/x-www-form-urlencoded and Mapping Template should be configured to encode the payload as Action=SendMessage&amp;MessageBody=$util.urlEncode($input.body)</em></blockquote><pre>PostMethod<br>  Properties:<br>    AuthorizationType: NONE<br>    HttpMethod: POST<br>    Integration:<br>      Credentials: !GetAtt &#39;ApiGatewayToSQSRole.Arn&#39;<br>      IntegrationHttpMethod: POST<br>      IntegrationResponses:<br>        - StatusCode: &#39;200&#39;<br>      PassthroughBehavior: NEVER<br>      RequestParameters:<br>        integration.request.header.Content-Type: &#39;&#39;&#39;application/x-www-form-urlencoded&#39;&#39;&#39;<br>      RequestTemplates:<br>        application/json: Action=SendMessage&amp;MessageBody=$util.urlEncode($input.body)<br>      Type: AWS<br>      Uri: !Join<br>        - &#39;&#39;<br>        - - &#39;arn:aws:apigateway:&#39;<br>          - !Ref &#39;AWS::Region&#39;<br>          - :sqs:path/<br>          - !Ref &#39;AWS::AccountId&#39;<br>          - /<br>          - !Sub order-event-queue<br>    MethodResponses:<br>      - ResponseModels:<br>          application/json: Empty<br>        StatusCode: &#39;200&#39;<br>    ResourceId: !Ref &#39;enqueueResource&#39;<br>    RestApiId: !Ref &#39;APIGateway&#39;<br>  Type: AWS::ApiGateway::Method:</pre><h3>WAF Configuration</h3><p>To secure the API, WAF can be configured in front of API Gateway to restrict the IPs to be allowed to access API</p><blockquote><em>Need to define resource of type ‘IPSet’ to have the list of ips to be allowed. Also have Web ACL defined to block by default and only allow the list of ips mentioned in IPSet configuration</em></blockquote><pre>IPSet:<br>  Type: &#39;AWS::WAFv2::IPSet&#39;<br>  Properties:<br>    Scope: &quot;REGIONAL&quot;<br>    IPAddressVersion: &quot;IPV4&quot;<br>    Addresses:<br>      - 192.168.*.*/*<br>WebAcl<br>    Type: &quot;AWS::WAFv2::WebACL&quot;<br>    Properties:<br>      Scope: &quot;REGIONAL&quot;<br>      Description: !Sub &quot;${AWS::StackName} allowed IPs&quot;<br>      DefaultAction:<br>        Block: {}<br>      VisibilityConfig:<br>        SampledRequestsEnabled: false<br>        CloudWatchMetricsEnabled: false<br>        MetricName: &quot;AllowedIPs&quot;<br>      Rules:<br>        - Name: &quot;Allow&quot;<br>          Priority: 0<br>          Action:<br>            Allow: {}<br>          VisibilityConfig:<br>            SampledRequestsEnabled: false<br>            CloudWatchMetricsEnabled: false<br>            MetricName: &quot;AllowedIPs&quot;<br>          Statement:<br>            IPSetReferenceStatement:<br>              Arn: !GetAtt IPSet.Arn<br>  <br>  WebAclAssociation:<br>    Type: AWS::WAFv2::WebACLAssociation<br>    Properties:<br>      WebACLArn: !GetAtt WebAcl.Arn<br>      ResourceArn: !Sub &quot;arn:aws:apigateway:${AWS::Region}::/restapis/${APIGateway}/stages/${apiStage}&quot;:</pre><p>Bharathy Poovalingam</p><p>#happy learning #iGreenData #aws #cloudformation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bp_2d2OvZqCcSXQHUtSo8A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ac157e040f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Boot Security with Okta]]></title>
            <link>https://medium.com/@bharathy.poovalingam/spring-boot-security-with-okta-ba987d80c5e6?source=rss-c4a022688382------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba987d80c5e6</guid>
            <dc:creator><![CDATA[Bharathy Poovalingam]]></dc:creator>
            <pubDate>Sat, 28 May 2022 03:41:13 GMT</pubDate>
            <atom:updated>2022-05-28T03:41:13.438Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>To integrate Spring Boot application with Okta, need to do below steps</p><pre>1. Sign Up Okta - developer.okta.com/signup<br>2. Create Application on Okta Porta <br>3. Bootstrap Spring Boot project with okta dependency<br>4. config files entry for okta</pre><p><strong>Okta Signing up</strong></p><p>Sign up with Okta through “developer.okta.com/signup/” using your work email address</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LyrKZ27Z0yHeOXogY6ebqA.png" /></figure><p>complete the email verification part as well</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTXQ-6eTnuApBuH56TrKLA.png" /></figure><p>Once the email verification is done, will be redirected to Okta portal as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6w8pwamm-9pBjG7gElk2Bw.png" /></figure><p>Now we need to configure the application in Okta portal</p><p>Click on Applications on the left hand panel, select the sign-in method and the application type ( Web , in this case we are going to have it for Java Application )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DW83d2rYaiIpktuzqW9Afw.png" /></figure><p>Give your app the name and the authorization access, you would like to have for the app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nn7WAortogJyozw7Da_gGA.png" /></figure><p>And in the next step, we should able to see the Client ID and Client Secret,that can be used in the application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k9ZrTKVOcK3u3r9MSLyiVA.png" /></figure><p>And click on Security -&gt; API, to get the authorization server ( to be used in SpringBoot app )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bGSlvRFHWIfpGMT22RVixA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rF01KJKAS5Xhp618uWcPIA.png" /></figure><p><strong>Application Changes</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ppp6REhdw3TVDQGFnq4CEA.png" /></figure><p>In application.properties, have config entries for Okta which we configured</p><pre># Okta related props<br>okta.oauth2.issuer=https://dev-19920738.okta.com/oauth2/default<br>okta.oauth2.client-id=0oa57kiahtTlHhTLd5d7<br>okta.oauth2.client-secret=h1o0SxFVV0Qr2q3omshQI_FHdh2c7zcRoqNuxOYx<br>okta.oauth2.redirect-uri=/authorization-code/callback</pre><p>Now if we hit the application <a href="http://localhost:8080/">http://localhost:8080</a></p><p>It should redirect to Okta login for authentication and then it will response back</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x2XR2GPugl7WU5i16bpHow.png" /></figure><p>Regards,</p><p>Bharathy Poovalingam</p><p>#iGreenData #SpringBoot #Okta #SpringSecurity</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*ZmFPkSQzcL27q8_rnOFEQQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba987d80c5e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS : ECS v FARGATE]]></title>
            <link>https://medium.com/@bharathy.poovalingam/aws-ecs-v-fargate-cb58d7bacae2?source=rss-c4a022688382------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb58d7bacae2</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Bharathy Poovalingam]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 08:23:26 GMT</pubDate>
            <atom:updated>2021-12-27T08:23:26.352Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*diCa-6erFl0tbDonLKqIng.png" /></figure><p><strong>Images:</strong></p><p>Docker is a build tool to create images based on the instructions specified in Dockerfile. Now if we need to run any application in containers, we need to create docker images and run it as Docker Container</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q9CeowR5Hy0g33q_wQBlNw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ddK3K8a_8-hssSHdMnQezQ.png" /></figure><p><strong>Containers:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZXiGpykKscp4tbu1n7Ijfw.png" /></figure><p><strong>Container Management:</strong></p><p>We need a container management platform to orchestrate/maintain the containers</p><ol><li>ECS ( <strong><em>Elastic Container Service</em></strong> ) , Amazon’s Own platform</li><li>Fargate , Amazon’s own serverless platform</li><li>EKS ( <strong><em>Elastic Kubernetes Service</em></strong> ), Opensource</li></ol><p><strong>ECS Clusters</strong></p><p>Logical grouping of EC2 Instances. EC2 instances run the Docker Container. It runs a special <strong><em>AMI ( Amazon Machine Image ) </em></strong>to support ECS !. This AMI machine type comes with preconfigured docker to run ECS. While creating ECS cluster, user can choose Fargate option ( Networking only) or EC2 plus Networking</p><p><strong>ECS Task Definition</strong></p><p>Task Definition in JSON format to instruct ECS , how to run a Docker Container.</p><p>It may contain Image Name, Port Mapping (Host Port :: Container Port), CPU and Memory required, Health check and networking information</p><p>Sample Task Definition file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9xsuj8DyCajZaYnXYgoTNQ.png" /></figure><p>Task Definition can be of type Fargate or EC2 ( it needs to be selected based on the cluster type selected above )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MpHXTU1KIBIipCXfHd7dlQ.png" /></figure><p><strong>ECS Service with Load Balancers</strong></p><p>ECS Service helps to run this task definition. It will maintain how many tasks should be running and how it should run across EC2 instances.</p><p>Launch type can be FARGATE or EC2. Then choose the task definition created earlier in the dropdown as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZcOXSt0jyu_spWvvfsYdpA.png" /></figure><p>ECS Service type can be of Replica ( where we have control over to specify the number of tasks to run ) and Daemon ( its automatic, we don’t have control over to specify the number of tasks )</p><p>ECS supports ALB ( Application Load Balancer ) to route traffic to various containers running on EC2 instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zPeCHjn3wTym75Y4K0mQtA.png" /></figure><p><strong>ECR</strong></p><p>ECR is a private Docker Image Repository ( AWS ). Access is controlled through IAM.</p><p>Images can be pushed into public repository ( Docker Hub ) or private repository ( <strong><em>Amazon ECR : Elastic Container Registry </em></strong>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l_1SAMoDGFbtTXFNlXUX2g.png" /></figure><p><strong>Dockerfile</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*S-_eYynyveBvofKhi8ub4g.png" /></figure><p><strong>Command</strong></p><p>docker build -t springio/gs-spring-boot-docker . This will create image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eym8wd3Tvc9ZfNIHrwJSnw.png" /></figure><p>This will create image as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LS2A5yzPTMM7WIvlInBPrQ.png" /></figure><p>Once images are created, we can push the image into AWS ECR ( Elastic Container Registry )</p><ol><li>Authenticate with AWS by running below command</li></ol><blockquote>aws ecr get-login-password — region region | docker login — username AWS — password-stdin aws_account_id.dkr.ecr.region.amazonaws.com</blockquote><p>2. Tag your image to ecr</p><blockquote>docker tag &lt;&lt;IMAGE_NAME&gt;&gt;aws_account_id.dkr.ecr.region.amazonaws.com/my-repository:tag</blockquote><p>docker push aws_account_id.dkr.ecr.region.amazonaws.com/my-repository:tag</p><p><strong>AWS Fargate</strong></p><p>Fargate is Serverless !!!</p><p>We don’t need to provision EC2 instances and just need to provide ECS task definition and AWS will run containers for us.</p><p>While creating the ECS Cluster, user can choose option as Fargate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r2Ee3yZdNlG76EEPCuyDZg.png" /></figure><blockquote>Today, 32% of AWS Container environments run on Fargate</blockquote><p><strong>Happy Learning !</strong></p><p>Bharathy Poovalingam</p><p><strong>#Learning #AWS #ECS #ECR #iGreenData</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*ZmFPkSQzcL27q8_rnOFEQQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb58d7bacae2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying MicroService on Kubernetes]]></title>
            <link>https://medium.com/@bharathy.poovalingam/deploying-microservice-on-kubernetes-92b6adc5ec59?source=rss-c4a022688382------2</link>
            <guid isPermaLink="false">https://medium.com/p/92b6adc5ec59</guid>
            <dc:creator><![CDATA[Bharathy Poovalingam]]></dc:creator>
            <pubDate>Sun, 07 Nov 2021 10:23:13 GMT</pubDate>
            <atom:updated>2021-11-07T10:23:13.797Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog is to demonstrate, how to deploy spring boot application into minikube cluster and access it</p><h3>Pre-requisites:</h3><p>Need to have Java, Docker and Minikube installed on mac</p><h3>Minikube Installation:</h3><p>Install minikube using brew command :</p><pre>brew install minikube<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C8H615LGzI15oV0d" /></figure><p>Start the minikube using below command</p><pre>minikube start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HkWVn4jW_7E9dXBT" /></figure><p>Please verify the status of minikube by running below command</p><pre>minikube status</pre><p>And to bring down the minikube, pls run below command</p><pre>minikube stop</pre><h3>Code Build :</h3><p>Package your application ( Spring Boot Microservice ) and using maven/gradle build tool to generate jar using particular command/task ( mvn clean install )</p><pre>Build:</pre><pre>docker build -t igd/spring-jpademo:1 ( Build and Tag )</pre><pre>Run:</pre><pre>Run the image to make sure, you can able to run the image and hit it<br>docker run -p 8080:8080 igd/spring-jpademo:1</pre><ul><li>Create a Dockerfile to build a image</li><li>Use docker build to tag a image ( which can be pushed to artifactory or container registry )</li><li>docker run to verify the image</li></ul><h3>Namespace:</h3><p>Before creating a deployment, can have namespace created to have deployments tagged to the namespace</p><pre>Namespace:<br>Syntax : kubectl create ns &lt;&lt;namespace_name&gt;&gt;<br>kubectl create ns igd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/0*xZUqjGIbJti2TwLw" /></figure><h3>Deployment:</h3><p>To create a deployment, need to have a deployment yaml file</p><pre>apiVersion: apps/v<br>kind: Deployment<br>metadata:<br>  creationTimestamp: null<br>  labels:<br>    app: employee-app<br>  name: employee-app<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: employee-app<br>  strategy: {}<br>  template:<br>    metadata:<br>      creationTimestamp: null<br>      labels:<br>        app: employee-app<br>    spec:<br>      containers:<br>      - image: igd/spring-jpademo:1<br>        name: employee-app<br>        imagePullPolicy: Never<br>        resources: {}<br>        ports:<br>          - containerPort: 8080<br>status: {}1</pre><p>Command to create a deployment and tag it to the namespace “igd” created before</p><pre>Deployment<br>kubectl create -f app_deploy.yml -n igd</pre><p>Verify the deployment is created and its running fine</p><pre>kubectl get deploy -n igd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ujjzk0I5D2W4Cpxg" /></figure><h3>Pods:</h3><p>Verify the pods are up and running by below command</p><pre>kubectl get pods -n igd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FBTllzASfskGjQBS" /></figure><h3>Services:</h3><p>Need to create service as type “LoadBalancer”, so that it can be accessed outside the cluster</p><pre>kubectl expose deployment employee-app -n igd --type=LoadBalancer --port=8080 </pre><pre>kubectl get services -n igd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MCnWOO1awh4hEW0i" /></figure><p>Please give some time for the external ip to popup, then you can able to access the services</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VAkqLiDfyRrxgdVm" /></figure><h3>Minikube Dashboard:</h3><pre>minikube dashboard</pre><p>Once the dashboard opens up, please choose the namespace from the dropdown, to view the services been deployed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1j9YkkxrB8MpiL7C" /></figure><p>To bring down the cluster, please run below command</p><pre>minikube service stop</pre><p>Bharathy Poovalingam</p><p>Happy Learning !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/0*uD8PGWeFQ6JL9OEq" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92b6adc5ec59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform]]></title>
            <link>https://medium.com/@bharathy.poovalingam/terraform-a27fc6dc1cdf?source=rss-c4a022688382------2</link>
            <guid isPermaLink="false">https://medium.com/p/a27fc6dc1cdf</guid>
            <dc:creator><![CDATA[Bharathy Poovalingam]]></dc:creator>
            <pubDate>Wed, 22 Sep 2021 09:35:37 GMT</pubDate>
            <atom:updated>2021-09-22T09:35:37.904Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction:</strong></p><p>Terraform are cloud agnostic unlike CloudFormation which is cloud native with AWS and AzureResourceManager which is native with Azure cloud provider. Terraform helps to maintain single codebase to maintain infrastructure related code to provision resources across multiple cloud providers.</p><h3>Setup:</h3><p>To install Terraform, need to download the binary from “<a href="https://www.terraform.io/downloads.html">https://www.terraform.io/downloads.html</a>&quot; and set it in PATH variable. Run ‘sudo mv terraform /usr/local/bin’.</p><blockquote>To verify the installation, please run the command <em>terraform — version</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*SsERwdFVMWc8J61z" /></figure><h3>IAC ( Infrastructure as Code )</h3><ol><li>Adhoc Scripts</li><li>Configuration Management Tools</li><li>Service Template Tools</li><li>Orchestration Tools</li><li>Service Provisioning Tools</li></ol><h3>AdHoc Scripts</h3><ol><li>General purpose programming language to write scripts</li><li>Good for small tasks and it’s not good for Complicated Tasks</li><li>Code can be messy, if we need to manage more servers, loadbalancers, here comes the advantage of IAC tools which provides features like IdemPotency and API support</li></ol><blockquote><em>“sudo apt-get update &amp;&amp; sudo apt-get install apache2 -y &amp;&amp; echo ‘&lt;!doctype html&gt;&lt;html&gt;&lt;body&gt;&lt;h1&gt;Adhoc Script to install Apache server !&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;’ | sudo tee /var/www/html/index.html”</em></blockquote><h3>Configuration Management Tools</h3><ol><li>Chef, Puppet, Ansible and SaltStack — Designed to install and manage softwares on existing servers</li><li>Enforce Coding Conventions and support for Idempotence</li><li>Good for managing large number of remote servers</li></ol><h3>Server Templating Tools</h3><ol><li>Docker, Packer and Vagrant</li><li>Create an image of a Server that captures everything ( OS, Software and files ) and use the Configuration Management tool like Ansible to install the image into multiple servers</li><li>Shift to Immutable infrastructure component</li></ol><h3>Orchestration Tools</h3><ol><li>Kubernetes,Nomad,Marathon/Mesos</li><li>Container Orchestration</li></ol><h3>Provisioning Tools</h3><ol><li>Terraform, CloudFormation (Specific to AWS), OpenStack Heat</li></ol><p>Add alt text</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/0*wymChkxYahZHvzl9" /></figure><h3>Approaches</h3><ol><li>Declarative vs Imperative</li><li>Immutable infrastructure vs Mutable Infrastructure</li></ol><h3>Terraform Files:</h3><p>To start with Terraform, we need to specify the providers for Infrastructure. It can be any cloud service providers GCP or AWS.</p><p>The file can be named as provider.tf and it may have the following content.</p><p>provider.tf</p><p>Add alt text</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/0*y_h0AGeLOMVVxYqw" /></figure><p>variables.tf:</p><p>Variables can be declared inside variables.tf file and can be refereed in resources or main.tf file. It can be created using keyword variable. It can have the default value and description key to it.</p><p>Add alt text</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/0*ZaajuzneKpgIvdgH" /></figure><h3>Terraform Commands:</h3><ol><li>terraform init ( To initialize the terraform )</li><li>terraform plan ( To plan or preview the changes )</li><li>terraform deploy ( To deploy or install the changes )</li><li>terraform destroy ( To destroy the resources once finished )</li><li>terraform fmt ( To do formatting )</li><li>terraform refresh ( to refresh the state )</li><li>terraform show ( to view the terraform.tfstate file )</li></ol><p>Happy Learning !</p><p>Bharathy Poovalingam</p><p>#GCP #Terraform #Service Template #Learning</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*qMfhQ6F2vTUshNhfk-MYCg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a27fc6dc1cdf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GCP Learning Series _ App Engine Part 3]]></title>
            <link>https://medium.com/@bharathy.poovalingam/gcp-learning-series-app-engine-part-3-8e4beca4c61?source=rss-c4a022688382------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e4beca4c61</guid>
            <dc:creator><![CDATA[Bharathy Poovalingam]]></dc:creator>
            <pubDate>Wed, 01 Sep 2021 01:38:11 GMT</pubDate>
            <atom:updated>2021-09-01T01:38:11.385Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Overview</strong></p><p>This blog will show how to deploy image from Container Registry to Google App Engine</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g_Zk4oqPAlfSUcIr5fyvDg.png" /></figure><p><strong>Configuration</strong></p><p>To deploy an app into App Engine, need to have app.yaml file configured as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*a9cfOGcOAnR05gS0MjhaLg.png" /></figure><p>Then run command :</p><blockquote><em>gcloud app deploy — image-url=gcr.io/gcpnikki/appengine/demo:latest</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jEWo7QS9SFTP-G1blHtSGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b5G97l4TsN-uTApqMb-lhQ.png" /></figure><p>After successful deployment, we can navigate to the AppEngine dashboard ( Instances/Services ) to review the changes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-34kKPoKiLRddfFqULt-zA.png" /></figure><blockquote><em>gcloud app browse</em></blockquote><p>Using gcloud app browse command to view the application been deployed and specify the endpoint been exposed, can able to hit the endpoints</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qxBVimjI_Qgq0-7frPx3ww.png" /></figure><p>Happy Learning !</p><p>Bharathy Poovalingam</p><p>#GCP #Learning #Serverless #AppEngine</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*qMfhQ6F2vTUshNhfk-MYCg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e4beca4c61" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GCP Learning Series _ App Engine Part 2]]></title>
            <link>https://medium.com/@bharathy.poovalingam/gcp-learning-series-app-engine-part-2-3f7d5b494ff1?source=rss-c4a022688382------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f7d5b494ff1</guid>
            <dc:creator><![CDATA[Bharathy Poovalingam]]></dc:creator>
            <pubDate>Tue, 24 Aug 2021 06:57:22 GMT</pubDate>
            <atom:updated>2021-08-24T06:57:22.293Z</atom:updated>
            <content:encoded><![CDATA[<p>Overview</p><p>This blog will show how to setup Cloud SDK in your local machine, configuring docker , create docker image and push it to Container Registry</p><p>Cloud SDK Installation</p><p><a href="https://cloud.google.com/sdk/docs/install">Install the gcloud CLI | Google Cloud SDK</a></p><p>To install Cloud SDK, Python3 is pre-requisite.</p><p>Please install Python, using brew</p><blockquote>brew install python3</blockquote><p>Then download the tar file : google-cloud-sdk-350.0.0-darwin-x86_64.tar</p><p>Unzip it and then run below command to do Cloud SDK installation</p><pre>./google-cloud-sdk/install.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P3_5_OoxK9wmVDpE9qqkBw.png" /></figure><p>Cloud Authentication</p><p>Need to run below command to do authentication</p><blockquote>gcloud auth login</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ArjlyXJISSACFkLr0VyrIQ.png" /></figure><p>the above command, will open up the gcloud console and need to give your consent there to access gcloud console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*thtq3sb7B-czADMqP5oqZQ.png" /></figure><p><strong>Building a sample application and push it to Container Registry</strong></p><p><a href="https://github.com/bhanikki28/GCPSamples/tree/master/AppEngineDemo">GCPSamples/AppEngineDemo at master · bhanikki28/GCPSamples</a></p><p>To build and dockerize the application, please refer to : <a href="https://medium.com/@bharathy.poovalingam/spring-boot-with-docker-d4129a353f87">https://medium.com/@bharathy.poovalingam/spring-boot-with-docker-d4129a353f87</a></p><p>Note : here , need to tag the image, that match to gcr registry as shown below</p><p>Syntax : gcr.io/PROJ_ID/folder/image_name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6u5UJgSDFuwrWOfUdxeIgA.png" /></figure><blockquote><strong>Authorizing Docker</strong></blockquote><p>Need to run below command to authorize docker to push image to Google Cloud Container Registry</p><blockquote><em>gcloud auth configure-docker</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bUbDYDEeEAkw3SNdbnOwbg.png" /></figure><blockquote><em>Pushing the image to Container Registry</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FXTehMCbYmNaZEeQ5C075w.png" /></figure><p>Login to gcloud console and navigate to Container Registry section, to view the image been pushed there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g_Zk4oqPAlfSUcIr5fyvDg.png" /></figure><p>to be continued… ( Deploying the image to Google App Engine )</p><p>Happy Learning !</p><p>Bharathy Poovalingam</p><p>#GCP #Learning #Serverless #AppEngine</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*qMfhQ6F2vTUshNhfk-MYCg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f7d5b494ff1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>