<?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: Rajesh Kumar</title>
    <description>The latest articles on DEV Community by Rajesh Kumar (@rajeshkumarbehura).</description>
    <link>https://dev.to/rajeshkumarbehura</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%2F393607%2F3b9af059-b9f1-4da1-9928-6ae0a958796e.jpeg</url>
      <title>DEV Community: Rajesh Kumar</title>
      <link>https://dev.to/rajeshkumarbehura</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajeshkumarbehura"/>
    <language>en</language>
    <item>
      <title>Using LLM, Postgres VectorDB, and OpenAI to Perform Semantic Search on PDF Documents</title>
      <dc:creator>Rajesh Kumar</dc:creator>
      <pubDate>Thu, 15 Feb 2024 05:30:37 +0000</pubDate>
      <link>https://dev.to/rajeshkumarbehura/using-llm-postgres-vectordb-and-openai-to-perform-semantic-search-on-pdf-documents-1hok</link>
      <guid>https://dev.to/rajeshkumarbehura/using-llm-postgres-vectordb-and-openai-to-perform-semantic-search-on-pdf-documents-1hok</guid>
      <description>&lt;h3&gt;
  
  
  Objective
&lt;/h3&gt;

&lt;p&gt;The goal of this project is to build a prototype app that can perform similarity search on PDF documents using VectorSearch (Postgres). The app will use the Langchain llm framework and OpenAI to extract and compare semantic vectors from the PDFs.&lt;/p&gt;

&lt;h3&gt;
  
  
  TechStack
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Postgres with VectorSearch (Run in docker)&lt;/li&gt;
&lt;li&gt;OpenAI (Create/Must have OpenAI key) : &lt;a href="https://openai.com/" rel="noopener noreferrer"&gt;https://openai.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Langchain LLM&lt;/li&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Source: &lt;a href="https://github.com/rajeshkumarbehura/pdf-reader-search" rel="noopener noreferrer"&gt;https://github.com/rajeshkumarbehura/pdf-reader-search&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Keywords to learn
&lt;/h3&gt;

&lt;p&gt;langchain framework, embeedding, vectorsearch or vector database, PVector, Document Loader&lt;/p&gt;

&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;p&gt;PDF is a common format for documents in organizations, and it is fascinating to test llm semantic search on PDFs.&lt;/p&gt;

&lt;p&gt;We used the book "Teach yourself Java in 21 days" for our testing.&lt;/p&gt;

&lt;p&gt;This app is a test case for extracting and embedding PDF content and storing it in a database. We use Postgres as the vector database and DBeaver as the database viewer. The PVector framework handles the data design and embedding process.&lt;/p&gt;

