<?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"><channel><title><![CDATA[Mukul Mantosh]]></title><description><![CDATA[Hey, I'm Mukul, and I'm on a mission to build something.]]></description><link>https://mukulmantosh.com</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 06:14:51 GMT</lastBuildDate><atom:link href="https://mukulmantosh.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Build a RAG App Using AWS Bedrock and Go]]></title><description><![CDATA[In this tutorial, we will create a simple RAG application using AWS Bedrock, Go, and Streamlit with Python.
Follow the tutorial here.]]></description><link>https://mukulmantosh.com/how-to-build-a-rag-app-using-aws-bedrock-and-go</link><guid isPermaLink="true">https://mukulmantosh.com/how-to-build-a-rag-app-using-aws-bedrock-and-go</guid><category><![CDATA[Go Language]]></category><category><![CDATA[AWS]]></category><category><![CDATA[RAG ]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Mukul Mantosh]]></dc:creator><pubDate>Fri, 21 Feb 2025 05:51:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1740117082954/05f814d1-2c35-4cc5-8022-7191d5e5af18.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this tutorial, we will create a simple RAG application using AWS Bedrock, Go, and Streamlit with Python.</p>
<p>Follow the tutorial <a target="_blank" href="https://www.jetbrains.com/guide/go/tutorials/simple_rag_with_go/">here</a>.</p>
]]></content:encoded></item><item><title><![CDATA[How to Begin Your Kubernetes Journey Using Go and GoLand]]></title><description><![CDATA[In this video, I'll show you how to deploy your Go application on Kubernetes using GoLand, all without leaving your IDE.
To watch the video, click here.
If you prefer reading, check out this blog post.]]></description><link>https://mukulmantosh.com/how-to-begin-your-kubernetes-journey-using-go-and-goland</link><guid isPermaLink="true">https://mukulmantosh.com/how-to-begin-your-kubernetes-journey-using-go-and-goland</guid><category><![CDATA[Go Language]]></category><category><![CDATA[golang]]></category><category><![CDATA[goland]]></category><category><![CDATA[Kubernetes]]></category><dc:creator><![CDATA[Mukul Mantosh]]></dc:creator><pubDate>Wed, 05 Feb 2025 08:04:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738742497018/c77b6681-4da2-4581-8848-9f9717312723.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this video, I'll show you how to deploy your Go application on Kubernetes using GoLand, all without leaving your IDE.</p>
<p>To watch the video, click <a target="_blank" href="https://www.youtube.com/watch?v=GGy4paf6rm0">here</a>.</p>
<p>If you prefer reading, check out this blog <a target="_blank" href="https://blog.jetbrains.com/go/2024/11/20/deploying-go-apps-with-kubernetes/">post</a>.</p>
]]></content:encoded></item><item><title><![CDATA[How to Build a FastAPI App with Kubernetes and AWS]]></title><description><![CDATA[This tutorial will focus entirely on FastAPI and also explore powerful tools like Kubernetes and Amazon Web Services.
We will cover many features, including:

Working with SQLAlchemy and Alembic

Implementing APIs and securing them with JSON Web Toke...]]></description><link>https://mukulmantosh.com/how-to-build-a-fastapi-app-with-kubernetes-and-aws</link><guid isPermaLink="true">https://mukulmantosh.com/how-to-build-a-fastapi-app-with-kubernetes-and-aws</guid><category><![CDATA[Python]]></category><category><![CDATA[FastAPI]]></category><category><![CDATA[AWS]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[EKS]]></category><dc:creator><![CDATA[Mukul Mantosh]]></dc:creator><pubDate>Wed, 05 Feb 2025 07:52:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738741855698/2f512a23-2f3e-4b7d-bdea-a6343f6105bd.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This tutorial will focus entirely on <a target="_blank" href="https://fastapi.tiangolo.com/">FastAPI</a> and also explore powerful tools like <a target="_blank" href="https://kubernetes.io/">Kubernetes</a> and <a target="_blank" href="https://aws.amazon.com/">Amazon Web Services</a>.</p>
<p>We will cover many features, including:</p>
<ul>
<li><p>Working with SQLAlchemy and Alembic</p>
</li>
<li><p>Implementing APIs and securing them with JSON Web Tokens (JWT)</p>
</li>
<li><p>Integrating with Celery and Redis</p>
</li>
<li><p>Async tests</p>
</li>
<li><p>Helm charts</p>
</li>
<li><p>Deploying apps using Kubernetes and AWS EKS (Elastic Kubernetes Service)</p>
</li>
</ul>
<p>Follow this <a target="_blank" href="https://www.jetbrains.com/guide/python/tutorials/fastapi-aws-kubernetes/">link</a> to get started.</p>
]]></content:encoded></item><item><title><![CDATA[Step-by-Step Guide to Remote Development in PyCharm with Google Cloud Code]]></title><description><![CDATA[In this tutorial, you’ll learn how to build and run your applications in both a local Kubernetes cluster (using Docker Desktop or Minikube) and remotely in Google Kubernetes Engine. This setup lets you focus on coding while the Google Cloud Code plug...]]></description><link>https://mukulmantosh.com/step-by-step-guide-to-remote-development-in-pycharm-with-google-cloud-code</link><guid isPermaLink="true">https://mukulmantosh.com/step-by-step-guide-to-remote-development-in-pycharm-with-google-cloud-code</guid><category><![CDATA[google cloud]]></category><category><![CDATA[pycharm]]></category><category><![CDATA[Python]]></category><category><![CDATA[Django]]></category><category><![CDATA[RemoteDevelopment]]></category><category><![CDATA[Kubernetes]]></category><dc:creator><![CDATA[Mukul Mantosh]]></dc:creator><pubDate>Wed, 05 Feb 2025 07:48:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738741620653/e6c41435-a64f-409a-bf36-2ab4bfebfc2c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this tutorial, you’ll learn how to build and run your applications in both a local Kubernetes cluster (using Docker Desktop or Minikube) and remotely in Google Kubernetes Engine. This setup lets you focus on coding while the Google Cloud Code plugin handles everything else.</p>
<p>Follow this <a target="_blank" href="https://www.jetbrains.com/guide/python/tutorials/cloud-code-pycharm/">link</a>.</p>
<p><a target="_blank" href="https://www.jetbrains.com/guide/authors/mm/">  
</a></p>
]]></content:encoded></item><item><title><![CDATA[Accelerate Your Coding Workflow with Docker and Django]]></title><description><![CDATA[In this tutorial, we will explore two popular tools that are very helpful in your software development journey: Django, a powerful and well-tested web framework, and Docker, a tool for managing your applications. If you haven't heard of them, it's li...]]></description><link>https://mukulmantosh.com/accelerate-your-coding-workflow-with-docker-and-django</link><guid isPermaLink="true">https://mukulmantosh.com/accelerate-your-coding-workflow-with-docker-and-django</guid><category><![CDATA[Django]]></category><category><![CDATA[pycharm]]></category><category><![CDATA[Docker]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[Mukul Mantosh]]></dc:creator><pubDate>Wed, 05 Feb 2025 07:37:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738740912265/e33289ae-92b9-4d0f-a2ed-3eda594cd344.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this tutorial, we will explore two popular tools that are very helpful in your software development journey: Django, a powerful and well-tested web framework, and Docker, a tool for managing your applications. If you haven't heard of them, it's like you haven't been born yet.</p>
<p>Let's start our journey of using Django and Docker together.</p>
<p>To follow this tutorial, click <a target="_blank" href="https://www.jetbrains.com/guide/django/tutorials/django-docker/">here</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Building RESTful APIs with Gin: A Step-by-Step Guide]]></title><description><![CDATA[Are you ready to dive into REST API development with Go? In this tutorial, we'll cover all the key components:

Databases

ORM-driven development

JSON

HTTP


Follow this link to get started..]]></description><link>https://mukulmantosh.com/rest-api-development-with-gin</link><guid isPermaLink="true">https://mukulmantosh.com/rest-api-development-with-gin</guid><category><![CDATA[golang]]></category><category><![CDATA[gin-gonic]]></category><category><![CDATA[APIs]]></category><dc:creator><![CDATA[Mukul Mantosh]]></dc:creator><pubDate>Wed, 05 Feb 2025 07:23:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738740290442/5ef8c6a7-b22f-4136-b072-98b7a04f9ac1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Are you ready to dive into REST API development with Go? In this tutorial, we'll cover all the key components:</p>
<ul>
<li><p>Databases</p>
</li>
<li><p>ORM-driven development</p>
</li>
<li><p>JSON</p>
</li>
<li><p>HTTP</p>
</li>
</ul>
<p>Follow this <a target="_blank" href="https://www.jetbrains.com/guide/go/tutorials/bookstore_rest_api/">link</a> to get started..</p>
]]></content:encoded></item><item><title><![CDATA[Step-by-Step Guide: Deploying Go APIs on Google Cloud's GKE]]></title><description><![CDATA[In this tutorial, we'll walk through the process of deploying a Go application on Google Kubernetes Engine. You can find the full post on Medium; check it out here.]]></description><link>https://mukulmantosh.com/deploying-go-api-on-gke-google-cloud</link><guid isPermaLink="true">https://mukulmantosh.com/deploying-go-api-on-gke-google-cloud</guid><category><![CDATA[golang]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[google cloud]]></category><dc:creator><![CDATA[Mukul Mantosh]]></dc:creator><pubDate>Wed, 05 Feb 2025 06:48:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738737958649/d6026f93-c64b-4b2b-a055-9dd40184f1f3.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this tutorial, we'll walk through the process of deploying a Go application on Google Kubernetes Engine. You can find the full post on Medium; check it out <a target="_blank" href="https://medium.com/google-cloud/deploying-go-api-on-gke-google-cloud-9cec676bb3a6">here</a>.</p>
]]></content:encoded></item><item><title><![CDATA[How to Build an AI Assistant Using AWS Bedrock and Go]]></title><description><![CDATA[This tutorial explores how to build an AI assistant by integrating AWS Bedrock, Go programming, and React for a dynamic frontend.
Make sure you have installed GoLand & WebStorm.
Additionally, we expect that the intended audience would have experience...]]></description><link>https://mukulmantosh.com/ai-assistant-with-aws-bedrock-and-go</link><guid isPermaLink="true">https://mukulmantosh.com/ai-assistant-with-aws-bedrock-and-go</guid><category><![CDATA[AWS]]></category><category><![CDATA[golang]]></category><category><![CDATA[Amazon Bedrock]]></category><dc:creator><![CDATA[Mukul Mantosh]]></dc:creator><pubDate>Wed, 05 Feb 2025 06:42:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738737638948/ff129b7e-4877-4b89-9332-463db89d34cc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This tutorial explores how to build an AI assistant by integrating AWS Bedrock, Go programming, and React for a dynamic frontend.</p>
<p>Make sure you have installed <a target="_blank" href="https://www.jetbrains.com/go/">GoLand</a> &amp; <a target="_blank" href="https://www.jetbrains.com/webstorm/">WebStorm</a>.</p>
<p>Additionally, we expect that the intended audience would have experience working with Go.</p>
<p>Follow this link to read more about this <a target="_blank" href="https://www.jetbrains.com/guide/go/tutorials/bedrock_with_go/">tutorial</a>.</p>
]]></content:encoded></item><item><title><![CDATA[How to Build a Full Stack App Using React and Go: My Experience]]></title><description><![CDATA[You can read the original blog here.]]></description><link>https://mukulmantosh.com/how-to-build-a-full-stack-app-using-react-and-go-my-experience</link><guid isPermaLink="true">https://mukulmantosh.com/how-to-build-a-full-stack-app-using-react-and-go-my-experience</guid><category><![CDATA[golang]]></category><category><![CDATA[Go Language]]></category><category><![CDATA[React]]></category><dc:creator><![CDATA[Mukul Mantosh]]></dc:creator><pubDate>Sun, 03 Nov 2024 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738743078571/915852a7-953a-4674-8b26-6c4dd05353bf.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You can read the original blog <a target="_blank" href="https://blog.jetbrains.com/go/2024/11/04/create-a-full-stack-app-with-go-and-react/">here</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Streamlining AMIs using Packer, Vault & GitHub Actions]]></title><description><![CDATA[Nowadays, if you want to minimize human errors and maintain a consistent process for how software is released then you are going to rely on Continuous integration and continuous deployment (CI/CD). It's really hard to imagine how much productivity th...]]></description><link>https://mukulmantosh.com/streamlining-amis-using-packer-vault-github-actions</link><guid isPermaLink="true">https://mukulmantosh.com/streamlining-amis-using-packer-vault-github-actions</guid><dc:creator><![CDATA[Mukul Mantosh]]></dc:creator><pubDate>Sun, 30 Jun 2024 05:48:29 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726322787/b1a21718-fbad-4844-b3c8-61ee5aa67453.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Nowadays, if you want to minimize human errors and maintain a consistent process for how software is released then you are going to rely on Continuous integration and continuous deployment (CI/CD). It's really hard to imagine how much productivity they bring into the plate.</p>
<p>In this tutorial, we are going to take entire AWS instance backup using tools like Packer and see how it solves our problem and make our life much easier.</p>
<h2 id="heading-amazon-machine-image-ami">Amazon Machine Image (AMI)</h2>
<p>An <strong>Amazon Machine Image (AMI)</strong> is a special type of virtual appliance that is used to create a virtual machine within the Amazon Elastic Compute Cloud ("EC2"). It serves as the basic unit of deployment for services delivered using EC2. -- <em>Wikipedia</em></p>
<p>An AMI includes the following:</p>
<ul>
<li><p>A template for the root volume for the instance (for example, an operating system, an application server, and applications)</p>
</li>
<li><p>Launch permissions that control which AWS accounts can use the AMI to launch instances.</p>
</li>
<li><p>A block device mapping that specifies the volumes to attach to the instance when it's launched.</p>
</li>
</ul>
<hr />
<h2 id="heading-what-is-packer">What is Packer ?</h2>
<p>Packer is a tool for building identical machine images for multiple platforms from a single source configuration.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726267174/501d40cf-4542-495e-b851-35580df0fd9b.jpeg" alt="Packer_HashiCorp" /></p>
<p>Image Source : https://www.hashicorp.com/</p>
<p>Packer is lightweight, runs on every major operating system, and is highly performant, creating machine images for multiple platforms in parallel. Packer comes out of the box with support for many platforms.</p>
<p>To know more about Packer, visit : https://developer.hashicorp.com/packer</p>
<hr />
<h2 id="heading-project-structure">Project Structure</h2>
<p>GitHub Repository : https://github.com/mukulmantosh/Packer-Exercises</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726268600/45a00e45-c710-4007-afd9-e7550a8717db.png" alt="project_structure" /></p>
<ul>
<li><p><strong>.github</strong> - Workflow files for GitHub Actions</p>
</li>
<li><p><strong>packer</strong> - Contains HCL2 Packer templates, Shell Scripts etc.</p>
</li>
<li><p><strong>Dockerfile</strong> - Building Docker Image</p>
</li>
<li><p><strong>main.py</strong> - FastAPI Routes handling two endpoints</p>
</li>
<li><p><strong>requirements.txt</strong> - listing all the dependencies for a specific Python project</p>
</li>
</ul>
<hr />
<h2 id="heading-lets-begin">Let's Begin</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726270556/03e4fdf2-530c-465e-bc5b-c1f2ee22a209.png" alt="project_structure_2" /></p>
<p>I have used Amazon Linux 2 with arm64 architecture as our base AMI.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ifcn28rcnw5xs8k1qkz.png" alt="ami" /></p>
<p>The custom AMI name is <code>FastAPI_Base_Image</code>. It's a clean AMI without any OS/Software dependencies.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726271931/26fdf4bc-b26d-4e8a-8e3f-706a3723aa02.png" alt="custom_ami_fastapi" /></p>
<p>If you are not sure how to create an AMI, follow this link : https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/tkv-create-ami-from-instance.html</p>
<h3 id="heading-dockerfile">Dockerfile</h3>
<p>I will create a container from the Dockerfile which is taking Python 3.9 as the base image and followed with python dependencies installation and starting the uvicorn server.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726273412/e908b965-f0d3-410d-b75b-70accce9e92b.png" alt="dockerfile" /></p>
<p>The image is already hosted in DockerHub.</p>
<p>URL : https://hub.docker.com/r/mukulmantosh/packerexercise</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726274599/b735957c-9ea4-4bd9-92f7-6c367082c9e8.png" alt="dockerhub" /></p>
<p>We have compiled for three architectures. Thanks to <a target="_blank" href="https://docs.docker.com/build/">Docker Buildx</a>.</p>
<ul>
<li><p><code>amd64</code></p>
</li>
<li><p><code>arm64</code></p>
</li>
<li><p><code>arm/v7</code></p>
</li>
</ul>
<hr />
<h2 id="heading-packer-template">Packer Template</h2>
<p><strong>packer/build.pkr.hcl</strong></p>
<pre><code class="lang-plaintext">variable "ami_name" {
  type        = string
  description = "The name of the newly created AMI"
  default     = "fastapi-nginx-ami-{{timestamp}}"
}

