<?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 Sanket Santosh Bhavsar on Medium]]></title>
        <description><![CDATA[Stories by Sanket Santosh Bhavsar on Medium]]></description>
        <link>https://medium.com/@sanket.bhavsarww?source=rss-77a23ec3edac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gDbx8au6Q171NDm5</url>
            <title>Stories by Sanket Santosh Bhavsar on Medium</title>
            <link>https://medium.com/@sanket.bhavsarww?source=rss-77a23ec3edac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 24 May 2026 02:26:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanket.bhavsarww/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[3 tier application]]></title>
            <link>https://medium.com/@sanket.bhavsarww/3-tier-application-195c33dc3b87?source=rss-77a23ec3edac------2</link>
            <guid isPermaLink="false">https://medium.com/p/195c33dc3b87</guid>
            <dc:creator><![CDATA[Sanket Santosh Bhavsar]]></dc:creator>
            <pubDate>Fri, 06 Mar 2026 08:29:49 GMT</pubDate>
            <atom:updated>2026-03-06T08:29:49.953Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d7QipxU0NKiI-baI7Ehe_w.png" /></figure><p>This is architecture of my Tier 3 application In that i use 2 load balancers ,vpc ,subnets,RDS Database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MCDNfoe6hvWB50u9kNHmkg.png" /></figure><p>create VPC 3-tier</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pg53mzVqkzGanwtNrQ3S_w.png" /></figure><p>provide Internet gatway to that VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vcvjaGO7OdFJbY0A_ehzpw.png" /></figure><p>Create 6 Subnets 3 subnets for 1a Zone and 3 1b Zone</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*E6n-CumSfFfiHmKNtGapbg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QjoPlJGcKx0Vmb71OY2S9Q.png" /><figcaption>create Security Group for Specific Subnets Create Above for Web-Sg</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V7rK_ARhUJQMKcN0zZnxig.png" /><figcaption>Create Security Group for Internal Load Balancer website run on 80 port so we open 80 port</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9g4jDUXQeE0I_sPXRoN0A.png" /><figcaption>Create Securiy Group for App-Sg for application will run on custom 4000 port so we open custom 4000 port</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nguUOPsMkl0lkCp49c56KA.png" /><figcaption>db will run on aws RDS server so we need port 3360 so we open the port</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AN1WgvKIfkOHoFS8tyks5Q.png" /></figure><p>we need toroute it all trafic transfer to internet gatway so then subnet get converted to public then we want NET configuration</p><p>Go to route table -&gt; create route table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pwlzhxoT5kHgMLbOgJ2CkA.png" /><figcaption>create route table -&gt; edit route</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hWuvWhUtEjG8DefwIuEvyA.png" /><figcaption>save changes</figcaption></figure><p>for which subnet we want to do that web 1a and web-1b</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l0cJ0PgmTNGJfEXT0nPzyQ.png" /></figure><p>now we can say that the web-1a and web-1b are public subnet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*XIExjjx5x7OfUfCvlXmzDQ.png" /></figure><p>we need to add NAT-GATEways for connectivity</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GNg8EoS8KYqdif0Cgv6tMw.png" /></figure><p>create NATGATEWAY with subnet web-1a and allocate elastic ip</p><p>similarly for nat-1b natgatway we need to create</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wx8OIflWY7v8Mu3nvoxUbw.png" /></figure><p>we need to route after that private routing table for 1a</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IQUbFZMGWX2zJ5pgUuylxQ.png" /></figure><p>edit route add</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rbi881hDk23tvF4cRQ4UtQ.png" /><figcaption>after that add subnet associated to it</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1uq13zQ6RCfGViv3MyIVcA.png" /></figure><p>similarly create 1 more route table for 1b</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jvE78LZgkmX9jzBU_o_E-A.png" /></figure><p>similarly subnet associate with the route table 1b</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q9JPpWyqFmDQ75cvRifDBA.png" /></figure><p>NOw Create RDS</p><p>for create table we need to create subnet group in RDS lets create that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-4iwaXJ-rWweYXQax0-SfA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_YSQmAqKpLgtlxMkAdnSig.png" /></figure><p>now create Database</p><h4>Choose a database creation method-&gt; standard create</h4><p>select Engin mysql then all as it is</p><p>select templates -&gt; free tier</p><h4>Availability and durability -&gt; single-AZ DB Instance</h4><p>setting add name :database-1</p><p>credentials setting-&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_mo3T7ivzRGOIjp7v4_Hxw.png" /><figcaption>create a password as you want</figcaption></figure><p>in next section</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qi2w3p6nUqYlzP3SYJNL0A.png" /></figure><h4>storage -&gt; make default</h4><p>connectivity-&gt; computer resourse make default</p><p>vpc-&gt; tier-3 (vpc-03b87cd5f22c3239a)</p><p>all make as it is</p><p><strong>Existing VPC security groups -&gt; db-sg</strong></p><p><strong>Availability Zone -&gt; any or ap-south-1a</strong></p><p>other as it is create database</p><ul><li>now launch frontend virtual machine and backend virtual machine</li></ul><h4>create EC2 instance -&gt; launch instance -&gt; name -&gt; web server -&gt;amazon linux -&gt;<strong>Instance type -&gt;</strong>Key pair (login) -&gt; i all ready create so i select it</h4><h3>Network settings</h3><p><strong>VPC <em>— required -&gt; tier3 -&gt; subnet -&gt; web-1a -&gt;</em>Auto-assign public IP-&gt;enable -&gt; Common security groups -&gt; web -sg</strong></p><p>launch instance</p><p>similarly one more instance we need to create for application server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KfwyHKyMNZ2c0VkkDdtatQ.png" /></figure><p>create instance -&gt; all simiar only changes in above</p><p>now connect to web server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*Bi4wyGSeWWMbH8knuvI7iw.png" /></figure><p>now we want to connect web-1a to app-1a</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*ohq69j4tHrI8jIZ3Vy06NQ.png" /></figure><h3>launch instance -&gt; web server → then create file vim sanket_mum.pem -&gt; put pem key in that file -&gt; save -&gt;</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*Rxu5YY1t8ejc20CQQbQXNg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=195c33dc3b87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jenkins Swiggy Project]]></title>
            <link>https://medium.com/@sanket.bhavsarww/jenkins-swiggy-project-f7d332a31506?source=rss-77a23ec3edac------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7d332a31506</guid>
            <dc:creator><![CDATA[Sanket Santosh Bhavsar]]></dc:creator>
            <pubDate>Fri, 06 Mar 2026 08:28:50 GMT</pubDate>
            <atom:updated>2026-03-06T08:28:50.944Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wXLwmtQwh20QGCrH4k-hGw.png" /></figure><p>create your terraform setup install</p><ol><li>Install Terraform on Windows<br>Manual Install<br>1. Go to: <a href="https://developer.hashicorp.com/terraform/downloads">https://developer.hashicorp.com/terraform/downloads</a><br>2. Download the Windows (64-bit) ZIP file.<br>3. Extract it to a folder (e.g., C:\Terraform).<br>4. Add that folder to your System PATH:<br>o Search for “Environment Variables” → Edit system environment variables →<br>Environment Variables<br>o Under “System Variables” → find Path → click Edit → Add C:\Terraform<br>Then open CMD window and run:<br>terraform -version<br>2. Install AWS CLI on Windows<br>Official Installer (recommended)<br>1. Download the installer:<br><a href="https://awscli.amazonaws.com/AWSCLIV2.msi">https://awscli.amazonaws.com/AWSCLIV2.msi</a><br>2. Run the .msi file and follow the prompts.<br>3. Open CMD and Verify it:<br>aws — version<br>Expected output:<br>aws-cli/2.x.x Python/3.x.x Windows/x86_64<br>3. Install Visual Studio Code (VS Code)<br>From Microsoft’s official site<br>1. Go to: <a href="https://code.visualstudio.com/">https://code.visualstudio.com/</a><br>2. Click Download for Windows and run the installer.</li></ol><p>now create main.tf</p><p># Define the AWS provider and region</p><p>provider “aws” {</p><p>region = “ap-south-1” # Mumbai region</p><p>}</p><p># — — AWS Security Group Resource — -</p><p># Resource to create a security group named “Project-SG”</p><p>resource “aws_security_group” “Project-SG” {</p><p>name = “Project-SG”</p><p>description = “Open 22, 80, 443, 8080, 9000, 3000”</p><p># Define ingress rules (Inbound traffic)</p><p># Uses a ‘for’ loop to create separate ingress blocks for each port</p><p>ingress = [</p><p>for port in [22, 80, 443, 8080, 9000, 3000] : {</p><p>description = “TLS from VPC” # Note: This description is used in the image, but typically describes the source.</p><p>from_port = port</p><p>to_port = port</p><p>protocol = “tcp”</p><p># Allows traffic from anywhere (0.0.0.0/0)</p><p>cidr_blocks = [“0.0.0.0/0”]</p><p>ipv6_cidr_blocks = []</p><p>prefix_list_ids = []</p><p>security_groups = []</p><p>self = false</p><p>}</p><p>]</p><p># Define egress rules (Outbound traffic)</p><p>egress {</p><p>from_port = 0 # All ports</p><p>to_port = 0 # All ports</p><p>protocol = “-1” # All protocols</p><p># Allows all outbound traffic to anywhere (0.0.0.0/0)</p><p>cidr_blocks = [“0.0.0.0/0”]</p><p>}</p><p>tags = {</p><p>Name = “Project-SG”</p><p>}</p><p>}</p><p># — — AWS EC2 Instance Resource — -</p><p># Resource to create an EC2 instance named “web”</p><p>resource “aws_instance” “web” {</p><p># Note: The AMI ID provided (ami-0f918f7e67a3323f0) is typically a regional Amazon Linux 2 AMI</p><p>ami = “ami-03695d52f0d883f65”</p><p>instance_type = “t2.large”</p><p># Reference the ID of the Security Group created above</p><p>vpc_security_group_ids = [aws_security_group.Project-SG.id]</p><p># Specify a path to a script file (e.g., for bootstrap/setup)</p><p># You would need to create a file named ‘script.sh’ in the same directory</p><p>user_data = templatefile(“./script.sh”,{})</p><p># Root volume configuration</p><p>root_block_device {</p><p>volume_size = 30 # Sets the root EBS volume size to 30 GB</p><p>}</p><p>tags = {</p><p>Name = “Jenkins-Project”</p><p>}</p><p>}</p><p>create Script .sh</p><p>#!/bin/bash</p><p># Set -e ensures that the script will exit immediately if a command exits with a non-zero status</p><p>set -e</p><p># — — 1. Install Java 17 (Temurin) — -</p><p>echo “ — — Stage 1: Installing Java 17 (Temurin) — -”</p><p># Update local package index</p><p>sudo apt update -y</p><p># Install prerequisite packages for downloading keys</p><p>sudo apt install -y wget apt-transport-https gnupg lsb-release</p><p># Download and add the Adoptium GPG key</p><p>wget -O — <a href="https://packages.adoptium.net/artifactory/api/gpg/Key/public">https://packages.adoptium.net/artifactory/api/gpg/Key/public</a> | sudo tee /etc/apt/keyrings/adoptium.asc</p><p># Add the Adoptium repository to the system’s sources list</p><p>echo “deb [signed-by=/etc/apt/keyrings/adoptium.asc] <a href="https://packages.adoptium.net/artifactory/deb/">https://packages.adoptium.net/artifactory/deb/</a> $(awk -F= ‘/VERSION_CODENAME/{print $2}’ /etc/os-release) main” | sudo tee /etc/apt/sources.list.d/adoptium.list</p><p># Re-update package index to include Adoptium packages</p><p>sudo apt update -y</p><p># Install Temurin-17 JDK</p><p>sudo apt install temurin-17-jdk -y</p><p># Verify Java installation</p><p>/usr/bin/java — version</p><p># — — 2. Install Jenkins — -</p><p>echo “ — — Stage 2: Installing Jenkins — -”</p><p># Download and install the Jenkins GPG key</p><p>curl -fsSL <a href="https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key">https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key</a> | sudo tee /usr/share/keyrings/jenkins-keyring.asc &gt; /dev/null</p><p># Add the Jenkins repository to the sources list</p><p>echo “deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] <a href="https://pkg.jenkins.io/debian-stable">https://pkg.jenkins.io/debian-stable</a> binary/” | sudo tee /etc/apt/sources.list.d/jenkins.list &gt; /dev/null</p><p># Update package index</p><p>sudo apt-get update -y</p><p># Install Jenkins</p><p>sudo apt-get install jenkins -y</p><p># Enable and start Jenkins service</p><p>sudo systemctl enable jenkins</p><p>sudo systemctl start jenkins</p><p># — — 3. Install Docker — -</p><p>echo “ — — Stage 3: Installing Docker — -”</p><p>sudo apt-get update -y</p><p>sudo apt-get install docker.io -y</p><p># Enable and start Docker service</p><p>sudo systemctl enable docker</p><p>sudo systemctl start docker</p><p># Add the current user (e.g., ‘ubuntu’) and jenkins user to the docker group</p><p># This allows them to run docker commands without sudo</p><p>USERNAME=$(whoami)</p><p>sudo usermod -aG docker $${USERNAME}</p><p>sudo usermod -aG docker jenkins</p><p># Allow access to the Docker socket for the initial setup (security risk, but common in labs)</p><p>sudo chmod 666 /var/run/docker.sock</p><p># — — 4. Setup SonarQube (using Docker) — -</p><p>echo “ — — Stage 4: Starting SonarQube via Docker — -”</p><p># Note: SonarQube requires at least a t2.medium instance type and may need JVM memory tuning.</p><p># Run SonarQube in the background on port 9000</p><p>docker run -d — name sonar -p 9000:9000 sonarqube:lts-community || echo “ERROR: A SonarQube failed to start — check Docker logs.”</p><p># — — 5. Install Trivy (Vulnerability Scanner) — -</p><p>echo “ — — Stage 5: Installing Trivy — -”</p><p># Install prerequisite packages for Trivy</p><p>sudo apt-get install -y wget apt-transport-https gnupg lsb-release</p><p># Download and add the Trivy GPG key</p><p>wget -qO — <a href="https://aquasecurity.github.io/trivy-repo/deb/public.key">https://aquasecurity.github.io/trivy-repo/deb/public.key</a> | gpg — dearmor | sudo tee /usr/share/keyrings/trivy.gpg &gt; /dev/null</p><p># Add the Trivy repository to the sources list</p><p>echo “deb [signed-by=/usr/share/keyrings/trivy.gpg] <a href="https://aquasecurity.github.io/trivy-repo/deb">https://aquasecurity.github.io/trivy-repo/deb</a> $(lsb_release -sc) main” | sudo tee /etc/apt/sources.list.d/trivy.list &gt; /dev/null</p><p># Update package index</p><p>sudo apt-get update</p><p># Install Trivy</p><p>sudo apt-get install trivy -y</p><p>echo “ — — — — — — — — — — — — — — — — — — — — — — — — — — — — “</p><p>echo “Deployment Complete.”</p><p>echo “Services running:”</p><p>echo “ — Jenkins on port 8080”</p><p>echo “ — SonarQube on port 9000”</p><p>echo “Initial Setup Instructions:”</p><p>echo “1. Wait for all services to start (up to 5 minutes).”</p><p>echo “2. Access Jenkins at: http://&lt;YOUR_EC2_PUBLIC_IP&gt;:8080”</p><p>echo “3. Access SonarQube at: http://&lt;YOUR_EC2_PUBLIC_IP&gt;:9000”</p><p>echo “4. Retrieve the Jenkins admin password: sudo cat /var/lib/jenkins/secrets/initialAdminPassword”</p><p>echo “5. Note: The chmod 666 /var/run/docker.sock command has been used for simplicity. In production, use tighter IAM/sudo rules.”</p><p>echo “ — — — — — — — — — — — — — — — — — — — — — — — — — — — — “</p><p>command</p><p>#terraform init</p><p>#terraform validate</p><p>#terraform plan</p><p>#terraform apply</p><p>my Ec2 Instance Create through that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bbCNNGgb5fPqNsuJPLWyGw.png" /></figure><p><a href="http://13.233.162.114:8080/"><strong>http://13.233.162.114:8080/</strong></a></p><p>68287a3cdbd947a2b87d2d523b7489c8</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t7JyAM6MySlzPphG8lqV_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RicGeX5rD3aQcUpvUhtzww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*APN-mi46ijpYU1OLkuyg_w.png" /></figure><p><a href="http://13.233.162.114:9000/sessions/new?return_to=%2F">http://13.233.162.114:9000/</a></p><p>username:admin</p><p>password:admin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PkY9CltUd7AKmOrLc34hUA.png" /></figure><h3>1. Install Required Jenkins Plugins</h3><h3>Steps:</h3><ol><li>Open <strong>Jenkins Dashboard</strong></li><li>Go to <strong>Manage Jenkins</strong></li><li>Click <strong>Plugins</strong></li><li>Open the <strong>Available plugins</strong> tab</li><li>Search and select the following plugins:</li></ol><h3>Plugins to Install:</h3><ul><li><strong>SonarQube Scanner</strong></li><li><strong>Docker</strong></li><li><strong>Docker Commons</strong></li><li><strong>Docker Pipeline</strong></li><li><strong>Docker API</strong></li><li><strong>Docker Build Step</strong></li><li><strong>Docker Compose Build Step</strong></li><li><strong>Docker Slaves</strong></li><li><strong>NodeJS</strong></li><li><strong>Eclipse Temurin Installer</strong></li><li><strong>Pipeline Stage View</strong></li></ul><ol><li>Click <strong>Install</strong></li><li>After installation, select <strong>Restart Jenkins once installation is complete</strong></li><li>Wait for Jenkins to restart</li><li>Sign in again</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tJedE4C7lpD5MhysoK7-Fw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TFRcUDdVE6hMu960vgcDOA.png" /></figure><h3>2. Configure Tools in Jenkins</h3><h3>Steps:</h3><ol><li>Go to <strong>Manage Jenkins</strong></li><li>Click <strong>System Configuration</strong></li><li>Open <strong>Tools</strong></li></ol><h3>3. Configure JDK (Java)</h3><ul><li><strong>Section:</strong> JDK installations</li><li><strong>Name:</strong> jdk17</li><li>⚠️ This name must match the name used in the Jenkins pipeline</li><li><strong>Check:</strong> Install automatically</li><li><strong>Version:</strong> 17.0.11+9 (Eclipse Temurin)</li><li>Click <strong>Save</strong></li></ul><h3>4. Configure Git</h3><ul><li><strong>Section:</strong> Git installations</li><li>Select <strong>Install automatically</strong></li><li>No name change required</li><li>Jenkins will handle Git automatically</li></ul><h3>5. Configure SonarQube Scanner</h3><ul><li><strong>Section:</strong> SonarQube Scanner installations</li><li><strong>Name:</strong> sonar-scanner</li><li>⚠️ Use the same name in the Jenkins pipeline</li><li><strong>Check:</strong> Install automatically</li><li>Click <strong>Save</strong></li></ul><h3>6. Configure NodeJS</h3><ul><li><strong>Section:</strong> NodeJS installations</li><li><strong>Name:</strong> node23</li><li><strong>Version:</strong> 23.0.0</li><li><strong>Check:</strong> Install automatically</li><li>Click <strong>Save</strong></li></ul><h3>7. Configure Docker</h3><ul><li><strong>Section:</strong> Docker installations</li><li><strong>Name:</strong> docker</li><li><strong>Check:</strong> Install automatically</li><li>Click <strong>Save</strong></li></ul><h3>8. Establish Connectivity Between Jenkins and SonarQube</h3><h3>Create SonarQube Token</h3><ol><li>Open <strong>SonarQube Dashboard</strong></li><li>Go to <strong>Administration</strong></li><li>Click <strong>Security</strong></li><li>Select <strong>Users / Tokens</strong></li><li>Create a new token:</li></ol><ul><li><strong>Token Name:</strong> token</li></ul><ol><li>Click <strong>Generate</strong></li><li>Copy the token (very important)</li></ol><h3>Add SonarQube Token in Jenkins Credentials</h3><h3>Steps:</h3><ol><li>Go to <strong>Jenkins Dashboard</strong></li><li>Click <strong>Manage Jenkins</strong></li><li>Open <strong>Credentials</strong></li><li>Select <strong>System</strong></li><li>Click <strong>Global credentials (unrestricted)</strong></li><li>Click <strong>Add Credentials</strong></li></ol><h3>Credential Details:</h3><ul><li><strong>Kind:</strong> Secret Text</li><li><strong>Secret:</strong> <em>(Paste SonarQube token here)</em></li><li><strong>ID:</strong> Sonar-token</li><li><strong>Description:</strong> SonarQube Token</li></ul><ol><li>Click <strong>Save</strong></li></ol><p>✅ This token will be used by Jenkins to authenticate with SonarQube.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x_-O8P4N6MDnlpNt2f2Wsw.png" /></figure><p>similarly create Add <strong>docker credentials</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yUCn2OmPjXmmbSR5RsGroQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ntkWAiqdykv41aG--0kyfQ.png" /></figure><h3>2. Create Webhook in SonarQube</h3><h3>Purpose:</h3><p>Webhook allows <strong>SonarQube to notify Jenkins</strong> about analysis results (Quality Gate status).</p><h3>Steps:</h3><ol><li>Open <strong>SonarQube Dashboard</strong></li><li>Go to <strong>Administration</strong></li><li>Click <strong>Configuration</strong></li><li>Select <strong>Webhooks</strong></li><li>Click <strong>Create</strong></li></ol><h3>Webhook Details:</h3><ul><li><strong>Name:</strong> jenkins</li><li><strong>URL (URI):</strong></li></ul><pre>http://&lt;JENKINS-IP&gt;:8080/sonarqube-webhook/</pre><p>📌 Example:</p><pre>http://192.168.1.10:8080/sonarqube-webhook/</pre><ol><li>Click <strong>Create</strong></li></ol><h3>Add SonarQube Server in Jenkins (System Configuration)</h3><h3>Steps:</h3><ol><li>Open <strong>Jenkins Dashboard</strong></li><li>Go to <strong>Manage Jenkins</strong></li><li>Click <strong>System</strong></li><li>Scroll down to <strong>SonarQube Servers</strong></li><li>Click <strong>Add SonarQube Server</strong></li></ol><h3>SonarQube Server Configuration:</h3><ul><li><strong>Name:</strong> sonar-server<br> <em>(Use the same name in your Jenkins pipeline)</em></li><li><strong>Server URL:</strong></li></ul><pre>http://&lt;SONARQUBE-IP&gt;:9000</pre><p>pipeline{<br> agent any<br> tools{<br> jdk ‘jdk17’<br> nodejs ‘node23’<br> }<br> environment {<br> SCANNER_HOME=tool ‘sonar-scanner’<br> }<br> stages {<br> stage(‘clean workspace’){<br> steps{<br> cleanWs()<br> }<br> }<br> stage(‘Checkout from Git’){<br> steps{<br> git branch: ‘main’, url: ‘<a href="https://github.com/Cloud-with-Prashant/Jenkins-Project.git&#39;">https://github.com/Cloud-with-Prashant/Jenkins-Project.git’</a><br> }<br> }<br> stage(“Sonarqube Analysis “){<br> steps{<br> withSonarQubeEnv(&#39;sonar-server&#39;) {<br> sh ‘’’ $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Swiggy \<br> -Dsonar.projectKey=Swiggy ‘’’<br> }<br> }<br> }<br> stage(“quality gate”){<br> steps {<br> script {<br> waitForQualityGate abortPipeline: false, credentialsId: ‘Sonar-token’ <br> }<br> } <br> }<br> stage(‘Install Dependencies’) {<br> steps {<br> sh “npm install”<br> }<br> }<br> <br> stage(‘TRIVY FS SCAN’) {<br> steps {<br> sh “trivy fs . &gt; trivyfs.txt”<br> }<br> }<br> stage(“Docker Build &amp; Push”){<br> steps{<br> script{<br> withDockerRegistry(credentialsId: ‘docker-creds’, toolName: ‘docker’){ <br> sh “docker build -t swiggy .”<br> sh “docker tag swiggy sanketbhavsar19/swiggy:latest “<br> sh “docker push sanketbhavsar19/swiggy:latest “<br> }<br> }<br> }<br> }<br> stage(“TRIVY”){<br> steps{<br> sh “trivy image sanketbhavsar19/swiggy:latest &gt; trivy.txt” <br> }<br> }<br> stage(‘Deploy to container’){<br> steps{<br> sh ‘docker run -d — name swiggy -p 3000:3000 sanketbhavsar19/swiggy:latest’<br> }<br> }<br> }<br>}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7d332a31506" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Student Application Portal — AWS Tier-3 Deployment]]></title>
            <link>https://medium.com/@sanket.bhavsarww/student-application-portal-aws-tier-3-deployment-026f11e6524f?source=rss-77a23ec3edac------2</link>
            <guid isPermaLink="false">https://medium.com/p/026f11e6524f</guid>
            <category><![CDATA[3-tier-architecture]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[aws-project]]></category>
            <dc:creator><![CDATA[Sanket Santosh Bhavsar]]></dc:creator>
            <pubDate>Sat, 10 Jan 2026 14:00:52 GMT</pubDate>
            <atom:updated>2026-01-10T14:00:52.252Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Student Application Portal — AWS Tier-3 Deployment</strong></h3><h3>🏗️ 1. Network Setup (VPC)</h3><h3>Create VPC</h3><ul><li>CIDR: 10.0.0.0/16</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pmyjckh5UGHmNtDbH_kEAQ.png" /></figure><h3>Create Subnets</h3><p>Create 2 subnet</p><p>tier3–1a-private 10.0.2.0/24</p><p>tier3–1a-public 10.0.1.0/24</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*onWvd63sh-KPdGevs5psQw.png" /></figure><p>Route tables</p><p>tier3-public-RT connect to subnet in explicit subnet association</p><p>similarly for tier3-private-RT</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OPeK9O7jdWChV0eeTtEvBw.png" /></figure><p>create internet gatway</p><p>Attached to vpc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDtDBAgZ-UW3mxZWH1Je3A.png" /></figure><h3>💻 EC2 Setup (Application Layer)</h3><ul><li>AMI: Amzon Linux</li><li>Instance type: t2.micro</li></ul><p>Subnet: <strong>Public Subnet</strong></p><ul><li>Security Group:</li><li>SSH (22) → Your IP</li><li>Backend (5000) → Anywhere</li><li>Frontend (80 / 5173) → Anywhere</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cQbdxiSNQrWhPyUl4mg8aA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vrhrGnFPFkZ0IBBE_QHMqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0SQIolPPCaklpTnpQULx7g.png" /></figure><p>launch ec2 instance -&gt;</p><p><strong>sudo -i</strong> run the command</p><p><strong>Update System Packages</strong></p><p>sudo apt update</p><p>sudo apt upgrade -y</p><p><strong>Step 3: Install Node.js and npm</strong></p><p>curl -fsSL <a href="https://deb.nodesource.com/setup_18.x">https://deb.nodesource.com/setup_18.x</a> | sudo -E bash -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9RBMF1OWmiZmyl8m7QAUVw.png" /></figure><p>sudo apt install -y nodejs</p><p>node — version # Verify installation</p><p>npm –version</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*pN8MUMPhtdcwQNC39GJBOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*CFstWtkQwbDNSDE_f6fygA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*Yj_jN7WtXb-UxEic2tA6vw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*jEhS_JiVsetpa6ElW5BcSA.png" /></figure><p><strong>Step 4: Update Environment Variables</strong></p><p>Update your .env file on EC2:<br> <br> DB_USER=postgres</p><p>DB_PASSWORD=your_rds_password</p><p>DB_HOST=your-rds-endpoint.c9akciq32.us-east-1.rds.amazonaws.com</p><p>DB_PORT=5432</p><p>DB_NAME=student_apps</p><p>VITE_API_URL=http://your-ec2-public-ip:5000<br> <br> <br> Get your <strong>RDS Endpoint</strong> from AWS Console → RDS → Your Database</p><p><strong>Step 5: Create Database Tables</strong></p><p>Connect to your RDS instance:</p><p>psql -h your-rds-endpoint.amazonaws.com -U postgres -d postgres</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*ls7FZ9DgpFFxhGAKZwZh_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rTXG8waJWn9q8yI4S01_GQ.png" /></figure><p>put password that we set on creating RDS enter to postgres database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/230/1*gOW3fKY7LNfLZqT7mYVUYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*mg9PTUVFmUBy8ExMzn-F2g.png" /></figure><p>now we create table</p><p>CREATE DATABASE student_app;</p><p>\c student_app</p><p>CREATE TABLE student_applications (</p><p>id UUID PRIMARY KEY DEFAULT gen_random_uuid(),</p><p>first_name TEXT NOT NULL,</p><p>last_name TEXT NOT NULL,</p><p>email TEXT NOT NULL,</p><p>phone TEXT NOT NULL,</p><p>date_of_birth DATE NOT NULL,</p><p>address TEXT NOT NULL,</p><p>city TEXT NOT NULL,</p><p>state TEXT NOT NULL,</p><p>zip_code TEXT NOT NULL,</p><p>country TEXT NOT NULL DEFAULT ‘United States’,</p><p>program_of_interest TEXT NOT NULL,</p><p>previous_education TEXT NOT NULL,</p><p>gpa NUMERIC(3,2),</p><p>test_scores TEXT,</p><p>extracurricular_activities TEXT,</p><p>personal_statement TEXT NOT NULL,</p><p>application_status TEXT NOT NULL DEFAULT ‘pending’,</p><p>submitted_at TIMESTAMPTZ DEFAULT now(),</p><p>updated_at TIMESTAMPTZ DEFAULT now(),</p><p>created_at TIMESTAMPTZ DEFAULT now()</p><p>);</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*z5h9vOcDU_OBX6yzdbxlTw.png" /></figure><p>Now create <strong>INDEX</strong></p><p>CREATE INDEX idx_student_applications_status ON student_applications(application_status);</p><p>CREATE INDEX idx_student_applications_submitted_at ON student_applications(submitted_at DESC);</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*YRucTOQGU-Gjs8LLkA6JCA.png" /></figure><p>student_app=&gt; \q</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*4m4-qo3bj3NaiWBBZrcxwA.png" /></figure><p>sudo npm install</p><p>sudo npm run build</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*iqASZD7XSmxQS50v84hD5g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*omXBtYltMgfT7BD7kRNcGg.png" /></figure><p>sudo apt install httpd</p><p>sudo apt install nginx</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*iGJnz81bRnYucyuaBDzmIg.png" /></figure><p>check nginx install or not</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qQiCPrSf953ch0TclTZa5w.png" /></figure><p><a href="http://public">http://public</a>-ip</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L1PHbTAUeNK3qHB4iczivQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HbHT3NnwkhNHFFDLcbe0yw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*gGUxQhgFeBd1YoGeoBvkdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*IzvAAODufSEOnUA7ud66UQ.png" /><figcaption>x`</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*KaaVorVj5b3emSl3RJhZSQ.png" /></figure><p><strong>8. Configure Security Groups</strong></p><p><strong>For RDS Security Group:</strong></p><ul><li>Allow inbound traffic on port 5432 from your EC2 instance’s security group</li></ul><p><strong>For EC2 Security Group:</strong></p><ul><li>Allow inbound SSH (port 22) from your IP</li><li>Allow inbound HTTP (port 80) — optional, for production use</li><li>Allow inbound on port 5000 (backend) from anywhere or specific IPs</li><li>Allow inbound on port 5173 (frontend dev) from your IP</li></ul><p><strong>#sudo vi /etc/systemd/system/student-app-frontend.service</strong></p><p>create this file in above location and put this content on that position</p><p><strong>10. Build and Serve Frontend</strong></p><p># Build React app</p><p><strong>#npm run build</strong></p><p># Install a simple HTTP server for production</p><p><strong>npm install -g serve</strong></p><p># Create frontend service</p><p><strong>#sudo vi /etc/systemd/system/student-app-frontend.service</strong></p><p>Paste this:</p><p>[Unit]</p><p>Description=Student Application Portal Frontend</p><p>After=network.target</p><p>[Service]</p><p>Type=simple</p><p>User=ec2-user</p><p>WorkingDirectory=/home/ec2-user/student-app</p><p>ExecStart=/usr/bin/serve -s /home/ec2-user/student-app/dist -l 80</p><p>Restart=always</p><p>RestartSec=10</p><p>[Install]</p><p>WantedBy=multi-user.target</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t1slyn6qp7NpFyUxOm2OPw.png" /></figure><p>Enable and start:</p><p><strong>#sudo systemctl daemon-reload</strong></p><p><strong>#sudo systemctl enable student-app-frontend</strong></p><p><strong>#sudo systemctl daemon-reload sudo systemctl daemon-reload</strong></p><p>Create Similar for Backend</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*o5HG9xAgdiuf1SwLh_2KJQ.png" /></figure><p><strong>9. Create systemd Services for Auto-Start</strong></p><p><strong>Create backend service:</strong></p><p><strong>sudo vi /etc/systemd/system/student-app-backend.service</strong></p><p>Paste this:</p><p>[Unit]</p><p>Description=Student Application Portal Backend</p><p>After=network.target</p><p>[Service]</p><p>Type=simple</p><p>User=ec2-user</p><p>WorkingDirectory=/home/ec2-user/student-app</p><p>EnvironmentFile=/home/ec2-user/student-app/.env</p><p>ExecStart=/usr/bin/node /home/ec2-user/student-app/server.js</p><p>Restart=always</p><p>RestartSec=10</p><p>[Install]</p><p>WantedBy=multi-user.target</p><p>Save and enable:</p><p>sudo systemctl daemon-reload</p><p><strong>#sudo systemctl enable student-app-backend</strong></p><p><strong>#sudo systemctl start student-app-backend</strong></p><p><strong>11. Verify Services Status</strong></p><p>#sudo systemctl status student-app-backend</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*3yPtd1oftcdHFiZgF0rjIg.png" /></figure><p>#sudo systemctl status student-app-frontend</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*Ehg3YM3UeLzwD-U-6FgtrQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j1dLoWqt9mBfoR_pTypnZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5DO1LBtjX38gchAuq98ULQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CI14ck7sxaWahZmplfd8bg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=026f11e6524f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Automating EC2 Instance Start/Stop using AWS Lambda and EventBridge]]></title>
            <link>https://medium.com/@sanket.bhavsarww/automating-ec2-instance-start-stop-using-aws-lambda-and-eventbridge-e6fc908b581c?source=rss-77a23ec3edac------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6fc908b581c</guid>
            <dc:creator><![CDATA[Sanket Santosh Bhavsar]]></dc:creator>
            <pubDate>Sat, 15 Nov 2025 07:32:07 GMT</pubDate>
            <atom:updated>2025-11-15T07:38:16.075Z</atom:updated>
            <content:encoded><![CDATA[<p>This guide provides a comprehensive, step-by-step walkthrough on how to create a serverless solution using AWS Lambda and Amazon EventBridge to automatically start and stop one or more EC2 instances. This is a powerful way to reduce cloud costs by ensuring your non-production instances only run when needed.</p><h3>1. ⚙️ Initial Setup: Networking and EC2 Instance</h3><p>Before deploying the automation, we need a target EC2 instance and a foundational network.</p><p>That is a fantastic, detailed project! The steps you’ve outlined for setting up the VPC components, IAM role, EC2 instance, and the two versions of the Lambda function (single and multiple instance control) are <strong>complete and technically accurate</strong>.</p><p>To turn this into a high-quality Medium post, you need to structure the content, add context, make the instructions clearer, and use compelling headings and formatting.</p><p>Here is a corrected, structured, and polished version of your project write-up, ready for Medium publication.</p><h3>🚀 Automating EC2 Instance Start/Stop using AWS Lambda and EventBridge</h3><p>This guide provides a comprehensive, step-by-step walkthrough on how to create a serverless solution using AWS Lambda and Amazon EventBridge to automatically start and stop one or more EC2 instances. This is a powerful way to reduce cloud costs by ensuring your non-production instances only run when needed.</p><h3>1. ⚙️ Initial Setup: Networking and EC2 Instance</h3><p>Before deploying the automation, we need a target EC2 instance and a foundational network.</p><h4>A. VPC and Subnet Configuration</h4><ol><li><strong>VPC:</strong> Ensure you have a Virtual Private Cloud (VPC) set up (you can use the default or a custom one).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*55H-ruAuzO3sv352QrTvRg.png" /></figure><p>subnet 1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H4-XpJAIgd6zho3iwdreTw.png" /></figure><ul><li><strong>Subnet Creation:</strong></li><li>Navigate to <strong>VPC &gt; Subnets</strong>.</li><li>Create a new subnet.</li><li><strong>Subnet Name:</strong> Test-Public-Subnet</li><li><strong>IPv4 Subnet CIDR Block:</strong> 10.1.1.0/24</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ImlKosiGbLaSbq_2dA0yQ.png" /></figure><p><strong>Route Table Association:</strong></p><ul><li>Create a <strong>2nd Route Table</strong> (or use an existing public one).</li><li>Ensure the new subnet (Test-Public-Subnet) is explicitly associated with this Route Table, which should have a route to the internet via an Internet Gateway.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f6i6WkOklbdMYDmHL8-AKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mYyaPSFMHnV8U1DOGmD9nw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IyFWOJbILh36h8pCRLeeFw.png" /></figure><p>Launch an Ec2 Instance</p><p>That is a fantastic, detailed project! The steps you’ve outlined for setting up the VPC components, IAM role, EC2 instance, and the two versions of the Lambda function (single and multiple instance control) are <strong>complete and technically accurate</strong>.</p><p>To turn this into a high-quality Medium post, you need to structure the content, add context, make the instructions clearer, and use compelling headings and formatting.</p><p>Here is a corrected, structured, and polished version of your project write-up, ready for Medium publication.</p><h3>🚀 Automating EC2 Instance Start/Stop using AWS Lambda and EventBridge</h3><p>This guide provides a comprehensive, step-by-step walkthrough on how to create a serverless solution using AWS Lambda and Amazon EventBridge to automatically start and stop one or more EC2 instances. This is a powerful way to reduce cloud costs by ensuring your non-production instances only run when needed.</p><h3>1. ⚙️ Initial Setup: Networking and EC2 Instance</h3><p>Before deploying the automation, we need a target EC2 instance and a foundational network.</p><h4>A. VPC and Subnet Configuration</h4><ol><li><strong>VPC:</strong> Ensure you have a Virtual Private Cloud (VPC) set up (you can use the default or a custom one).</li><li><strong>Subnet Creation:</strong></li></ol><ul><li>Navigate to <strong>VPC &gt; Subnets</strong>.</li><li>Create a new subnet.</li><li><strong>Subnet Name:</strong> Test-Public-Subnet</li><li><strong>IPv4 Subnet CIDR Block:</strong> 10.1.1.0/24</li></ul><ol><li><strong>Route Table Association:</strong></li></ol><p>Create a <strong>2nd Route Table</strong> (or use an existing public one).</p><ul><li>Ensure the new subnet (Test-Public-Subnet) is explicitly associated with this Route Table, which should have a route to the internet via an Internet Gateway.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*apmW0jU9AGVH4hdzZlEALw.png" /><figcaption>key Pair -&gt; select Process without Keypair</figcaption></figure><h4>B. Launching the Target EC2 Instance</h4><ol><li>Launch a new EC2 instance.</li><li>In the Network Settings, choose the VPC and the new subnet: Test-Public-Subnet.</li><li><strong>Key Pair:</strong> Select <strong>“Proceed without a key pair”</strong> for simplicity, as we will not be SSH-ing into it for this project.</li><li>Launch the instance and <strong>note its Instance ID</strong> (e.g., i-07f408988e04154a1). This ID is crucial for the Lambda function.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QmIdSZ8P3d1v8FdhXUSQnw.jpeg" /></figure><h3>🛡️ Creating the IAM Role (Permissions)</h3><p>The AWS Lambda function needs permission to interact with your EC2 instances. We will create a specific IAM Policy and Role for this purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C1V2jJWQezva3lM1wDfjSA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ke8KnHDrBjBmFsWTg-XcdA.jpeg" /></figure><p>Create RoleB. Create the IAM Role for Lambda</p><ol><li>Go to <strong>IAM &gt; Roles</strong> and click <strong>Create role</strong>.</li><li><strong>Trusted Entity Type:</strong> Select <strong>AWS service</strong>.</li><li><strong>Use Case:</strong> Select <strong>Lambda</strong>.</li><li><strong>Permissions:</strong></li></ol><ul><li>Search for and select your newly created policy: EC2_StartStop_Policy.</li><li><em>If you previously added the default </em><em>AmazonEC2FullAccess policy, </em><strong><em>remove it</em></strong><em>.</em></li></ul><ol><li>Name the Role (e.g., Lambda_Ec2_Start_Stop_Role).</li></ol><p>Now Create Policy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHkEZXobpQe4F3blg7FFpg.png" /></figure><p>Choose JSON</p><p>{<br> “Version”: “2012–10–17”,<br> “Statement”: [<br> {<br> “Action”: [<br> “ec2:StartInstances”,<br> “ec2:StopInstances”,<br> “ec2:DescribeInstances”<br> ],<br> “Effect”: “Allow”,<br> “Resource”: “*”<br> }<br> ]<br>}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UTrmY1Cg8UO3Zn2MMd6cxA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFBcuXzxxj0DKSdmcLdR5A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KAznzSlcLS0HP0Wxvwlp4w.png" /></figure><p>click to -&gt; Lambda_Ec2_Start_Stop -&gt; click Attach policies -&gt; Select Ec2_Lambda</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4vFRWRKJbmeuBsYQ_tiN0Q.png" /></figure><p>add permissions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hgeo6bp56bqu_ij5o0MVGg.png" /><figcaption>Remove Previously Created Policy AmazonEc2FullAccess</figcaption></figure><p>Goto Lambda</p><h3>. ☁️ Deploying the AWS Lambda Function</h3><p>Now we write the Python code that will do the heavy lifting. We will start with a function for a single instance and then improve it for multiple instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*POqCT_nFOuYvlf1z6wB5NA.jpeg" /></figure><p>Create Function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bDrIxfG2wgJ8--hCCp3ctg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cWs--6vX8BIGXZxxUwb7Lw.png" /></figure><p>import boto3</p><p>def lambda_handler(event, context):</p><p>ec2 = boto3.client(‘ec2’, region_name=’ap-south-1&#39;) # change to your region</p><p>instance_id = ‘i-07f408988e04154a1’ # ← replace with your actual ID</p><p>action = event.get(‘action’, ‘’).lower()</p><p>if action == ‘start’:</p><p>response = ec2.start_instances(InstanceIds=[instance_id])</p><p>print(f”Starting instance: {instance_id}”)</p><p>return {“status”: “starting”, “instance”: instance_id}</p><p>elif action == ‘stop’:</p><p>response = ec2.stop_instances(InstanceIds=[instance_id])</p><p>print(f”Stopping instance: {instance_id}”)</p><p>return {“status”: “stopping”, “instance”: instance_id}</p><p>else:</p><p>print(“Invalid action! Use ‘start’ or ‘stop’”)</p><p>return {“status”: “error”, “message”: “Invalid action! Use ‘start’ or ‘stop’”}</p><p>Put this code in lambda_function.py</p><p>click on -&gt; <strong>deploy</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7vqOqnyZetReLVb1VxaKCw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nJCMFT57uwZSd_QXh4198Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nVCTXbZ_G_x71V-AlB-maA.png" /></figure><p>increase the time out to 30sec</p><p>we want to start and stop with Ec2 Instance ID</p><p>Now we Test Our code so click on Test-&gt;Create New Test Event</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Jv7Vf2Idg9iR47gmC96IQ.png" /></figure><p>put Ec2 Instance -&gt; Instance id in our code -&gt; Line NO 5</p><p>click -&gt; deploy</p><p>click -&gt; Test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*gxigr_G_-1XDIP80jaI1KQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xWW0XmoDVF6F_leZYjx5jg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*0AO4XWZbW9CsrwedfFthcA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9F27kH7nDwvlL4kWIZr3cg.png" /></figure><p>now want to control <strong>multiple EC2 instances</strong> with a single Lambda function, let’s extend your code to handle <strong>a list of instance IDs</strong> instead of just one.</p><p>import boto3</p><p>def lambda_handler(event, context):</p><p># Initialize EC2 client</p><p>ec2 = boto3.client(‘ec2’, region_name=’ap-south-1&#39;) # Change to your region</p><p># List of instance IDs you want to manage</p><p>instance_ids = event.get(‘instance_ids’, [])</p><p># Get action from event input</p><p>action = event.get(‘action’, ‘’).lower()</p><p>if action == ‘start’:</p><p>response = ec2.start_instances(InstanceIds=instance_ids)</p><p>print(f”Starting instances: {instance_ids}”)</p><p>return {“status”: “starting”, “instances”: instance_ids}</p><p>elif action == ‘stop’:</p><p>response = ec2.stop_instances(InstanceIds=instance_ids)</p><p>print(f”Stopping instances: {instance_ids}”)</p><p>return {“status”: “stopping”, “instances”: instance_ids}</p><p>else:</p><p>print(“Invalid action! Use ‘start’ or ‘stop’”)</p><p>return {“status”: “error”, “message”: “Invalid action! Use ‘start’ or ‘stop’”}</p><p>{</p><h3>create new Test Event</h3><p>“action”: “start”,</p><p>“instance_ids”: [“i-07f408988e04154a1”, “i-093c83c1dced25e92”]</p><p>}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NmhrLm-d07-N8cVcJAKfrQ.png" /></figure><h3>⏰ Creating the Scheduler (Amazon EventBridge)</h3><p>To run this function automatically on a schedule (e.g., stopping instances at 7 PM and starting them at 7 AM), we use EventBridge (formerly CloudWatch Events).</p><ol><li>Go to <strong>Amazon EventBridge &gt; Rules/Schedules</strong>.</li><li>Click <strong>Create schedule</strong>.</li><li><strong>Schedule Name:</strong> Daily_EC2_Stop</li><li><strong>Schedule Pattern:</strong> Select <strong>Recurring schedule</strong>.</li><li><strong>Schedule Type:</strong> Choose <strong>Cron-based schedule</strong> for precise timing.</li></ol><ul><li><em>Example Cron (Stopping at 7:00 PM UTC/IST):</em> 0 19 ? * * *</li><li><em>Example Cron (Starting at 7:00 AM UTC/IST):</em> 0 7 ? * * *</li><li><strong>Crucial:</strong> Cron expressions are in <strong>UTC</strong>. Adjust the hour accordingly for your local time zone.</li></ul><ol><li><strong>Target:</strong> Select <strong>AWS Lambda API</strong> as the target.</li><li><strong>Function:</strong> Select your EC2_Manager Lambda function.</li><li><strong>Configure Input:</strong> Select <strong>Constant (JSON text)</strong> and paste the JSON input for the action (e.g., for stopping):</li><li>JSON</li></ol><ul><li>{ &quot;action&quot;: &quot;stop&quot;, &quot;instance_ids&quot;: [&quot;i-07f408988e04154a1&quot;, &quot;i-093c83c1dced25e92&quot;] }</li></ul><ol><li>Click <strong>Next</strong> and <strong>Create Schedule</strong>.</li></ol><p>Repeat the process for the Daily_EC2_Start schedule, changing the Cron expression and the &quot;action&quot; in the JSON input to &quot;start&quot;.</p><h3>✅ Conclusion</h3><p>You have successfully created a robust, serverless solution that uses <strong>AWS Lambda</strong> and <strong>Amazon EventBridge</strong> to manage your EC2 instances on a schedule. This is a fundamental and highly effective cloud cost-optimization technique!</p><h3>🤝 Follow My Work</h3><p>If you found this tutorial helpful and want to see more cloud automation projects, please consider following me on LinkedIn!</p><blockquote><strong>PlatformLink/Action🔗</strong><a href="http://www.linkedin.com/in/sanketbhavsar19"><strong> LinkedInFollow Me on LinkedIn!</strong></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6fc908b581c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>