&lt;p&gt;Understand Steps -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extracted the PDF content and split it into a list of documents.&lt;/li&gt;
&lt;li&gt;Created a database connection string and used it for PGVector (framework class) to handle the creation of embeddings and push them into the database. If the table did not exist, it created it automatically.&lt;/li&gt;
&lt;li&gt;Loaded the documents and their embeddings into the database.&lt;/li&gt;
&lt;li&gt;Used Dbeaver tool to view the data and tables.(&lt;a href="https://dbeaver.io/" rel="noopener noreferrer"&gt;https://dbeaver.io/&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.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%2Frbyqrt3bnoqe0oop448p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Frbyqrt3bnoqe0oop448p.png" alt="Image description"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Wrote question for testing as 
&lt;code&gt;ask_question(query="What is Incrementing and Decrementing ?")&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note : For more search options, check out the langchain documentation on different methods such as &lt;br&gt;
&lt;code&gt;similarity_search&lt;/code&gt;&lt;br&gt;
&lt;code&gt;search&lt;/code&gt;&lt;br&gt;
&lt;code&gt;similarity_search_with_score&lt;/code&gt;&lt;br&gt;
Do more experiments on this functions and get better understanding.&lt;/p&gt;

&lt;h3&gt;
  
  
  Execution
&lt;/h3&gt;


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

&lt;ol&gt;
&lt;li&gt;Run postgess.yml using docker-compose command.&lt;/li&gt;
&lt;li&gt;Update openai_key in Reader.py file&lt;/li&gt;
&lt;li&gt;Run main function either to extract pdf file or search query.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Reference&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=zxo3T4aQj6Q&amp;amp;t=1224s" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=zxo3T4aQj6Q&amp;amp;t=1224s&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/pgvector/pgvector" rel="noopener noreferrer"&gt;https://github.com/pgvector/pgvector&lt;/a&gt; &lt;br&gt;
&lt;a href="https://python.langchain.com/docs/integrations/vectorstores/pgvector" rel="noopener noreferrer"&gt;https://python.langchain.com/docs/integrations/vectorstores/pgvector&lt;/a&gt;&lt;br&gt;
&lt;a href="https://python.langchain.com/docs/modules/data_connection/document_loaders/pdf" rel="noopener noreferrer"&gt;https://python.langchain.com/docs/modules/data_connection/document_loaders/pdf&lt;/a&gt;&lt;br&gt;
&lt;a href="https://python.langchain.com/docs/integrations/vectorstores/pgembedding" rel="noopener noreferrer"&gt;https://python.langchain.com/docs/integrations/vectorstores/pgembedding&lt;/a&gt;&lt;/p&gt;

</description>
      <category>langchain</category>
      <category>postgres</category>
      <category>vectordatabase</category>
      <category>llm</category>
    </item>
    <item>
      <title>Aws Cognito email Passwordless </title>
      <dc:creator>Rajesh Kumar</dc:creator>
      <pubDate>Sat, 10 Apr 2021 15:33:59 +0000</pubDate>
      <link>https://dev.to/rajeshkumarbehura/aws-cognito-email-passwordless-me8</link>
      <guid>https://dev.to/rajeshkumarbehura/aws-cognito-email-passwordless-me8</guid>
      <description>&lt;p&gt;For my project, I was looking for passwordless implementation and I found few ways but most of the ways look a bit confusing for me and took time to resolve the problem. I went through few reference documents, videos and finally summarize the steps, how to set up quickly using serverless &amp;amp; terraform scripts.&lt;/p&gt;

&lt;p&gt;Find the code's here : &lt;br&gt;
&lt;a href="https://github.com/rajeshkumarbehura/aws-cognito-passwordless"&gt;https://github.com/rajeshkumarbehura/aws-cognito-passwordless&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Description
&lt;/h1&gt;

&lt;p&gt;Implementation for user signup and login by email-id using the passwordless concept in AWS Cognito.&lt;/p&gt;
&lt;h1&gt;
  
  
  Deployment steps
&lt;/h1&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. deploy the lambda using a serverless framework.
2. deploy AWS Cognito &amp;amp; ses email account using terraform.
3. verify your email id for ses account.
4. set up lambda for Cognito triggers.
5. test the passwordless using AWS Cognito CLI commands.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Note: By default, this project was setup in "ap-southeast-1".
Set SES Email Id with your email id = &amp;lt;&amp;lt;SES_VERIFIED_EMAIL_ID&amp;gt;&amp;gt;
Make sure terraform's tf &amp;amp; serverless.yml files will be updated with the appropriate region and email id.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Check out the code from my github project "aws-cognito-passwordless". The link is provided above.&lt;/p&gt;

&lt;p&gt;Installation Requirement :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Serveless must be installed.
&lt;a href="https://www.serverless.com/framework/docs/getting-started/"&gt;https://www.serverless.com/framework/docs/getting-started/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Terraform must be installed.
&lt;a href="https://www.terraform.io/downloads.html"&gt;https://www.terraform.io/downloads.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;aws cli commands must be installed. 
&lt;a href="https://aws.amazon.com/cli/"&gt;https://aws.amazon.com/cli/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Setup aws default credential(aws_access_key_id,aws_secret_access_key) for local pc&lt;/li&gt;
&lt;li&gt;All the deployment will happen in AWS account default setting in pc.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  1. Deploy lambda
&lt;/h3&gt;

&lt;p&gt;Make sure my github project is cloned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Go to email-passwordless-lambda project.
2. Go to the serverless.yml file and replace &amp;lt;&amp;lt;SES_VERIFIED_EMAIL_ID&amp;gt;&amp;gt; with your email id.
3. Run the command "sls deploy".
4. It will set up 5 lambdas for your aws account.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Deploy Aws Cognito &amp;amp; ses email account
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Go to cognito-setup project folder
2. Go to variables.tf update your aws region and replace &amp;lt;&amp;lt;SES_VERIFIED_EMAIL_ID&amp;gt;&amp;gt; with your email id same as for lambda.
3. Run command "terraform init"
4. Run command "terraform plan"
5. Run command "terraform apply"  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Ses email account verification
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. After deployment, an email will be sent to your account &amp;lt;&amp;lt;SES_VERIFIED_EMAIL_ID&amp;gt;&amp;gt;. Go to your email account and verify the account. Note- without verification of email, email-passwordless will not work.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Setup lambdas for Cognito triggers.
&lt;/h3&gt;

&lt;p&gt;Now you login to AWS console and go to user pools in Cognito, select your own created user-pool and setup Triggers for user-pool as &lt;br&gt;
image link. &lt;br&gt;
&lt;a href="https://github.com/rajeshkumarbehura/aws-cognito-passwordless/blob/main/images/cognito-lambda-triggers.png"&gt;https://github.com/rajeshkumarbehura/aws-cognito-passwordless/blob/main/images/cognito-lambda-triggers.png&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Test passwordless email using aws cli command.
&lt;/h3&gt;

&lt;p&gt;Go to your user pool's App Clients and get your App client Id as in the below image link&lt;br&gt;
&lt;a href="https://github.com/rajeshkumarbehura/aws-cognito-passwordless/blob/main/images/app-clients-detail.png"&gt;https://github.com/rajeshkumarbehura/aws-cognito-passwordless/blob/main/images/app-clients-detail.png&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  1. User sign-up
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;&amp;lt;app-client-id&amp;gt;&amp;gt;
&amp;lt;&amp;lt;SES_VERIFIED_EMAIL_ID&amp;gt;&amp;gt;

Signup the user using cli command in your local system-   
aws cognito-idp sign-up --client-id &amp;lt;&amp;lt;app-client-id&amp;gt;&amp;gt;  --username &amp;lt;&amp;lt;SES_VERIFIED_EMAIL_ID&amp;gt;&amp;gt; -password 12345678

for exmaple - (it's only sample)
aws cognito-idp sign-up --client-id 4cgrq69gatdp03sa7k6  --username rajesh.xxx@gmail.com -password 12345678

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. User sign-in &amp;amp; send token to your email
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sign-in the user using cli command in your local system- 

aws cognito-idp initiate-auth --client-id &amp;lt;&amp;lt;app-client-id&amp;gt;&amp;gt; --auth-flow CUSTOM_AUTH --auth-parameters USERNAME="&amp;lt;&amp;lt;SES_VERIFIED_EMAIL_ID&amp;gt;&amp;gt;",PASSWORD=""

For exmaple - (it's only sample)
aws cognito-idp initiate-auth --client-id 568fqvgq612k636hho        --auth-flow CUSTOM_AUTH --auth-parameters USERNAME="rajesh.xxxxx@gmail.com",PASSWORD=""

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

&lt;/div&gt;



&lt;p&gt;Now here, your receive session value in your command line, and you will receive a token in your email account.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. User token validation
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;&amp;lt;SESSION_VALUE_FROM_SINGINE_COMMAND&amp;gt;&amp;gt; = get the value above command
&amp;lt;&amp;lt;TOKEN_FROM_EMAIL&amp;gt;&amp;gt; = get the token from email

Token validation using commandline in your system -

aws cognito-idp respond-to-auth-challenge --client-id &amp;lt;&amp;lt;app-client-id&amp;gt;&amp;gt; --challenge-name CUSTOM_CHALLENGE --challenge-responses ANSWER=&amp;lt;&amp;lt;TOKEN_FROM_EMAIL&amp;gt;&amp;gt;,USERNAME="&amp;lt;&amp;lt;SES_VERIFIED_EMAIL_ID&amp;gt;&amp;gt;"
--session "&amp;lt;&amp;lt;SESSION_VALUE_FROM_SINGINE_COMMAND&amp;gt;&amp;gt;"

for example - (it's only sample)
aws cognito-idp respond-to-auth-challenge --client-id 568fqvgq612k63 --challenge-name CUSTOM_CHALLENGE --challenge-responses ANSWER=780322,USERNAME="rajesh.XXXX@gmail.com"
--session "XXXXXXXXXXXXXXXXXXX....XXX"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the above command, you will recive jwt token and refresh token on your command line.&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=grTaNCwPj58"&gt;https://www.youtube.com/watch?v=grTaNCwPj58&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/aws-samples/amazon-cognito-passwordless-email-auth"&gt;https://github.com/aws-samples/amazon-cognito-passwordless-email-auth&lt;/a&gt;&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>terraform</category>
      <category>aws</category>
      <category>passwordless</category>
    </item>
    <item>
      <title>Deploy dockerized app in aws ecs with fresh new vpc.</title>
      <dc:creator>Rajesh Kumar</dc:creator>
      <pubDate>Mon, 25 May 2020 15:20:30 +0000</pubDate>
      <link>https://dev.to/rajeshkumarbehura/deploy-dockerized-app-in-aws-ecs-in-new-vpc-3f9c</link>
      <guid>https://dev.to/rajeshkumarbehura/deploy-dockerized-app-in-aws-ecs-in-new-vpc-3f9c</guid>
      <description>&lt;p&gt;After struggling for few days to deploy a dockerrized applicatin in ECS, found the solution &amp;amp; simplified into script, so that anyone can deploy easily simply replacing app folder.&lt;/p&gt;

&lt;p&gt;This example is for deployment of App with fresh new VPC. Vpc will be created during ecs/fargate deployment.&lt;/p&gt;

&lt;h4&gt;
  
  
  git location
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://github.com/rajeshkumarbehura/vpc_ecs_app_deploy"&gt;https://github.com/rajeshkumarbehura/vpc_ecs_app_deploy&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirement an application to deploy in Aws ECS
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Project must dockerized. In my repo, its demo-app folder which is nestjs based simple application.You can have java/nodejs/python any kind of project as long as it is dockerized.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;aws cli &amp;amp; terraform cli must be installed in your command line.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws --version &lt;br&gt;
   terraform --version&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;aws details must be avaialble&lt;br&gt;
 export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXX&lt;br&gt;
 export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXX&lt;br&gt;
 export AWS_REGION=ap-southeast-1&lt;br&gt;
 export AWS_PROFILE=dev   // dev profile must match in terraform/providers.ts file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It will create fresh new VPC for ecs/fargate deployment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After successfully deployment, terraform will print the alb path as&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;demoapp_alb_hostname = dev-demoapp-XXXXXXX.ap-southeast-1.elb.amazonaws.com&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  Steps to deploy
&lt;/h4&gt;

&lt;p&gt;Clone the project into your local.&lt;/p&gt;

&lt;h5&gt;
  
  
  a. Validate aws profile
&lt;/h5&gt;



&lt;p&gt;&lt;code&gt;export AWS_PROFILE=dev&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;this dev profile name must match with deploy/terraform/provider.tf&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Specify the provider and access details
provider "aws" {
  shared_credentials_file = "$HOME/.aws/credentials"
  profile                 = "dev"
  region                  = var.aws_region
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  b. Update shell script file
&lt;/h5&gt;

&lt;p&gt;Two shell script files exist inside deploy folder.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;create_repo_in_ecr.sh :
Update aws profile details in this file. This file will create aws ecr repository for project. And print a link after successulry created.
Eg -

&lt;code&gt;XXXXXX.dkr.ecr.ap-southeast-1.amazonaws.com/demo_app_repo&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is ECR_REPO_PATH for your project.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;push_image_to_ecr_&amp;amp;_deploy_ecs.sh :
Update aws profile details &amp;amp; ECR_REPO_PATH. This file will follows below step.

&lt;ul&gt;
&lt;li&gt;create docker container, &lt;/li&gt;
&lt;li&gt;container will tagged for ecr repo, &lt;/li&gt;
&lt;li&gt;push into ecr repository
&lt;/li&gt;
&lt;li&gt;application deploy into aws ecs from ecr.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  c. Execution
&lt;/h5&gt;

&lt;p&gt;Now in final steps, after updating above details, go to deploy folder in command line.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run create_repo_in_ecr.sh file for creating repo.&lt;/li&gt;
&lt;li&gt;Run push_image_to_ecr_&amp;amp;_deploy_ecs.sh to deploy application&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  d. Destroy in Aws
&lt;/h5&gt;

&lt;p&gt;Cleaning or deleteing all resources from aws, use below steps-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to deploy/terraform folder location in command line &amp;amp; run below command
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform destroy 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  How to deploy your own application
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Replace your application inside demo-app content &amp;amp; make sure your application working dockerized. Please do not change demo-app &lt;/li&gt;
&lt;li&gt;Create health check api - api/index. This is configured inside terraform/variable.tf file in terraform folder
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;variable "demoapp_health_check_path" {&lt;br&gt;
  default = "/api/index"&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Optional step- to create your all configuration with a new name, do a find all for "demoapp" text inside terraform folder and replace with ur own text. For example- replace "demoapp" text with "customerapp". Then do terraform plan, and check all things are working or not. if any place, please rename according to your text.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Play with terraform, ecr &amp;amp; ecs to explore more.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>ecs</category>
      <category>fargate</category>
    </item>
    <item>
      <title>Deploy dockerized app in Aws ECS in existing vpc.</title>
      <dc:creator>Rajesh Kumar</dc:creator>
      <pubDate>Sun, 24 May 2020 12:53:54 +0000</pubDate>
      <link>https://dev.to/rajeshkumarbehura/deploy-dockerized-app-in-aws-ecs-in-existing-vpc-432i</link>
      <guid>https://dev.to/rajeshkumarbehura/deploy-dockerized-app-in-aws-ecs-in-existing-vpc-432i</guid>
      <description>&lt;p&gt;After struggling for few days to deploy a dockerrized applicatin in ECS, found the solution &amp;amp; simplified into script, so that anyone can deploy easily simply replacing app folder.&lt;/p&gt;

&lt;p&gt;To deploy your application in ECS,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Your docker container image needs to be push to ECR.&lt;/li&gt;
&lt;li&gt;From ECR repo, application will deploy in ECS&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  git location
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://github.com/rajeshkumarbehura/ecs-app-deploy"&gt;https://github.com/rajeshkumarbehura/ecs-app-deploy&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirement an application to deploy in Aws ECS
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Project must dockerized. In my repo, its demo-app folder which is nestjs based simple application.You can have java/nodejs/python any kind of project as long as it is dockerized.&lt;/li&gt;
&lt;li&gt;aws cli &amp;amp; terraform cli must be available in your command line.
  aws --version
  terraform --version &lt;/li&gt;
&lt;li&gt;&lt;p&gt;aws details must be avaialble&lt;br&gt;
 AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXX&lt;br&gt;
 AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXX&lt;br&gt;
 AWS_REGION=ap-southeast-1&lt;br&gt;
 AWS_PROFILE=dev&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You should know, whats your existing vpc &amp;amp; public subnet name in aws account.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Steps to deploy
&lt;/h4&gt;

&lt;p&gt;Clone the project in your local.&lt;/p&gt;

&lt;h5&gt;
  
  
  Update VPC details in terraform
&lt;/h5&gt;

&lt;p&gt;Go to /deploy/terraform/network.tf and replace dev-data-stream-vpc name with your existing vpc name.&lt;/p&gt;

&lt;p&gt;Replace dev-data-stream-public-subnet name, with your existing public subnet tied with your existing vpc name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;variable "existing_vpc_name" {
  description = "Existing VPC in your aws cloud"
  default     = "dev-data-stream-vpc"
}

variable "existing_vpc_public_subnet_name" {
  description = "public subnet name which tie up with existing vpc"
  default     = "dev-data-stream-public-subnet"
}

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

&lt;/div&gt;



&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;go to deploy folder&lt;/li&gt;
&lt;li&gt;update AWS parameters in create_repo_in_ecr.sh and run this file.&lt;/li&gt;
&lt;li&gt;Above script will create a repo in your aws account and print that ecr repo link in your console.&lt;/li&gt;
&lt;li&gt;Copy ecr link &amp;amp; update aws parameter in push_image_to_ecr_&amp;amp;_deploy_ecs.sh file.&lt;/li&gt;
&lt;li&gt;finally run push_image_to_ecr_&amp;amp;_deploy_ecs.sh script on your console to deploy this application&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Destroy in AWS
&lt;/h5&gt;

&lt;p&gt;Cleaning or deleteing all resources in aws, use below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you can deploy and destroy successfully, then you can change more parameter and play around terraform files to understand more.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to deploy your own application
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Replace your application inside demo-app content &amp;amp; make sure your application working dockerized.&lt;/li&gt;
&lt;li&gt;Create health check api - api/index 
This is configured inside variable.tf file in terraform folder&lt;/li&gt;
&lt;li&gt;Optional step- to create your all configuration with a new name, do a find all for "demoapp" text inside terraform folder and replace with ur own text. For example- replace "demoapp" text with "customerapp".
Then do terraform plan, and check all things are working or not. if any place, please rename according to your text.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Play with terraform, ecr &amp;amp; ecs to explore more.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>ecs</category>
      <category>terraform</category>
    </item>
    <item>
      <title>Kafkajs &amp; NestJS with Typescript Simplified Example</title>
      <dc:creator>Rajesh Kumar</dc:creator>
      <pubDate>Sat, 23 May 2020 17:18:17 +0000</pubDate>
      <link>https://dev.to/rajeshkumarbehura/kafkajs-nestjs-with-typescript-simplified-example-35ep</link>
      <guid>https://dev.to/rajeshkumarbehura/kafkajs-nestjs-with-typescript-simplified-example-35ep</guid>
      <description>&lt;p&gt;This code example tried to simplify kafka integration with nestjs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Github location
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://github.com/rajeshkumarbehura/ts-nestjs-kafka
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to integrate-
&lt;/h3&gt;

&lt;p&gt;Kafka module is created as global module in this project. To integrate your project, copy app/common/kakfa module and inject KafkaModule as app module.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    KafkaModule.register({
      clientId: 'test-app-client',
      brokers: ['localhost:9092'],
      groupId: 'test-app-group',
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my project, it is injected to top level in app.module.ts&lt;/p&gt;

&lt;h3&gt;
  
  
  Create A Kafka Payload
&lt;/h3&gt;

&lt;p&gt;Before sending message, create a custom payload to send message&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const payload: KafkaPayload = {
      messageId: '' + new Date().valueOf(), // uuid
      body: message,
      messageType: 'Say.Hello',  
      topicName: 'hello.topic', 
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Send message to KafkaTopic
&lt;/h3&gt;

&lt;p&gt;Inject KafkaService to your service or controller and call sendMessage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const value = await this.kafkaService.sendMessage('hello.topic', payload);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Consumer Implementation
&lt;/h3&gt;

&lt;p&gt;Extend AbstractKafkaConsumer class and implement registerTopic method.&lt;br&gt;
Inside registerTopic, you only need to add topic names.&lt;br&gt;
No need to inject any service, as its implemented globally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Injectable()
export class ConsumerService extends AbstractKafkaConsumer {
    protected registerTopic() {
        this.addTopic('hello.topic');  
        this.addTopic('hello.fixed.topic');
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Subscribe to Topic when GroupId is not fixed
&lt;/h3&gt;

&lt;p&gt;Add annotation to the method and define topic name as its parameter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; @SubscribeTo('hello.topic')
 helloSubscriber(payload: KafkaPayload) {
        console.log('Print message after receiving', payload);
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Subscribe to Topic when GroupId is fixed
&lt;/h3&gt;

&lt;p&gt;When multiple containers or apps are running during horizontal scaling and your only one container/application required to listen to topic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; @SubscribeToFixedGroup('hello.fixed.topic')
 helloSubscriber(payload: KafkaPayload) {
        console.log('Print message after receiving', payload);
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>kafkajs</category>
      <category>nestjs</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