variable "security_group" {
  type        = string
  description = "SG specific for Packer"
  default     = "sg-064ad8064cf203657"
}

variable "tags" {
  type = map(string)
  default = {
    "Name" : "FastAPI-NGINX-AMI-{{timestamp}}"
    "Environment" : "Production"
    "OS_Version" : "Amazon Linux 2"
    "Release" : "Latest"
    "Creator" : "Packer"
  }
}
source "amazon-ebs" "nginx-server-packer" {
  ami_name          = var.ami_name
  ami_description   = "AWS Instance Image Created by Packer on {{timestamp}}"
  instance_type     = "c6g.medium"
  region            = "ap-south-1"
  security_group_id = var.security_group
  tags              = var.tags

  run_tags        = var.tags
  run_volume_tags = var.tags
  snapshot_tags   = var.tags


  source_ami_filter {
    filters = {
      name                = "FastAPI_Base_Image"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }

    most_recent = true
    owners      = ["self"]
  }
  ssh_username = "ec2-user"



}

build {
  sources = [
    "source.amazon-ebs.nginx-server-packer"
  ]

  provisioner "shell" {
    inline = [
      "sudo yum update -y",
    ]
  }

  provisioner "shell" {
    script       = "./scripts/build.sh"
    pause_before = "10s"
    timeout      = "300s"
  }

  provisioner "file" {
    source      = "./scripts/fastapi.conf"
    destination = "/tmp/fastapi.conf"
  }


  provisioner "shell" {
    inline = ["sudo mv /tmp/fastapi.conf /etc/nginx/conf.d/fastapi.conf"]
  }

  error-cleanup-provisioner "shell" {
    inline = ["echo 'update provisioner failed' &gt; packer_log.txt"]
  }

}
</code></pre>
<p><a target="_blank" href="https://developer.hashicorp.com/packer/docs/templates/legacy_json_templates/user-variables"><strong>User Variables</strong></a></p>
<p>User variables allow your templates to be further configured with variables from the command-line, environment variables, Vault, or files. This lets you parameterize your templates so that you can keep secret tokens, environment-specific data, and other types of information out of your templates. This maximizes the portability of the template.</p>
<p><a target="_blank" href="https://developer.hashicorp.com/packer/docs/builders"><strong>Builders</strong></a></p>
<p>Builders create machines and generate images from those machines for various platforms (EC2, GCP, Azure, VMware, VirtualBox) etc. Packer also has some builders that perform helper tasks, like running provisioners.</p>
<p><a target="_blank" href="https://developer.hashicorp.com/packer/docs/provisioners"><strong>Provisioners</strong></a></p>
<p>Provisioners use built-in and third-party software to install and configure the machine image after booting. Provisioners prepare the system, so you may want to use them for the following use cases:</p>
<ul>
<li><p>installing packages</p>
</li>
<li><p>patching the kernel</p>
</li>
<li><p>creating users</p>
</li>
<li><p>downloading application code</p>
</li>
</ul>
<p><a target="_blank" href="https://developer.hashicorp.com/packer/docs/post-processors"><strong>Post-Processors</strong></a></p>
<p>Post-processors run after builders and provisioners. Post-processors are optional, and you can use them to upload artifacts, re-package files, and more.</p>
<p><a target="_blank" href="https://developer.hashicorp.com/packer/docs/templates/hcl_templates/blocks/build/provisioner#on-error-provisioner"><strong>On Error Provisioner</strong></a></p>
<p>You can optionally create a single specialized provisioner called an error-cleanup-provisioner. This provisioner will not run unless the normal provisioning run fails. If the normal provisioning run does fail, this special error provisioner will run before the instance is shut down. This allows you to make last minute changes and clean up behaviors that Packer may not be able to clean up on its own.</p>
<p>The <strong>amazon-ebs</strong> Packer builder is able to create Amazon AMIs backed by EBS volumes for use in EC2.</p>
<pre><code class="lang-plaintext">source "amazon-ebs"
</code></pre>
<p>This builder builds an AMI by launching an EC2 instance from a source AMI, provisioning that running machine, and then creating an AMI from that machine. This is all done in your own AWS account. The builder will create temporary keypairs, security group rules, etc. that provide it temporary access to the instance while the image is being created. This simplifies configuration quite a bit.</p>
<p>The builder does not manage AMIs. Once it creates an AMI and stores it in your account, it is up to you to use, delete, etc. the AMI.</p>
<p>To know more, visit this link : https://developer.hashicorp.com/packer/plugins/builders/amazon/ebs</p>
<p>In the “source_ami_filter” section, We are filtering based on the base AMI which we created earlier.</p>
<pre><code class="lang-plaintext">  source_ami_filter {
    filters = {
      name                = "FastAPI_Base_Image"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }

    most_recent = true
    owners      = ["self"]
  }
</code></pre>
<p><strong>most_recent</strong> - Selects the newest created image when true. <strong>owners</strong> - You may specify one or more AWS account IDs, "self" (which will use the account whose credentials you are using to run Packer)</p>
<p>We are using a Packer function called <strong>“timestamp”</strong> to generate UNIX timestamp, which helps to get a unique AMI name on every build.</p>
<p>By default the AMI’s you create will be private. If you want to share the AMI’s with other accounts you can make use of the <strong>“ami_users”</strong> option in packer.</p>
<p>If you want to build images in multi-region, you can specify the below code in the source section.</p>
<pre><code class="lang-plaintext">  ami_regions   = ["us-west-2", "us-east-1", "eu-central-1"]
</code></pre>
<p>In the provisioner section we will be updating the OS along-with installing scripts and copy nginx configuration.</p>
<p><strong>packer/scripts/build.sh</strong></p>
<p>Installing Docker, NGINX, and pulling latest application image from DockerHub and starting the container.</p>
<pre><code class="lang-plaintext">#!/bin/bash
sudo yum install jq -y
sudo yum install -y git

sudo yum install -y docker
sudo usermod -a -G docker ec2-user
sudo systemctl enable docker.service
sudo systemctl start docker.service

sudo amazon-linux-extras install nginx1 -y
sudo systemctl enable nginx.service
sudo systemctl start nginx.service

IMAGE_TAG=`curl -L -s 'https://hub.docker.com/v2/repositories/mukulmantosh/packerexercise/tags'|jq '."results"[0]["name"]' | bc`

sudo docker pull mukulmantosh/packerexercise:$IMAGE_TAG
sudo docker run -d --name fastapi --restart always -p 8080:8080 mukulmantosh/packerexercise:$IMAGE_TAG
</code></pre>
<p><strong>packer/scripts/fastapi.conf</strong></p>
<p>Copy the configuration to NGINX configuration folder. So, NGINX will proxy the request to backend.</p>
<pre><code class="lang-plaintext">upstream fastapi {
    server 127.0.0.1:8080;
}
server {

    listen 80;

    location / {
        proxy_pass http://fastapi;
        proxy_set_header X-Forwarded-For 
        $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }

}
</code></pre>
<hr />
<h2 id="heading-building-template">Building Template</h2>
<p>Before you begin to build, make sure you have setup the following keys in your system and <strong>aws-cli</strong> is installed in your machine.</p>
<ul>
<li><p><code>AWS_ACCESS_KEY_ID</code></p>
</li>
<li><p><code>AWS_SECRET_ACCESS_KEY</code></p>
</li>
</ul>
<p>There are two commands which you need to run before you execute build.</p>
<p><code>packer fmt build.pkr.hcl</code></p>
<p>The packer <a target="_blank" href="https://developer.hashicorp.com/packer/docs/commands/fmt">fmt</a> Packer command is used to format HCL2 configuration files to a canonical format and style</p>
<p><code>packer validate build.pkr.hcl</code></p>
<p>The packer <a target="_blank" href="https://developer.hashicorp.com/packer/docs/commands/validate">validate</a> Packer command is used to validate the syntax and configuration of a template</p>
<h3 id="heading-starting-the-build">Starting the Build</h3>
<p><code>packer build build.pkr.hcl</code></p>
<p>The packer <a target="_blank" href="https://developer.hashicorp.com/packer/docs/commands/build">build</a> command takes a template and runs all the builds within it in order to generate a set of artifacts.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ahmfrd9vqq09emfxo6gy.gif" alt="animate_packer_build" /></p>
<p>You can see the new AMI has been successfully created and tag has been assigned.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726277602/628fa052-a15c-4add-bfc2-482f2f6a0cbf.png" alt="new_ami_1" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726279585/8471b5a8-d38d-4e04-96f8-2166e6aee3c4.png" alt="new_ami_2" /></p>
<p>You must have observed in the packer template, that we are using a custom security group. By default, Packer creates security group which access port 22 (0.0.0.0) from anywhere.</p>
<p>This posses security risk and to minimize that, I created a custom security group (<strong>Packer_SG</strong>) which allows only My IP.</p>
<pre><code class="lang-plaintext">variable "security_group" {
  type        = string
  description = "SG specific for Packer"
  default     = "sg-064ad8064cf203657"
}
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726280955/ff668246-f101-443a-bad4-84bd8c930d38.png" alt="custom_sg" /></p>
<p>You can add more security by taking leverage of Session Manager Connections.</p>
<p><a target="_blank" href="https://developer.hashicorp.com/packer/plugins/builders/amazon/ebs#session-manager-connections"><strong>Session Manager Connections</strong></a> Support for the AWS Systems Manager session manager lets users manage EC2 instances without the need to open inbound ports, or maintain bastion hosts.</p>
<hr />
<h2 id="heading-github-actions">GitHub Actions</h2>
<p>GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline.</p>
<h3 id="heading-self-hosted-runners">Self-hosted runners</h3>
<p>For our setup we will be using self-hosted Github runners.</p>
<p>Self-hosted runners offer more control of hardware, operating system, and software tools than GitHub-hosted runners provide. With self-hosted runners, you can create custom hardware configurations that meet your needs with processing power or memory to run larger jobs, install software available on your local network, and choose an operating system not offered by GitHub-hosted runners. Self-hosted runners can be physical, virtual, in a container, on-premises, or in a cloud.</p>
<p>Don't know how to setup ? Follow the below link :</p>
<ul>
<li><p><a target="_blank" href="https://www.youtube.com/watch?v=G6nBM3NxBDc">Deploying Self-hosted Runners for GitHub Actions</a></p>
</li>
<li><p><a target="_blank" href="https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners">About self-hosted runners</a></p>
</li>
</ul>
<p>As from security standpoint, we will make sure <strong>"Packer_SG"</strong> security group allow inbound port 22 for Github Action IP.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726282897/b75b113d-9294-448d-b552-eb3800fec073.png" alt="allow_sg_gh_action_1" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726284094/3a23d848-cb1e-4a73-b759-d03699ac8b8c.png" alt="allow_sg_gh_action_2" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726285443/380d653a-dd16-43f3-ac08-9ad4fd6c281e.png" alt="allow_sg_gh_action_3" /></p>
<h3 id="heading-execute-pipeline">Execute Pipeline</h3>
<p>Before proceeding, make sure to create the secrets which will be required in the build process.</p>
<p><code>AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726287033/59f0de8e-afe7-41e3-a72d-22f404d26af2.png" alt="action_secrets" /></p>
<p><strong>.github/workflows/build-packer.yml</strong></p>
<pre><code class="lang-plaintext">name: Packer

on:
  push:
    branches: main

jobs:
  packer:
    runs-on: self-hosted
    name: packer

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

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1-node16
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ap-south-1


      # validate templates
      - name: Validate Template
        uses: hashicorp/packer-github-actions@master
        with:
          command: validate
          arguments: -syntax-only
          target: build.pkr.hcl
          working_directory: ./packer


      # build artifact
      - name: Build Artifact
        uses: hashicorp/packer-github-actions@master
        with:
          command: build
          arguments: "-color=false -on-error=abort"
          target: build.pkr.hcl
          working_directory: ./packer
</code></pre>
<p>On inspecting the YAML file, you can clearly observe that we will be validating packer templates and then followed by building the artifact.</p>
<p>Let me make a small change in main branch. So, the pipeline will get triggered.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7gc791kcxld37dvnlqg0.gif" alt="packer_github_action_flow" /></p>
<p>You can see now, the new AMI is created.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726291987/3fbaa141-3bae-493e-84a1-bfcf847b2acd.png" alt="packer_github_action_ami" /></p>
<hr />
<h2 id="heading-vault">Vault</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726293299/b07d4915-0e9f-4b8c-960b-4ed8ec5ec9a5.png" alt="hashicorp_vault" /></p>
<p><strong>HashiCorp Vault</strong> tightly controls access to secrets and encryption keys by authenticating against trusted sources of identity such as Active Directory, LDAP, Kubernetes, Cloud Foundry, and cloud platforms. Vault enables fine grained authorization of which users and applications are permitted access to secrets and keys.</p>
<p>To know more about Vault, visit this link :</p>
<ul>
<li>https://developer.hashicorp.com/vault</li>
</ul>
<p>The reason we are using Vault over here is to create dynamic user credentials.</p>
<p>This helps us to avoid setting up environment variables for</p>
<p><code>export AWS_ACCESS_KEY_ID="XXXXXXXXXXXXXXX"export AWS_SECRET_ACCESS_KEY="XXXXXXXXXXXXXXX"</code></p>
<p>Putting this keys in local machine, might expose some risks. So, I would recommend trying out <a target="_blank" href="https://developer.hashicorp.com/vault/docs/secrets/aws"><strong>AWS Secrets Engine</strong></a>.</p>
<h3 id="heading-aws-secrets-engine">AWS Secrets Engine</h3>
<p>The AWS secrets engine generates AWS access credentials dynamically based on IAM policies. This generally makes working with AWS IAM easier, since it does not involve clicking in the web UI. Additionally, the process is codified and mapped to internal auth methods (such as LDAP). The AWS IAM credentials are <strong>time-based</strong> and are <strong>automatically revoked</strong> when the Vault lease expires.</p>
<p>I have already setup Vault in my local machine.</p>
<p>Follow the below link for setting up Vault.</p>
<ul>
<li>https://developer.hashicorp.com/vault/downloads</li>
</ul>
<p>You can either setup in your local machine or use <a target="_blank" href="https://cloud.hashicorp.com/">HashiCorp Cloud</a>.</p>
<p>Let's now begin by enabling the AWS secrets engine in our Vault server which is running locally.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726295082/adc3e4a0-ff71-47a5-a077-c2308abd4778.png" alt="create_vault_aws_1" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726297134/db2d2d12-9701-4aa5-a5d0-93db7b1b2498.png" alt="create_vault_aws_2" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726298396/ddbeb36c-eefc-4a67-b56a-43a5c9dc7d22.png" alt="create_vault_aws_3" /></p>
<p>Now, click on <strong>Configuration</strong> to setup our credentials.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726299662/965655af-40e3-498d-b9fe-6d49f70774b4.png" alt="vault_configure" /></p>
<p>Provide the AWS credentials and region which will be used to create user and attach role to them.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726301548/3af5d95b-194a-4240-b6b2-748daf2643fa.png" alt="create_vault_aws_4" /></p>
<p>Next, I will modify lease time to 15 minutes. So, once the user is created it will be deleted automatically after 15 minutes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726303430/9e313f39-78fc-4293-af13-75c6dce137b1.png" alt="create_vault_aws_5" /></p>
<p>Click on Save.</p>
<p>I have configured the AWS credential. Now, I will create the role which is going to be attached to the new user.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726304757/5d236424-d86b-4d5c-b7a0-e21648560c11.png" alt="create_vault_aws_6" /></p>
<p><strong>Policy Document</strong></p>
<pre><code class="lang-plaintext">{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:AttachVolume",
        "ec2:AuthorizeSecurityGroupIngress",
        "ec2:CopyImage",
        "ec2:CreateImage",
        "ec2:CreateKeypair",
        "ec2:CreateSecurityGroup",
        "ec2:CreateSnapshot",
        "ec2:CreateTags",
        "ec2:CreateVolume",
        "ec2:DeleteKeyPair",
        "ec2:DeleteSecurityGroup",
        "ec2:DeleteSnapshot",
        "ec2:DeleteVolume",
        "ec2:DeregisterImage",
        "ec2:DescribeImageAttribute",
        "ec2:DescribeImages",
        "ec2:DescribeInstances",
        "ec2:DescribeInstanceStatus",
        "ec2:DescribeRegions",
        "ec2:DescribeSecurityGroups",
        "ec2:DescribeSnapshots",
        "ec2:DescribeSubnets",
        "ec2:DescribeTags",
        "ec2:DescribeVolumes",
        "ec2:DetachVolume",
        "ec2:GetPasswordData",
        "ec2:ModifyImageAttribute",
        "ec2:ModifyInstanceAttribute",
        "ec2:ModifySnapshotAttribute",
        "ec2:RegisterImage",
        "ec2:RunInstances",
        "ec2:StopInstances",
        "ec2:TerminateInstances"
      ],
      "Resource": "*"
    }
  ]
}
</code></pre>
<p>I would recommend follow defense in depth and principle of least privilege.</p>
<p>Most of them don't encourage that policy document should contain delete permissions.</p>
<p>I came across an interesting article for tightening your policy document and make it more secure. So, it won't interfere with other instances.</p>
<p>Please checkout the below link :</p>
<ul>
<li><a target="_blank" href="https://blog.stefan-koch.name/2021/05/16/restricted-packer-aws-permissions"><strong>Towards a more Restricted Set of AWS IAM Permissions for Packer</strong></a></li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726306695/644d69b3-4471-43e6-bb68-4ac4bc003153.png" alt="create_vault_aws_7" /></p>
<p>Now, I will click on <strong>Generate Credentials</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726308888/5a13c7c4-42cc-484f-8206-dc35b1519f20.png" alt="create_vault_aws_8" /></p>
<p>Now, it's going to create a IAM user which is valid for 15 minutes (900 seconds)</p>
<p>You can see below, the new user is appearing in the IAM User section.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726310834/3a460117-d5a1-4c8d-a194-4fd417616ec9.png" alt="create_vault_aws_9" /></p>
<p>The <strong>PackerRole</strong> with assigned permissions are also being reflected.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726312113/cab4d464-32a0-44f2-9acf-1d185e3048d6.png" alt="create_vault_aws_10" /></p>
<p>Now, we are going to make sure that Packer should generate this credentials automatically.</p>
<p>Let's begin by editing the <strong>build.pkr.hcl</strong> file.</p>
<p>You need to add this line before closing of the source block.</p>
<pre><code class="lang-plaintext">  vault_aws_engine {
    name = "PackerRole"
  }
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726313593/d2d78f68-5fd5-4560-8169-af1efde2740d.png" alt="vault_aws_engine_packer_template" /></p>
<p>Next, you need to setup environment variables.</p>
<p>Windows :</p>
<p><code>set VAULT_ADDR=http://127.0.0.1:8200set VAULT_TOKEN=XXXXXXXXXXXXXXXXXXXXX</code></p>
<p>Linux :</p>
<p><code>export VAULT_ADDR=http://127.0.0.1:8200export VAULT_TOKEN=XXXXXXXXXXXXXXXXXXXXX</code></p>
<p>Once, we are done setting up our environment variables. We need to validate everything is working as expected by running the <code>validate</code> command.</p>
<pre><code class="lang-plaintext">packer validate build.pkr.hcl
</code></pre>
<p>If you receive this message <code>The configuration is valid</code> then you are good to proceed.</p>
<p>To initiate the build run the below command :</p>
<pre><code class="lang-plaintext">packer build build.pkr.hcl
</code></pre>
<ul>
<li>Note : Make sure before your begin build. The security group <strong>Packer_SG</strong> allows inbound access to port 22 from MyIP, as you are running the build from local machine.</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726315032/0d382b4c-7f29-4662-a611-a08e93820042.png" alt="Image description" /></p>
<p>Observe the message : <code>You're using Vault-generated AWS credentials</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726316361/5744e35b-4493-4732-aa9c-c6f4e2c8c4ca.png" alt="Image description" /></p>
<p>This is going to pick the credentials from Vault, which is going to dynamically create a new user and attach the role.</p>
<p>The user will get automatically deleted based on the expiry specified.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726318274/facb065a-8c3b-44ea-8a70-fda0d4a4e2b9.png" alt="vault_iam_user_expire" /></p>
<p>Once, the build is complete. You will find the new image appearing in the AMI section.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726319578/40c226f2-13e9-4825-9c95-d2f280a4be67.png" alt="ami_images_list" /></p>
<h2 id="heading-final-destination">Final Destination</h2>
<p>Congratulations !!! You did it 🏆🏆🏆</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719726321059/83ff6301-58b8-47df-8ca9-59bbc5451d43.jpeg" alt="conclusion" /></p>
<p>If you liked this tutorial 😊, make sure to share across your friends and colleagues.</p>
<h4 id="heading-references">References</h4>
<ul>
<li><p><a target="_blank" href="https://developer.hashicorp.com/packer/tutorials/cloud-production/golden-image-with-hcp-packer">Build a Golden Image Pipeline with HCP Packer</a></p>
</li>
<li><p><a target="_blank" href="https://aws.amazon.com/blogs/security/how-to-set-up-continuous-golden-ami-vulnerability-assessments-with-amazon-inspector/">How to Set Up Continuous Golden AMI Vulnerability Assessments with Amazon Inspector</a></p>
</li>
<li><p><a target="_blank" href="https://developer.hashicorp.com/packer/docs">Packer Docs</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Developing Django Application using AWS]]></title><description><![CDATA[Run, build, test and deploy Django Application in PyCharm using NICE DCV.
  
If you're interested in running your entire application on AWS while feeling like you're working on a local machine, you're in the right place. This tutorial will help you u...]]></description><link>https://mukulmantosh.com/developing-django-application-using-aws</link><guid isPermaLink="true">https://mukulmantosh.com/developing-django-application-using-aws</guid><category><![CDATA[AWS]]></category><category><![CDATA[#NICEDCV]]></category><category><![CDATA[Django]]></category><category><![CDATA[pycharm]]></category><dc:creator><![CDATA[Mukul Mantosh]]></dc:creator><pubDate>Fri, 09 Apr 2021 06:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738742315088/86256095-ba88-43cc-b787-60eb7e60573c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-run-build-test-and-deploy-django-application-in-pycharm-using-nice-dcv"><strong>Run, build, test and deploy Django Application in PyCharm using NICE DCV.</strong></h3>
<p><a target="_blank" href="https://www.jetbrains.com/guide/authors/mm/">  
</a>If you're interested in running your entire application on AWS while feeling like you're working on a local machine, you're in the right place. This tutorial will help you understand how to easily run, test, build, and deploy your application using PyCharm with <a target="_blank" href="https://aws.amazon.com/hpc/dcv/">NICE DCV</a>. NICE DCV is a high-performance remote display protocol that securely delivers remote desktops and application streaming from any cloud or data center to any device.</p>
<p>This is just the beginning, and we'll explore many exciting topics, including:</p>
<ul>
<li><p>Working with AWS RDS</p>
</li>
<li><p>Integrating Sentry</p>
</li>
<li><p>Securing APIs with JSON Web Tokens (JWT)</p>
</li>
<li><p>Using BDD Tests and much more</p>
</li>
</ul>
<p>To follow this tutorial, click <a target="_blank" href="https://www.jetbrains.com/guide/django/tutorials/django-aws/">here</a>.</p>
]]></content:encoded></item></channel></rss>