<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Rajit Paul</title>
    <description>The latest articles on Forem by Rajit Paul (@rajitpaul).</description>
    <link>https://forem.com/rajitpaul</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F599923%2F80fcd0d3-e299-44a5-b109-43d522211510.png</url>
      <title>Forem: Rajit Paul</title>
      <link>https://forem.com/rajitpaul</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rajitpaul"/>
    <language>en</language>
    <item>
      <title>Detect, Collect, Isolate: Automated EC2 Malware Response with GuardDuty</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Sat, 11 Apr 2026 10:58:55 +0000</pubDate>
      <link>https://forem.com/aws-builders/detect-collect-isolate-automated-ec2-malware-response-with-guardduty-23bb</link>
      <guid>https://forem.com/aws-builders/detect-collect-isolate-automated-ec2-malware-response-with-guardduty-23bb</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;It's 2 AM. GuardDuty just flagged a malware finding on one of your EC2 instances. What happens next determines whether you have a contained incident or a full-blown breach. If the answer is "someone gets paged and logs in manually" — you already have a problem.&lt;/p&gt;

&lt;p&gt;This blog walks through building a fully automated incident response pipeline on AWS that triggers the moment GuardDuty raises a malware finding — no human in the loop, no delay.&lt;/p&gt;

&lt;p&gt;The goal is to achieve three things automatically, without any human action:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Collect forensic evidence&lt;/strong&gt; — capture a live memory dump, running processes, network connections, and a full EBS snapshot of the compromised instance&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upload to S3&lt;/strong&gt; — preserve all artifacts in a secure, durable location before any evidence is lost&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Isolate the instance&lt;/strong&gt; — replace its security group with a lockdown SG that cuts off all inbound and outbound network access, containing the threat immediately&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The pipeline is built entirely on native AWS services — GuardDuty, EventBridge, SSM Automation, SNS, S3, and EC2 — with no third-party tooling required.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi50i0hte02b2x96d32is.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi50i0hte02b2x96d32is.png" alt="Architecture Diagram — GuardDuty automated response pipeline" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;CLI note:&lt;/strong&gt; All AWS CLI commands in this blog were run using &lt;strong&gt;AWS CloudShell&lt;/strong&gt; directly from the AWS Console — no local CLI setup or credentials configuration needed. You can launch CloudShell from the top navigation bar in the AWS Console (the terminal icon &lt;code&gt;&amp;gt;_&lt;/code&gt;). It comes with the AWS CLI pre-installed and automatically authenticated to your account.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  What is Amazon GuardDuty?
&lt;/h2&gt;

&lt;p&gt;Amazon GuardDuty is a managed threat detection service that continuously analyses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VPC Flow Logs&lt;/li&gt;
&lt;li&gt;DNS Logs&lt;/li&gt;
&lt;li&gt;CloudTrail Events&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It uses threat intelligence, behavioural analysis, and ML models to detect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Credential Compromise&lt;/li&gt;
&lt;li&gt;Crypto Mining&lt;/li&gt;
&lt;li&gt;Backdoor Communication&lt;/li&gt;
&lt;li&gt;Malware Detection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;GuardDuty is not a preventive control — it is a detective control. It detects and signals; what you build on top of it is what actually stops the damage — which is exactly what this blog is about.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8vmnyhtc2z9pv711i80.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8vmnyhtc2z9pv711i80.png" alt="GuardDuty Findings" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Types of Malware Protection in GuardDuty
&lt;/h2&gt;

&lt;p&gt;Amazon GuardDuty provides agentless malware scanning for EC2 instances. There are two types of malware scans:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. GuardDuty Initiated Malware Scan&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This scan runs automatically when GuardDuty detects malware-related findings on an EC2 instance. It creates snapshots of the instance's attached EBS volumes and scans those snapshots for known malware and suspicious artifacts.&lt;/p&gt;

&lt;p&gt;If malware is found, GuardDuty generates a malware finding linked to the original security signal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. On-Demand Malware Scan&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An on-demand scan is manually triggered by the user and does not depend on existing GuardDuty findings. When initiated, GuardDuty follows the same procedure — taking EBS snapshots, scanning them for malware, and reporting the result as a GuardDuty Malware Finding if detected.&lt;/p&gt;

&lt;p&gt;This scan type is commonly used during investigations, after remediation, or to proactively verify an instance. We will use this later to validate our workflow.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we get started with the implementation, the following must be in place.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. AWS Account
&lt;/h3&gt;

&lt;p&gt;An active &lt;a href="https://aws.amazon.com/resources/create-account/" rel="noopener noreferrer"&gt;AWS Account&lt;/a&gt; with permissions to manage EC2, IAM, SSM, GuardDuty, EventBridge, SNS, S3 and CloudFormation.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. EC2 Instance
&lt;/h3&gt;

&lt;p&gt;Any Linux-based EC2 instance will work — this will be the target instance for the malware simulation and forensic workflow. For this demo I am using Amazon Linux 2023.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SSM Agent&lt;/strong&gt; must be running on the instance for Run Command and Session Manager to function. Amazon Linux 2 and Amazon Linux 2023 come with SSM Agent pre-installed and running. Newer AMIs of Ubuntu, CentOS, and RHEL may also include it out of the box — but don't assume. Verify it is active before proceeding:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status amazon-ssm-agent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it is not installed or not running, follow the official &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/manually-install-ssm-agent-linux.html" rel="noopener noreferrer"&gt;SSM Agent installation guide&lt;/a&gt; for your specific distribution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff2zoyr0u2jsighirz5yb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff2zoyr0u2jsighirz5yb.png" alt="EC2 Instance with IAM Role attached" width="800" height="299"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  3. IAM Role for the EC2 Instance
&lt;/h3&gt;

&lt;p&gt;Attach an IAM role to the instance with the following two policies:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AmazonSSMManagedInstanceCore&lt;/strong&gt; — AWS managed policy, allows SSM Agent to communicate with the Systems Manager service (required for Run Command and Session Manager).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;S3 Evidence Upload&lt;/strong&gt; — inline policy granting the instance permission to upload forensic archives to the S3 bucket:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"s3:PutObject"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::guardduty-malware-demo/guardduty-ec2-malware/*"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The instance uploads forensic data to S3 using its own IAM role — not the SSM Automation role — since the script runs directly on the instance.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;KMS for Session Manager (optional)&lt;/strong&gt; — only if you enable &lt;strong&gt;encryption of Session Manager data&lt;/strong&gt; with a customer-managed KMS key in &lt;strong&gt;Systems Manager → Session Manager → Preferences&lt;/strong&gt;. The SSM agent on the instance must be allowed to use that key for the session channel (including after isolation, when traffic goes through the KMS VPC endpoint). Add an inline policy on the same instance role that grants &lt;code&gt;kms:Decrypt&lt;/code&gt; on your key ARN (replace with your key ID, Account ID and Region):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"kms:Decrypt"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:kms:REGION:ACCOUNT_ID:key/KEY_ID"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are not using KMS for Session Manager, skip this policy and the KMS VPC endpoint in the deployment section.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. S3 Bucket for Forensic Evidence
&lt;/h3&gt;

&lt;p&gt;Create the S3 bucket that will store forensic archives and confirm it exists before running the automation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 mb s3://guardduty-malware-demo &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Replace &lt;code&gt;guardduty-malware-demo&lt;/code&gt; with your own bucket name. Once you’ve done that, update the &lt;strong&gt;S3 Evidence Upload&lt;/strong&gt; inline policy in section 3 (the &lt;code&gt;Resource&lt;/code&gt; ARN). When you reach Create the SSM Automation Document, set the document's default &lt;code&gt;S3BucketName&lt;/code&gt; in &lt;code&gt;ssm-automation-document-inline.json&lt;/code&gt; to match.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Enable GuardDuty and Malware Protection for EC2
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_settingup.html#guardduty_enable-gd" rel="noopener noreferrer"&gt;Enable GuardDuty&lt;/a&gt; in your AWS account if not already active.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpf3nobtiwglk1n1podg8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpf3nobtiwglk1n1podg8.png" alt="GuardDuty Console" width="800" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once GuardDuty is enabled, go to &lt;strong&gt;Malware Protection&lt;/strong&gt; on the left pane and enable the feature for EC2.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxr03x642o9dw79b3kqah.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxr03x642o9dw79b3kqah.png" alt="Malware Protection For EC2" width="800" height="297"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Deploy VPC Interface Endpoints
&lt;/h2&gt;

&lt;p&gt;We deploy the following four VPC Interface Endpoints:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;ssm&lt;/code&gt;, &lt;code&gt;ssmmessages&lt;/code&gt;, &lt;code&gt;ec2messages&lt;/code&gt;&lt;/strong&gt; — core SSM endpoints required for two reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;During forensic collection:&lt;/strong&gt; SSM Run Command needs to reach the instance to execute the forensic script, particularly when the instance is in a private subnet with no internet route.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;After isolation:&lt;/strong&gt; Once the isolation SG is applied, all internet access is cut off. These endpoints are the only way to connect to the instance via Session Manager for further manual forensic investigation.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;kms&lt;/code&gt;&lt;/strong&gt; — required only if your SSM sessions are encrypted with a customer-managed KMS key. When KMS encryption is enabled, the SSM agent must call the KMS API to generate and decrypt session data keys — without this endpoint, that call fails on an isolated instance since there is no internet access. If you are not using KMS session encryption, you can remove this endpoint from the CloudFormation template.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Public subnet note:&lt;/strong&gt; If your instance is in a public subnet and you only need SSM during the automated collection phase (before isolation), VPC endpoints are not strictly required — SSM works over the internet. However, they are still needed for post-isolation Session Manager access regardless of subnet type.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Use this &lt;a href="https://raw.githubusercontent.com/Rajit11/guardduty-malware-isolation-demo/refs/heads/main/vpc-ssm-endpoints.yaml" rel="noopener noreferrer"&gt;CloudFormation template&lt;/a&gt; to create the SSM endpoints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws cloudformation create-stack &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--stack-name&lt;/span&gt; vpc-ssm-endpoints &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--template-body&lt;/span&gt; file://vpc-ssm-endpoints.yaml &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--parameters&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nv"&gt;ParameterKey&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;VpcId,ParameterValue&lt;span class="o"&gt;=&lt;/span&gt;vpc-xxxxx &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nv"&gt;ParameterKey&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;VpcCidr,ParameterValue&lt;span class="o"&gt;=&lt;/span&gt;10.0.0.0/16 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nv"&gt;ParameterKey&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;SubnetIds,ParameterValue&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"subnet-xxxxx&lt;/span&gt;&lt;span class="se"&gt;\,&lt;/span&gt;&lt;span class="s2"&gt;subnet-yyyyy"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;SubnetIds&lt;/strong&gt; — subnets where your EC2 instances are launched. Deploy endpoints across multiple subnets for fault tolerance, or a single subnet to minimise cost — interface endpoints are billed per Availability Zone.&lt;/p&gt;




&lt;h2&gt;
  
  
  Create the Isolation Security Group
&lt;/h2&gt;

&lt;p&gt;This security group is attached to the compromised instance as the final automation step. It blocks all inbound traffic and restricts outbound to HTTPS only towards the SSM VPC endpoints — keeping the instance completely isolated from the internet and all other VPC resources while still allowing Session Manager access for post-isolation forensic investigation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create the isolation SG&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 create-security-group &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--group-name&lt;/span&gt; ec2-isolation-sg &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--description&lt;/span&gt; &lt;span class="s2"&gt;"Isolation SG - SSM access only, no internet"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--vpc-id&lt;/span&gt; vpc-xxxxx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Remove the default allow-all egress rule&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 revoke-security-group-egress &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--group-id&lt;/span&gt; sg-ISOLATION_SG_ID &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--protocol&lt;/span&gt; &lt;span class="nt"&gt;-1&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--cidr&lt;/span&gt; 0.0.0.0/0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Get the SSM endpoint SG ID from the CloudFormation stack output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;ENDPOINT_SG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws cloudformation describe-stacks &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--stack-name&lt;/span&gt; vpc-ssm-endpoints &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s1"&gt;'Stacks[0].Outputs[?OutputKey==`EndpointSecurityGroupId`].OutputValue'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--output&lt;/span&gt; text &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Add outbound rule allowing HTTPS only to the SSM endpoint SG&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 authorize-security-group-egress &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--group-id&lt;/span&gt; sg-ISOLATION_SG_ID &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--protocol&lt;/span&gt; tcp &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--port&lt;/span&gt; 443 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--source-group&lt;/span&gt; &lt;span class="nv"&gt;$ENDPOINT_SG&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The isolation SG now has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inbound:&lt;/strong&gt; no rules — no traffic can reach the instance&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Outbound:&lt;/strong&gt; HTTPS (443) to the SSM endpoint SG only — allows Session Manager for post-isolation forensics, blocks everything else including internet&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Why not allow-all outbound?&lt;/strong&gt; Allowing only the SSM endpoint SG as the destination means the instance can talk to SSM but cannot reach any other host in the VPC or the internet, even over HTTPS. This is a tightly scoped rule that preserves network isolation while enabling investigator access.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  SSM Automation IAM Role
&lt;/h2&gt;

&lt;p&gt;This role is used by the SSM Automation document during execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create trust policy&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;cat&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;ssm-automation-trust-policy.json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&amp;lt;EOF&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Principal"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"Service"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ssm.amazonaws.com"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sts:AssumeRole"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;EOF&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create IAM Role&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam create-role &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--role-name&lt;/span&gt; GuardDuty-SSM-Automation-Role &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--assume-role-policy-document&lt;/span&gt; file://ssm-automation-trust-policy.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Attach Inline Policy&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;cat&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;ssm-automation-permissions.json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&amp;lt;EOF&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"ec2:DescribeInstances"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"ec2:ModifyInstanceAttribute"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"ec2:CreateSnapshot"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"ec2:CreateTags"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"ssm:SendCommand"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"ssm:ListCommands"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"ssm:ListCommandInvocations"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"ssm:GetCommandInvocation"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"ssm:DescribeInstanceInformation"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;EOF&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam put-role-policy &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--role-name&lt;/span&gt; GuardDuty-SSM-Automation-Role &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--policy-name&lt;/span&gt; SSM-Automation-Permissions &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--policy-document&lt;/span&gt; file://ssm-automation-permissions.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Installing Forensic Collection Prerequisites
&lt;/h2&gt;

&lt;p&gt;The automation triggers immediately on a GuardDuty finding and cannot download tools at runtime. Install the following on the instance in advance — ideally as part of your golden AMI, or on-demand via SSM for existing instances.&lt;/p&gt;

&lt;h3&gt;
  
  
  AVML
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Already running instances&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ssm send-command &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--document-name&lt;/span&gt; &lt;span class="s2"&gt;"AWS-RunShellScript"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--targets&lt;/span&gt; &lt;span class="s2"&gt;"Key=tag:Environment,Values=nonProd"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--parameters&lt;/span&gt; &lt;span class="s1"&gt;'commands=["wget -q https://github.com/microsoft/avml/releases/download/v0.14.0/avml -O /usr/bin/avml","chmod +x /usr/bin/avml","avml --version"]'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;New instance user data&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
wget &lt;span class="nt"&gt;-q&lt;/span&gt; https://github.com/microsoft/avml/releases/download/v0.14.0/avml &lt;span class="nt"&gt;-O&lt;/span&gt; /usr/bin/avml
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x /usr/bin/avml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  AWS CLI
&lt;/h3&gt;

&lt;p&gt;Follow the official &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; to install AWS CLI on your instance.&lt;/p&gt;




&lt;h2&gt;
  
  
  Create the SSM Automation Document
&lt;/h2&gt;

&lt;p&gt;Download the &lt;a href="https://raw.githubusercontent.com/Rajit11/guardduty-malware-isolation-demo/refs/heads/main/ssm-automation-document-inline.json" rel="noopener noreferrer"&gt;SSM Automation Document&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The default reaction is to isolate immediately — but that will make the instance go dark and cut off our S3 upload path. In practice, it’s often more effective to grab the forensic data first, then lock things down.&lt;/p&gt;

&lt;p&gt;The automation executes the following steps in order:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;GetInstanceDetails&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Looks up the EBS volume ID&lt;/td&gt;
&lt;td&gt;Required for snapshot creation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CollectForensicData&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Captures live memory, processes, network connections and uploads to S3&lt;/td&gt;
&lt;td&gt;Done first, while the instance still has network access&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CreateEBSSnapshot&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Creates a forensic EBS snapshot&lt;/td&gt;
&lt;td&gt;EC2 API call — no instance network access needed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ReplaceSecurityGroup&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Swaps to the isolation SG&lt;/td&gt;
&lt;td&gt;Network lockdown happens last, after data is safely in S3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The document accepts the following parameters:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Required&lt;/th&gt;
&lt;th&gt;Default&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;InstanceId&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;EC2 instance ID from the GuardDuty finding&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;IsolationSecurityGroupId&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;ID of the isolation SG to apply as the final step&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;AutomationAssumeRole&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;ARN of the IAM role assumed by SSM Automation during execution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;S3BucketName&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;&lt;code&gt;guardduty-malware-demo&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;S3 bucket where forensic archives are uploaded. Override by updating the &lt;code&gt;default&lt;/code&gt; value in the document or passing it explicitly in the EventBridge &lt;code&gt;InputTemplate&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;AwsRegion&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ap-south-1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;AWS region for the S3 upload — passed explicitly to avoid runtime region detection failures on instances with restricted IMDS access. Override by updating the &lt;code&gt;AwsRegion&lt;/code&gt; value in &lt;code&gt;eventbridge-targets.json&lt;/code&gt; &lt;code&gt;InputTemplate&lt;/code&gt; before running &lt;code&gt;put-targets&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Create the SSM Automation document&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ssm create-document &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; GuardDuty-EC2-Isolate-And-Collect &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--document-type&lt;/span&gt; Automation &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--document-format&lt;/span&gt; JSON &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--content&lt;/span&gt; file://ssm-automation-document-inline.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fethrg9m1w4oxh8urcb2h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fethrg9m1w4oxh8urcb2h.png" alt="SSM Automation Document" width="539" height="1163"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Create IAM Role for EventBridge
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Create trust policy&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;cat&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;eventbridge-trust-policy.json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&amp;lt;EOF&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Principal"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"Service"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"events.amazonaws.com"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sts:AssumeRole"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;EOF&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create role&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam create-role &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--role-name&lt;/span&gt; GuardDuty-EventBridge-Role &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--assume-role-policy-document&lt;/span&gt; file://eventbridge-trust-policy.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Attach permissions&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;cat&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;eventbridge-permissions.json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&amp;lt;EOF&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ssm:StartAutomationExecution"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:ssm:*:*:automation-definition/GuardDuty-EC2-Isolate-And-Collect:*"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sns:Publish"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:sns:*:*:guardduty-malware-alerts"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"iam:PassRole"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:iam::*:role/GuardDuty-SSM-Automation-Role"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;EOF&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam put-role-policy &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--role-name&lt;/span&gt; GuardDuty-EventBridge-Role &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--policy-name&lt;/span&gt; EventBridge-Permissions &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--policy-document&lt;/span&gt; file://eventbridge-permissions.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Create SNS Topic for Notifications
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws sns create-topic &lt;span class="nt"&gt;--name&lt;/span&gt; guardduty-malware-alerts &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Subscribe your email&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws sns subscribe &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--topic-arn&lt;/span&gt; arn:aws:sns:REGION:ACCOUNT_ID:guardduty-malware-alerts &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--protocol&lt;/span&gt; email &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--notification-endpoint&lt;/span&gt; your-email@example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Confirm the subscription from your email&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdzpp79flpcdydy3jk7iv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdzpp79flpcdydy3jk7iv.png" alt="SNS Confirmation" width="586" height="260"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Create EventBridge Rule
&lt;/h2&gt;

&lt;p&gt;Download &lt;a href="https://raw.githubusercontent.com/Rajit11/guardduty-malware-isolation-demo/refs/heads/main/eventbridge-rule-pattern.json" rel="noopener noreferrer"&gt;eventbridge-rule-pattern.json&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws events put-rule &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; guardduty-malware-response &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--event-pattern&lt;/span&gt; file://eventbridge-rule-pattern.json &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--state&lt;/span&gt; ENABLED &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--role-arn&lt;/span&gt; arn:aws:iam::ACCOUNT_ID:role/GuardDuty-EventBridge-Role
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Download &lt;a href="https://raw.githubusercontent.com/Rajit11/guardduty-malware-isolation-demo/refs/heads/main/eventbridge-targets.json" rel="noopener noreferrer"&gt;eventbridge-targets.json&lt;/a&gt; and replace the following placeholders before running the command:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Placeholder&lt;/th&gt;
&lt;th&gt;Replace with&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;REGION&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Your AWS region (e.g. &lt;code&gt;ap-south-1&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ACCOUNT_ID&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Your 12-digit AWS account ID&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;sg-YOUR_ISOLATION_SG_ID&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The isolation SG ID created earlier&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;AwsRegion&lt;/code&gt; value&lt;/td&gt;
&lt;td&gt;Replace &lt;code&gt;ap-south-1&lt;/code&gt; with your actual AWS region if you are not deploying in Mumbai (e.g. &lt;code&gt;us-east-1&lt;/code&gt;, &lt;code&gt;eu-west-1&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Add EventBridge targets (SNS + SSM)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws events put-targets &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--rule&lt;/span&gt; guardduty-malware-response &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--targets&lt;/span&gt; file://eventbridge-targets.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq674avd0k9ig4xfyipds.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq674avd0k9ig4xfyipds.png" alt="Eventbridge Rules with Targets" width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Test with EICAR Malware
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1 — Connect to the instance via Session Manager&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Via AWS Console:&lt;/strong&gt;&lt;br&gt;
Go to &lt;strong&gt;EC2 → Instances → select your instance → Connect → Session Manager tab → Connect&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Via CLI:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ssm start-session &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--target&lt;/span&gt; i-INSTANCE_ID &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once connected, switch to the ec2-user (or your OS-specific user) for the correct home directory context:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;su - ec2-user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2 — Download the EICAR test file&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;EICAR is a completely harmless standardised test file — it contains no malicious code, but antivirus and detection tools are programmed to flag it exactly as they would real malware. It's the industry-standard safe way to test detection pipelines.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-o&lt;/span&gt; /home/ec2-user/eicar.com https://secure.eicar.org/eicar.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The path &lt;code&gt;/home/ec2-user/&lt;/code&gt; is the default home directory on Amazon Linux. Replace &lt;code&gt;ec2-user&lt;/code&gt; with the appropriate username for your OS — for example &lt;code&gt;ubuntu&lt;/code&gt; on Ubuntu, or &lt;code&gt;centos&lt;/code&gt; on CentOS.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Validate the Workflow with an On-Demand Malware Scan
&lt;/h2&gt;

&lt;p&gt;Rather than waiting for GuardDuty to detect the file organically, we will trigger an &lt;strong&gt;On-Demand Malware Scan&lt;/strong&gt; directly against the instance to validate the end-to-end workflow.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; GuardDuty on-demand malware scanning is not covered under the free trial.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Get the instance ARN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go to &lt;strong&gt;EC2 Console → Instances → select your instance → Details tab&lt;/strong&gt; and copy the &lt;strong&gt;Instance ARN&lt;/strong&gt; field. It follows the format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arn:aws:ec2:ap-south-1:ACCOUNT_ID:instance/i-INSTANCE_ID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Trigger the on-demand scan&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the GuardDuty console in the correct Region (e.g. ap-south-1).&lt;/li&gt;
&lt;li&gt;In the left navigation pane, open Malware Protection, then View Feature for EC2.&lt;/li&gt;
&lt;li&gt;Paste the Amazon EC2 instance ARN for On-Demand malware scan and start scan.&lt;/li&gt;
&lt;li&gt;Click on See malware scan details to monitor the malware scan.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jcvx5j37zgrpm5jpfay.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jcvx5j37zgrpm5jpfay.png" alt="Start Malware Scan" width="800" height="693"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fae5igy7jy4xjtijwpxis.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fae5igy7jy4xjtijwpxis.png" alt="See Malware Scan Details" width="800" height="47"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GuardDuty will detect the file and raise a &lt;code&gt;Execution:EC2/MaliciousFile&lt;/code&gt; finding.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F55mo89xf7jplaku9p8r8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F55mo89xf7jplaku9p8r8.png" alt="GuardDuty Malware Finding" width="800" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7mxzdmc4sb75xihpy6ly.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7mxzdmc4sb75xihpy6ly.png" alt="GuardDuty Malware Finding" width="800" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This finding triggers the configured EventBridge rule, which in turn starts the SSM Automation — mirroring the same flow as an organic detection. At the same time, an SNS notification is sent to alert responders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SNS Alert&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxfd2dn6h13jar1bjn96m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxfd2dn6h13jar1bjn96m.png" alt="SNS Alert" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SSM Automation&lt;/strong&gt;&lt;br&gt;
As part of the automated response, the runbook performs the following actions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Collect live forensic data (memory, processes, network connections) and upload to S3&lt;/li&gt;
&lt;li&gt;Create an EBS snapshot of the root volume&lt;/li&gt;
&lt;li&gt;Replace the instance's security group with the isolation SG — cutting off all internet and VPC traffic&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Successful SSM Automation Execution&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff292072s4ui65nozvk7l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff292072s4ui65nozvk7l.png" alt="SSM Automation Success" width="800" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feexodhlix7ms0prl59bg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feexodhlix7ms0prl59bg.png" alt="SSM Automation Execution" width="800" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Forensic EBS Snapshot&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjfuuhjwq3jh2uxen8dz9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjfuuhjwq3jh2uxen8dz9.png" alt="Forensic EBS Snapshot" width="800" height="312"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  What's inside the forensic archive
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62swek93xl2ib7h468qt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62swek93xl2ib7h468qt.png" alt="S3-Forensic" width="800" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once uploaded to S3, the tar.gz contains a complete snapshot of the instance's runtime state at the time of detection:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwfk1jtdu5t2yvhdv36lv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwfk1jtdu5t2yvhdv36lv.png" alt="Extracted Forensic Tar Archive" width="800" height="581"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File / Folder&lt;/th&gt;
&lt;th&gt;What it contains&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;memory.lime&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Full memory dump captured by AVML — used for deep malware analysis, extracting encryption keys, recovering injected code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;processes.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Full process list with user, CPU, memory, command line (&lt;code&gt;ps auxww&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;process-tree.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Process tree with PID, PPID, state and start time — helps identify parent-child relationships of suspicious processes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;network-connections.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;All active TCP/UDP connections and listening ports — identifies C2 channels or lateral movement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;proc/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Per-process details from &lt;code&gt;/proc&lt;/code&gt; — command line, environment variables, open file descriptors and status for every running process&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mounts.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Mounted filesystems — identifies unexpected mounts or bind mounts used for evasion&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;disk-usage.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Filesystem usage at time of collection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;system-info.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Kernel version and architecture (&lt;code&gt;uname -a&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;os-release.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;OS distribution and version&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;active-users.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Currently logged-in users (&lt;code&gt;who&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;recent-logins.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Last 20 login events — identifies suspicious access prior to detection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;crontab.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Root crontab — checks for persistence via scheduled tasks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;cron-jobs.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contents of &lt;code&gt;/etc/cron.*&lt;/code&gt; directories — system-wide scheduled jobs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Isolated EC2 instance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff2mvn9lxt513i06jklfi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff2mvn9lxt513i06jklfi.png" alt="Isolated EC2 instance" width="800" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After isolation, you can still connect to the instance via &lt;strong&gt;Session Manager&lt;/strong&gt; for further manual forensic investigation — refer to the Session Manager connect steps in the Test with EICAR Malware section above.&lt;/p&gt;


&lt;h2&gt;
  
  
  Cleanup
&lt;/h2&gt;

&lt;p&gt;Once you are done testing, remove all resources created in this demo to avoid unnecessary charges.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Restore the instance's original security group&lt;/strong&gt; (before terminating or reusing it)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 modify-instance-attribute &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--instance-id&lt;/span&gt; i-INSTANCE_ID &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--groups&lt;/span&gt; sg-ORIGINAL_SG_ID &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Delete the EventBridge rule and targets&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws events remove-targets &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--rule&lt;/span&gt; guardduty-malware-response &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--ids&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt; &lt;span class="s2"&gt;"2"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1

aws events delete-rule &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; guardduty-malware-response &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Delete the SNS topic&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws sns delete-topic &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--topic-arn&lt;/span&gt; arn:aws:sns:ap-south-1:ACCOUNT_ID:guardduty-malware-alerts &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Delete the SSM Automation document&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ssm delete-document &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; GuardDuty-EC2-Isolate-And-Collect &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Delete the IAM roles and their inline policies&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam delete-role-policy &lt;span class="nt"&gt;--role-name&lt;/span&gt; GuardDuty-SSM-Automation-Role &lt;span class="nt"&gt;--policy-name&lt;/span&gt; SSM-Automation-Permissions
aws iam delete-role &lt;span class="nt"&gt;--role-name&lt;/span&gt; GuardDuty-SSM-Automation-Role

aws iam delete-role-policy &lt;span class="nt"&gt;--role-name&lt;/span&gt; GuardDuty-EventBridge-Role &lt;span class="nt"&gt;--policy-name&lt;/span&gt; EventBridge-Permissions
aws iam delete-role &lt;span class="nt"&gt;--role-name&lt;/span&gt; GuardDuty-EventBridge-Role
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Delete the isolation security group&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 delete-security-group &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--group-id&lt;/span&gt; sg-ISOLATION_SG_ID &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Delete the CloudFormation stack (SSM VPC endpoints)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws cloudformation delete-stack &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--stack-name&lt;/span&gt; vpc-ssm-endpoints &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8. Delete forensic EBS snapshots&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 describe-snapshots &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--filters&lt;/span&gt; &lt;span class="s2"&gt;"Name=tag:Forensics,Values=GuardDuty-Malware"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s1"&gt;'Snapshots[*].SnapshotId'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--output&lt;/span&gt; text &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1 | &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nb"&gt;tr&lt;/span&gt; &lt;span class="s1"&gt;'\t'&lt;/span&gt; &lt;span class="s1"&gt;'\n'&lt;/span&gt; | xargs &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt; aws ec2 delete-snapshot &lt;span class="nt"&gt;--snapshot-id&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt; &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;9. Empty and delete the S3 bucket&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 &lt;span class="nb"&gt;rm &lt;/span&gt;s3://guardduty-malware-demo &lt;span class="nt"&gt;--recursive&lt;/span&gt; &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
aws s3 rb s3://guardduty-malware-demo &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;10. Terminate the EC2 instance&lt;/strong&gt; &lt;em&gt;(if no longer needed)&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 terminate-instances &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--instance-ids&lt;/span&gt; i-INSTANCE_ID &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; ap-south-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Closing Thoughts
&lt;/h2&gt;

&lt;p&gt;In this demo we built a fully automated, event-driven incident response pipeline entirely on native AWS services. The moment GuardDuty raises a malware finding, the pipeline springs into action — collecting live forensic evidence, snapshotting the EBS volume, uploading everything to S3, and locking down the instance — all without a single manual step.&lt;/p&gt;

&lt;p&gt;A few things worth carrying forward if you are moving this towards production:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Golden AMI&lt;/strong&gt; — bake AVML and the AWS CLI into your base image so every instance is always ready for forensic collection without any on-demand installation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scope the IAM policies&lt;/strong&gt; — the SSM Automation role uses &lt;code&gt;Resource: *&lt;/code&gt; for simplicity here; in production, restrict actions to specific instance IDs and snapshot ARNs where possible&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;S3 bucket hardening&lt;/strong&gt; — enable versioning, server-side encryption, and an S3 Object Lock policy on the forensics bucket to make evidence tamper-proof&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-account / multi-region&lt;/strong&gt; — if you run workloads across accounts, consider centralising the forensics bucket and deploying the EventBridge rule via AWS Organizations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full source for all files used in this demo is available on &lt;a href="https://github.com/Rajit11/guardduty-malware-isolation-demo" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The next time GuardDuty pages at 2 AM, your only job is to open the S3 bucket.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>automation</category>
      <category>security</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Enhance your Code Security with Amazon Inspector</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Sun, 27 Jul 2025 15:47:03 +0000</pubDate>
      <link>https://forem.com/aws-builders/enhance-your-code-security-with-amazon-inspector-45no</link>
      <guid>https://forem.com/aws-builders/enhance-your-code-security-with-amazon-inspector-45no</guid>
      <description>&lt;p&gt;As a latest addition to the vulnerability scanning capabilities of Amazon Inspector across multiple AWS services, it now supports scanning of your application source code, dependencies and Infrastructure as Code (IAC). It has a native integration with your SCMs - GitHub and GitLab and it helps you build a shift left security approach while taking proactive decisions securing your SDLC.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Let's Get Up and Running&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Currently Amazon Inspector Code Security scan is available in 10 AWS Regions, you can get the full list &lt;a href="https://docs.aws.amazon.com/inspector/latest/user/inspector_regions.html#ins-regional-feature-availability" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;Considering you are in one of the listed regions and have activated Inspector, select Code Security on the left pane.&lt;/p&gt;

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

&lt;p&gt;Once I click on ConnectTo, I get two options. As I am using GitHub as my SCM, I select it and proceed.&lt;/p&gt;

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

&lt;p&gt;You can choose the default scan configuration or customise it according to your usecase. I will create a custom scan configuration for now.&lt;/p&gt;

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

&lt;p&gt;In here you fix a scan frequency, I chose change based and periodic scanning which means whenever you create a pull or merge request or push new code a scan will be triggered. Alongside you can set weekly or monthly periodic scans, and in weekly scans you can choose the day you want the scan to run, this could be based off of your release cycles. &lt;/p&gt;

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

&lt;p&gt;Next, you choose the scope of the scan analysis, in my case I need all the three options enabled, so I will keep things as it is and create the scan configuration.&lt;/p&gt;

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

&lt;p&gt;Now I will provide a name to my configuration and connect to Github.&lt;/p&gt;

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

&lt;p&gt;I will use the link mentioned in the pop up screen to authorize to GitHub.&lt;/p&gt;

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

&lt;p&gt;Accept the authorization&lt;/p&gt;

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

&lt;p&gt;Once authorized, I got a message on the top of Inspector Console asking me to visit the GitHub connections page&lt;/p&gt;

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

&lt;p&gt;I will install a new GitHub App&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffzj44x7m0b4e8ayvdlwb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffzj44x7m0b4e8ayvdlwb.png" alt=" " width="632" height="974"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Installed the app with a selected repository from my personal account.&lt;/p&gt;

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

&lt;p&gt;We have a successful GitHub connection.&lt;/p&gt;

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

&lt;p&gt;I pushed a commit to Master to trigger a scan.&lt;/p&gt;

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

&lt;p&gt;Once the analysis is concluded (it might take some time), you can see the Scan status as Active against your Code Repositories.&lt;/p&gt;

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

&lt;p&gt;In the Findings section you can see all the vulnerabilities in your code and you can get assisted remediation and fix with other details when you select the particular vulnerability. Also you can filter out the vulnerabilites based on SCM provider, severity, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Testing Terraform IAC&lt;/strong&gt;
&lt;/h2&gt;

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

&lt;p&gt;Added one more repo with Terraform code to my GitHub application and it is listed in Code Security Console but pending inital scan, let's push a commit to the repository.&lt;/p&gt;

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

&lt;p&gt;Code Security scanned the newly added repo and flagged issues in the code and also suggested remediation with code fixes which is super useful.&lt;/p&gt;

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

&lt;p&gt;I created a seperate branch in my newly added repository and updated the Terraform code. Post which I created a PR to merge the changes with main, which triggered a CodeSecurity Scan on the GitHub console and once concluded it highlighted the code snippets that needed to be checked and stated the reason for flagging those with severity.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;On-Demand Scan&lt;/strong&gt;
&lt;/h2&gt;

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

&lt;p&gt;I added a third repository to my GitHub Application, and it is listed in my Code Security console. This time instead of pushing some code or creating a PR, I will generate an On-Demand Scan for the repository.&lt;/p&gt;

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

&lt;p&gt;I get a message saying that the On-Demand Scan generation is successful.&lt;/p&gt;

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

&lt;p&gt;Within sometime I see findings generated :)&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Lets Talk About Pricing&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;You are charged for each scan and each scan type 0.15 USD, against a single repository.&lt;/p&gt;

&lt;p&gt;So a scan of a single repository with all three scan types enabled would cost 1*0.15*3 = 0.45 USD&lt;/p&gt;

&lt;p&gt;If your repository does not contain IAC, you should create a new scanning configuration with IAC disabled to save costs.&lt;/p&gt;

&lt;p&gt;Also there is an option in your scanning configuration to disable scanning when code is changed or disable periodic scanning if you want to save further costs and just rely on On-Demand scans, but this will not let you utilize the full potential of this tool. &lt;/p&gt;

&lt;p&gt;More details related to pricing &lt;a href="https://aws.amazon.com/inspector/pricing/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Wrapping Up&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I feel this feature is a great addition to the current capabilities of Amazon Inspector by helping find code vulnerabilities and misconfigurations early in the development lifecycle and I hope this blog will help you get started with Code Security 🤘&lt;/p&gt;

</description>
      <category>aws</category>
      <category>security</category>
      <category>vulnerabilities</category>
      <category>devsecops</category>
    </item>
    <item>
      <title>Elevating Security with Amazon GuardDuty Runtime Monitoring</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Sat, 25 Jan 2025 07:12:46 +0000</pubDate>
      <link>https://forem.com/aws-builders/enhanced-runtime-monitoring-for-ecs-with-amazon-guardduty-4d16</link>
      <guid>https://forem.com/aws-builders/enhanced-runtime-monitoring-for-ecs-with-amazon-guardduty-4d16</guid>
      <description>&lt;p&gt;With the majority of our applications now being cloud-native and containerized, ensuring security has become paramount. While static security measures, such as &lt;a href="https://community.aws/content/2pk8NbSgCTL3lL8nR60LaqHdbq5" rel="noopener noreferrer"&gt;image scanning with Amazon Inspector&lt;/a&gt;, play a crucial role, monitoring container security during runtime is equally important. This is where ECS Runtime Monitoring with &lt;a href="https://aws.amazon.com/guardduty/" rel="noopener noreferrer"&gt;Amazon GuardDuty&lt;/a&gt; comes into play. GuardDuty Runtime Monitoring, now over a year in general availability, has proven its effectiveness in detecting runtime security threats across EC2 instances, ECS Clusters, and EKS Clusters. In this blog, we'll walk through enabling runtime monitoring for your ECS Cluster, generating GuardDuty findings, and setting up alerts for both runtime monitoring health and GuardDuty Findings to enhance your security posture. &lt;/p&gt;

&lt;h2&gt;
  
  
  Amazon GuardDuty: Advanced Threat Detection for AWS Security
&lt;/h2&gt;

&lt;p&gt;Amazon GuardDuty is a fully managed threat detection service that continuously monitors your AWS environment for suspicious activity. By analyzing vast amounts of data from sources like AWS Cloudtrail, VPC Flow Logs, and DNS logs, GuardDuty detects threats such as unauthorized access, data exfiltration, or compromised instances engaging in malicious activity.&lt;/p&gt;

&lt;p&gt;Leveraging AI, machine learning, and threat intelligence , GuardDuty identifies anomalies such as unusual login attempts, unexpected changes to resources, or attempts to disable security controls helping you respond before threats escalate. It provides automated analysis and actionable insights without the need for complex security infrastructure, making it an efficient and scalable solution for cloud security.&lt;/p&gt;

&lt;p&gt;GuardDuty offers specialized protection across AWS Services including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;S3 Protection - Detects unauthorized access and data theft from S3 Buckets.&lt;/li&gt;
&lt;li&gt;EKS Protection - Monitor Kubernetes workloads for suspicious activity.&lt;/li&gt;
&lt;li&gt;Runtime Monitoring - Identifies real time threats in compute environments.&lt;/li&gt;
&lt;li&gt;Malware Protection - Scans Amazon EC2 and S3 for malware threats.&lt;/li&gt;
&lt;li&gt;RDS Protection - Guards against database related security risks.&lt;/li&gt;
&lt;li&gt;Lambda Protection - Monitors serverless workloads for anomalies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By automating threat detection and reducing manual security efforts, GuardDuty helps businesses safeguard their AWS infrastructure with minimal operational overhead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enabling the fully managed GuardDuty Agent
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fku1aie6zl7964wdllkea.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fku1aie6zl7964wdllkea.png" alt="Enabling the GuardDuty Agent" width="800" height="421"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;When we deploy the GuardDuty security agent, GuardDuty will create a VPC Endpoint for the security agent to deliver runtime security events to GuardDuty. Alongside it will also create a new security group that will control the traffic that's allowed to reach the resources using inbound rules of the security group and will adapt to vpc cidr range changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  ECS Cluster
&lt;/h2&gt;

&lt;p&gt;I started with an existing ECS Cluster with a single task running on AWS Fargate.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxvi5kdbl9g3q06bz9bwl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxvi5kdbl9g3q06bz9bwl.png" alt="ECS Fargate Cluster" width="800" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Within the task configuration, you'll notice two containers running:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Main Application Container&lt;/li&gt;
&lt;li&gt;Sidecar Container launched by AWS to run the Amazon GuardDuty agent&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr1a26u422baj2v0prh3s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr1a26u422baj2v0prh3s.png" alt="ECS Task Configuration" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GuardDuty actively monitoring the ECS Cluster&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fscb24uw9ht39wpla1h1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fscb24uw9ht39wpla1h1b.png" alt="GuardDuty Runtime Monitoring" width="800" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  GuardDuty Runtime Monitoring Alerts
&lt;/h2&gt;

&lt;p&gt;It is essential to configure alerts for when GuardDuty Runtime Monitoring enters an unhealthy state or when a Runtime Monitoring Finding is detected.&lt;/p&gt;

&lt;p&gt;To achieve this, I have configured EventBridge rules with Amazon SNS as the target to trigger email notifications for both.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GuardDuty Runtime Monitoring Unhealthy State Alert&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I manually scaled down the ECS service from 1 to 0, so that the GuardDuty agent is no longer able to communicate with Amazon GuardDuty and the Runtime Monitoring status is pushed to an unhealthy state, upon which the Eventbridge Rule is triggered and a SNS notification is generated.&lt;/p&gt;

&lt;p&gt;Event Pattern for Eventbridge Rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "source": ["aws.guardduty"],
  "detail-type": ["GuardDuty Runtime Protection Unhealthy"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fybuc181938hfg9xuu83e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fybuc181938hfg9xuu83e.png" alt="Unhealthy GuardDuty Runtime Monitoring" width="800" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe7mxm2mijffwv6mjxw14.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe7mxm2mijffwv6mjxw14.png" alt="Unhealthy Runtime Monitoring Notification" width="800" height="132"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GuardDuty Runtime Monitoring Findings Alert&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I &lt;a href="https://docs.aws.amazon.com/guardduty/latest/ug/sample_findings.html" rel="noopener noreferrer"&gt;generated sample findings in GuardDuty&lt;/a&gt; to test and validate the alerting mechanism.&lt;/p&gt;

&lt;p&gt;Event Pattern for Eventbridge Rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "source": ["aws.guardduty"],
  "detail": {
    "type": ["Backdoor:Runtime/C&amp;amp;CActivity.B", "PrivilegeEscalation:Runtime/DockerSocketAccessed"]
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find the full list of GuardDuty Runtime Monitoring Finding Types &lt;a href="https://docs.aws.amazon.com/guardduty/latest/ug/findings-runtime-monitoring.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Findings Generated&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7z6i21hoezffn6sxta4l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7z6i21hoezffn6sxta4l.png" alt="Sample Findings" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgl303nxi0f2gjm6v0pq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgl303nxi0f2gjm6v0pq.png" alt="Alerts on Runtime Findings" width="800" height="162"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using an Encrypted SNS Topic
&lt;/h2&gt;

&lt;p&gt;If you would like to encrypt your SNS Messages before saving them in it's data centers in order to comply with a certain compliance, there are a few things you need to ensure so that your GuardDuty alerts don't fail to deliver.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Firstly, you need to use a CMK(Customer Managed Key) instead of a default SNS Encryption key to encrypt your SNS Topic.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7a6wh2c3nvc975h2nkb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7a6wh2c3nvc975h2nkb.png" alt="Image description" width="800" height="291"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Secondly the Eventbridge rule should have the necessary permission to invoke your KMS key to decrypt the data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While you are creating the Eventbridge rule note down the IAM role that is being created by default and you can later add the necessary permissions to it.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Effect": "Allow",
    "Action": [
      "kms:GenerateDataKey",
      "kms:Decrypt"
    ],
    "Resource": [
      "arn:aws:kms:ap-south-1:123456734:key/53c1b423-3a5e-1234-1111-eda13df344de"               ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace your kms key arn!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Third, you need to add the necessary &lt;a href="https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-encryption-key-policy.html" rel="noopener noreferrer"&gt;permission&lt;/a&gt; in your KMS policy to authorize Eventbridge.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you see the messages not getting delivered, it means you failed to satisfy any of the above three pointers and for further troubleshooting you can also refer [this].(&lt;a href="https://repost.aws/knowledge-center/sns-not-getting-eventbridge-notification" rel="noopener noreferrer"&gt;https://repost.aws/knowledge-center/sns-not-getting-eventbridge-notification&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope this blog serves as a great starting point for exploring this exciting feature. Below, I've compiled a few additional resources that will help you dive deeper and make the most of it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://aws.amazon.com/blogs/security/using-amazon-guardduty-ecs-runtime-monitoring-with-fargate-and-amazon-ec2/" rel="noopener noreferrer"&gt;Using Amazon GuardDuty ECS runtime monitoring with Fargate and Amazon EC2&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_settingup.html#setup-sns" rel="noopener noreferrer"&gt;GuardDuty Alerting using Eventbridge&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/guardduty/latest/ug/runtime-monitoring.html" rel="noopener noreferrer"&gt;GuardDuty Runtime Monitoring&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/guardduty/latest/ug/what-is-guardduty.html" rel="noopener noreferrer"&gt;GuardDuty Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devsecops</category>
      <category>aws</category>
      <category>security</category>
      <category>containers</category>
    </item>
    <item>
      <title>Optimize Cost Savings using AWS EC2 Spot Instances as your EKS Worker Nodes</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Sun, 20 Aug 2023 09:29:26 +0000</pubDate>
      <link>https://forem.com/aws-builders/optimize-cost-savings-using-aws-ec2-spot-instances-as-your-eks-worker-nodes-2b6f</link>
      <guid>https://forem.com/aws-builders/optimize-cost-savings-using-aws-ec2-spot-instances-as-your-eks-worker-nodes-2b6f</guid>
      <description>&lt;p&gt;To optimize cost-savings while deploying dev/test workloads on EKS you can utilize Amazon EC2 Spot Instances and run them as your EKS Nodes.&lt;/p&gt;

&lt;p&gt;Amazon EC2 Spot Instances let you take advantage of unused EC2 capacity in the AWS cloud. Spot Instances are available at up to a 90% discount compared to On-Demand prices. [Source: &lt;a href="https://aws.amazon.com/ec2/spot/" rel="noopener noreferrer"&gt;AWSDocs&lt;/a&gt;]&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-Requisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;An AWS Account&lt;/li&gt;
&lt;li&gt;An IAM user with administrator access and a EC2 Role with administrator access&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We are going to deploy an EKS Cluster using eksctl from an EC2 Instance which is going to be our launchpad, you can do the same from your local machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Launch an EC2 Instance and install necessary packages
&lt;/h2&gt;

&lt;p&gt;We shall be launching an EC2 using the Amazon Linux 2023 AMI, with t3a.small instance type and keeping the rest of the settings default, if you wish you can change them based on your requirements. I've kept the SSH Access allowed for anywhere for the sake of this demo, highly recommend you to opt granular access for the same using MyIP.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Installing eksctl&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For Unix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# for ARM systems, set ARCH to: `arm64`, `armv6` or `armv7`
ARCH=amd64
PLATFORM=$(uname -s)_$ARCH

curl -sLO "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_$PLATFORM.tar.gz"

# (Optional) Verify checksum
curl -sL "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_checksums.txt" | grep $PLATFORM | sha256sum --check

tar -xzf eksctl_$PLATFORM.tar.gz -C /tmp &amp;amp;&amp;amp; rm eksctl_$PLATFORM.tar.gz

sudo mv /tmp/eksctl /usr/local/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Source: &lt;a href="https://eksctl.io/introduction/#installation" rel="noopener noreferrer"&gt;eksctl docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing kubectl&lt;/strong&gt;&lt;br&gt;
As we shall be launching the latest version of EKS (1.27) for amd64 based architecture, we will run the below commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.27.1/2023-04-19/bin/linux/amd64/kubectl
chmod +x ./kubectl
mkdir -p $HOME/bin &amp;amp;&amp;amp; cp ./kubectl $HOME/bin/kubectl &amp;amp;&amp;amp; export PATH=$HOME/bin:$PATH
echo 'export PATH=$HOME/bin:$PATH' &amp;gt;&amp;gt; ~/.bashrc
kubectl version --short --client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Source: &lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html" rel="noopener noreferrer"&gt;AWS Docs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Launching an EKS Cluster with spot instances using eksctl
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;ClusterConfig:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
    name: my-eks-cluster
    region: ap-south-1
    version: "1.27"

vpc:
  subnets:
    private:
      private-ap-south-1a: 
        id: "xxxxxxx"
      private-ap-south-1b: 
        id: "xxxxxxx"
      private-ap-south-1c: 
        id: "xxxxxxx"

managedNodeGroups:
    - name: spot-nodegroup
      ami: ami-016931097ac39b652
      amiFamily: AmazonLinux2
      overrideBootstrapCommand: |
        #!/bin/bash
        /etc/eks/bootstrap.sh my-eks-cluster --container-runtime containerd
      privateNetworking: true
      minSize: 1
      maxSize: 3
      desiredCapacity: 1
      instanceTypes: ["t3.medium","t3.small","t3a.small","t3a.medium"]
      spot: true
      subnets:
      - private-ap-south-1a
      - private-ap-south-1b
      - private-ap-south-1c
      labels: {node: spot}
      ssh:
        publicKeyName: yourkeypairname
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally we have to create an Admin Role for our EKS LaunchPad Server and attach it&lt;/p&gt;

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

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

&lt;p&gt;To create the cluster, run &lt;code&gt;eksctl create cluster -f cluster.yaml&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;When we create the cluster using eksctl, AWS launches two CloudFormation Stacks in the backend, one to create the control plane with additional infrastructure and the other to create the nodegroups.&lt;/p&gt;

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

&lt;p&gt;It shall take from 20-25 mins to launch the cluster.&lt;/p&gt;

&lt;h2&gt;
  
  
  EKS Cluster Successfully Launched with Spot Instance NodeGroup
&lt;/h2&gt;

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

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

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

&lt;h2&gt;
  
  
  Clean-Up
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Delete the cluster&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;eksctl delete cluster -f cluster.yaml&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Terminate the EC2 Instance&lt;/strong&gt;&lt;/p&gt;

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

</description>
      <category>aws</category>
      <category>devops</category>
      <category>containers</category>
    </item>
    <item>
      <title>Access AWS Secrets Manager from your container using AWS SDK</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Sat, 19 Aug 2023 12:03:33 +0000</pubDate>
      <link>https://forem.com/aws-builders/access-aws-secrets-manager-from-your-container-using-aws-sdk-1018</link>
      <guid>https://forem.com/aws-builders/access-aws-secrets-manager-from-your-container-using-aws-sdk-1018</guid>
      <description>&lt;p&gt;In case you need to store your credentials securely at a place and not in your application code, AWS Secrets Manager can become your ideal choice. &lt;/p&gt;

&lt;p&gt;AWS Secrets Manager helps you manage, retrieve, and rotate database credentials, application credentials, OAuth tokens, API keys, and other secrets throughout their lifecycles. &lt;br&gt;
[Source: &lt;a href="https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html" rel="noopener noreferrer"&gt;AWS Docs&lt;/a&gt;] &lt;/p&gt;

&lt;p&gt;Today, we are going to look into how to fetch a secret from AWS Secrets Manager inside your container using AWS SDK, we shall be using the Python SDK (boto3). I shall be going ahead with a dummy secret for this demo but you can use the same process to fetch DB Passwords, Application Credentials or other critical tokens that you should not hardcode onto your application source code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-Requisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;An AWS Account&lt;/li&gt;
&lt;li&gt;An user with full access to AWS Secrets Manager and EC2&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating a secret in the Secret Manager
&lt;/h2&gt;

&lt;p&gt;We shall be going ahead with other type of secrets but in your case you can go ahead and store secrets if you are using AWS Native Databases services as well.&lt;br&gt;
We have chosen aws/secretsmanager as the Encryption Key, you can have a Customer Managed KMS Key to encrypt yoru secret based on your requirement.&lt;/p&gt;

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

&lt;p&gt;In the next window, you shall be asked to provide a secret name in our case we have provided &lt;strong&gt;test/mysecret&lt;/strong&gt;, you can leave the rest of the options as default.&lt;/p&gt;

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

&lt;p&gt;Click on next, and if you wish to enable automatic rotation you can do so in this window, this would also require a lambda function that will rotate the secret.&lt;/p&gt;

&lt;p&gt;Click next and in the Review section you shall be getting a code snippet for multiple languages, according to your needs you can choose one, in this case I shall be going ahead with Python3 and we shall use that later.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Launching an EC2 Instance and installing Docker
&lt;/h2&gt;

&lt;p&gt;Create an instance providing the name and selecting the instance type.&lt;/p&gt;

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

&lt;p&gt;Choose an instance type and your keypair, if you don't have a keypair you can create one using the create keypair option.&lt;/p&gt;

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

&lt;p&gt;You can keep the network settings as default, for this demo I'm keeping the SSH Access open from anywhere, it's recommended to keep restricted access from the same.&lt;/p&gt;

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

&lt;p&gt;Once the instance is launched you can ssh into the instance and install docker&lt;/p&gt;

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

&lt;p&gt;Start the docker service&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Creating an IAM Role for EC2 to access Secrets Manager
&lt;/h2&gt;

&lt;p&gt;Select EC2 as the trusted entity type&lt;/p&gt;

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

&lt;p&gt;Choosing the SecretsManager R/W Permission, in your case you can choose a granular permission&lt;/p&gt;

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

&lt;p&gt;Provide a role name and create the role&lt;/p&gt;

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

&lt;p&gt;Attach the role to your EC2 Instance&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  Launch an Ubuntu Container and Access Secrets Manager
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;sudo docker run -it ubuntu /bin/bash&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;Install Python3 and boto3 in the container&lt;/p&gt;

&lt;p&gt;&lt;code&gt;apt update &amp;amp;&amp;amp; apt install python3 -y&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdb4a8gqpvxzfyn869or8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdb4a8gqpvxzfyn869or8.png" alt="Image description" width="800" height="144"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;apt install python3-pip -y&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fst2hvpomdmoqidm9eo6m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fst2hvpomdmoqidm9eo6m.png" alt="Image description" width="746" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip3 install boto3&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy27en2pq4jablx461ij1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy27en2pq4jablx461ij1.png" alt="Image description" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We shall also install vim in the container using - &lt;code&gt;apt install vim -y&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Access Secrets Manager inside the container using a Python Script
&lt;/h2&gt;

&lt;p&gt;We shall use the code snippet we got while creating the secret and add a command to print the secret, and subsequently a call statement to call the get_secret method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://raw.githubusercontent.com/RajitPaul11/AWS-Security/main/access-secrets-manager-using-boto3.py" rel="noopener noreferrer"&gt;https://raw.githubusercontent.com/RajitPaul11/AWS-Security/main/access-secrets-manager-using-boto3.py&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;

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

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

&lt;h2&gt;
  
  
  CleanUp
&lt;/h2&gt;

&lt;p&gt;Terminate the EC2 Instance and schedule deletion for the secret, the minimum duration is 7 days.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>containers</category>
      <category>cloud</category>
      <category>devops</category>
    </item>
    <item>
      <title>Monitor and Visualize Nginx Ingress Controller Metrics on Amazon EKS with Prometheus &amp; Grafana</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Thu, 25 May 2023 12:17:59 +0000</pubDate>
      <link>https://forem.com/aws-builders/monitor-and-visualize-nginx-ingress-controller-metrics-on-amazon-eks-with-prometheus-grafana-5gn7</link>
      <guid>https://forem.com/aws-builders/monitor-and-visualize-nginx-ingress-controller-metrics-on-amazon-eks-with-prometheus-grafana-5gn7</guid>
      <description>&lt;p&gt;In today’s digital landscape, it is very necessary to figure out trends in our data and act accordingly to ensure high availability of our application. Monitoring helps us to stay on top of the game and get insights on our product environment. An Ingress Controller acts as a bridge between Kubernetes Service and the external world and can be considered as a specialized load balancer for Kubernetes. &lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-Requisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;A Kubernetes Cluster (&lt;a href="https://dev.to/aws-builders/creating-an-amazon-eks-cluster-from-scratch-using-eksctl-540i"&gt;Create an EKS Cluster from scratch&lt;/a&gt;) &lt;/li&gt;
&lt;li&gt;Helm V3 (&lt;a href="https://helm.sh/docs/intro/install/" rel="noopener noreferrer"&gt;Helm Install Docs&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Install Kube-Prometheus-Stack using Helm
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helm repo add prometheus-community https://prometheus-community.github.io/helm-charts 
helm repo update 
helm install --create-namespace --namespace monitoring \
my-k8s-prom-stack prometheus-community/kube-prometheus-stack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have the stack installed you should have Prometheus, Grafana and AlertManager installed onto your cluster. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flki9rlbmwl7qfkrt0fc7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flki9rlbmwl7qfkrt0fc7.png" alt="Kube Prometheus Stack" width="800" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Nginx Ingress Controller
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx 
helm repo update 
helm install ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx --create-namespace \
--set controller.metrics.enabled=true \
--set controller.metrics.serviceMonitor.enabled=true \
--set controller.metrics.serviceMonitor.additionalLabels.release="my-k8s-prom-stack" \
--version=4.5.2 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Along with installing the ingress controller we are setting the controller metrics as true which will populate an additional metrics service and creating a service monitor for that service which will feed data onto Prometheus, the additional Label would be as per the selector you have set on the Prometheus Operator, follow the later part for more details on this.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can check the Service Monitor selector on your Prometheus Operator using:  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl get prometheus --namespace monitoring prometheus-svc-name –oyaml&lt;/code&gt; (lookout for the section below on the manifest) &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo67owwmj0k8lbwclyt5o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo67owwmj0k8lbwclyt5o.png" alt="Service Monitor Selector on Prom Operator" width="529" height="90"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once Nginx controller is installed you can verify the services that are spawned using: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl get svc --namespace ingress-nginx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F22cupf64pg4ejovr01qn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F22cupf64pg4ejovr01qn.png" alt="Ingress Controller Services" width="800" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn56aepy2ev5amzvlc84w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn56aepy2ev5amzvlc84w.png" alt="Service Monitor" width="800" height="101"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Monitor and Visualize Nginx Controller Metrics
&lt;/h2&gt;

&lt;p&gt;To access the Prometheus and Grafana you can set ingress objects &lt;br&gt;
Sample Ingress Manifest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:    
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: 5m  
  name: prometheus-ingress
  namespace: monitoring
spec:
  rules:
  - host: prom.mydomain.com
    http:
      paths:
      - backend:
          service:
            name: my-k8s-prom-stack-kube-pro-prometheus
            port:
              number: 9090
        path: /
        pathType: ImplementationSpecific
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generate some load on the Ingress Controller by hitting the Ingress Endpoints.&lt;/p&gt;

&lt;p&gt;Access Prometheus and Grafana to query and visualize the controller metrics:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fko8zkdgdagjyy9sw5kfl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fko8zkdgdagjyy9sw5kfl.png" alt="Prometheus Console" width="800" height="310"&gt;&lt;/a&gt;&lt;br&gt;
Prom Query to check the number of 200 requests on ingress:&lt;br&gt;
&lt;code&gt;nginx_ingress_controller_requests{status=~'2..'}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjbpn2loge7l5iakt3ifg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjbpn2loge7l5iakt3ifg.png" alt="Prom Console" width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Import Nginx Controller Dashboard on Grafana and visualize the metrics (Dashboard ID: 9614) &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faj4pif05kg1msiqtebab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faj4pif05kg1msiqtebab.png" alt="Grafana Dashboard" width="800" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading this, you can follow me for more such content, or reach out to me on &lt;a href="https://in.linkedin.com/in/rajitpaul" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>monitoring</category>
      <category>devops</category>
      <category>eks</category>
      <category>kubernetes</category>
    </item>
    <item>
      <title>Deploy your application on Kubernetes (Amazon EKS) using AWS Serverless (Codebuild)</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Thu, 21 Jul 2022 14:52:32 +0000</pubDate>
      <link>https://forem.com/aws-builders/deploy-your-application-on-kubernetes-amazon-eks-using-aws-serverless-codebuild-594i</link>
      <guid>https://forem.com/aws-builders/deploy-your-application-on-kubernetes-amazon-eks-using-aws-serverless-codebuild-594i</guid>
      <description>&lt;p&gt;Hi folks, &lt;br&gt;
Recently I came across an use-case of deploying a microservice on EKS using CodeBuild with GitHub as source. Although I've used Jenkins numerous times to do the same thing but I haven't used AWS Serverless to deploy on EKS. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This blog is for you if you want to deploy your microservice to Kubernetes, or want to learn how to setup AWS CodePipeline with CodeBuild, or like to integrate CodeBuild with EKS or you are generally curious about Kubernetes and Serverless :)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  This is how I started the journey:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I enquired about the source code and got to know it was on GitHub. For this blogpost I am going to create my own GitHub Repo with a basic deployment manifest. You can create your own repo and have the full stack of manifests starting from Ingress, to the service, deployment etc required for your microservice.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, I setup a CodePipeline. I'll show you how to do that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to Developer Tools in the console, and select Code Pipeline.
Provide your pipeline a name, select the default service role so CodePipeline can create a role on your behalf, let the advanced setting be as it is unless you have a custom location for your artifact and want to use a custom KMS Key.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fat6l4zolgri82uz6bnyw.png" alt="Image description" width="800" height="418"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Moving on you need to specify where is your SourceCode that you want to build or deploy.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add a Source Provider: In our case that would be GitHub (Version2).
Connection: Select if you have an existing connection with your GitHub Account or Create a connection for GitHub, it's fairly simple.
Once you authenticate CodePipeline to connect to your GitHub Account you shall receive a CodeStar connection URL, use that.
Once you fill in all the details it should look something like this.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fskg7zfrlsfxocqlodx63.png" alt="Image description" width="488" height="607"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/RajitPaul11/my_dummy_microservice_deploy_on_eks.git" rel="noopener noreferrer"&gt;My GitHub Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we shall add a build stage.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;As a build provider we will select AWS CodeBuild. Feel free to choose the region of your choice. If you have an existing project you can select the same or else create a new project. I am going to setup a project from scratch.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To setup a CodeBuild Project you need to provide the Project Name &amp;amp; Description, you can also restrict concurrent builds and provide additional tags if you want.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxial4mclsjhmwj58tzgr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxial4mclsjhmwj58tzgr.png" alt="Image description" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Design the CodeBuild Environment, we shall go with the latest image of Amazon Linux 2 and ask CodeBuild to create a new service role on our behalf.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq2u6xv7wr6ytvvxid706.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq2u6xv7wr6ytvvxid706.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Additional Environment Configuration&lt;br&gt;
Select your VPC, choose a private subnet and a SG with outbound allow and then validate your VPC setting. This is where your codebuild server will be provisioned ~ No, Serverless does not mean there are no servers, it's just that, you don't have to manage them ;)&lt;br&gt;
Provide appropriate compute resource to the server as per your code requirements and we are good to go. If you require you can add environment variables and filesystems for your server.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0w25wz2j3xtfk06th8j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0w25wz2j3xtfk06th8j.png" alt="Image description" width="728" height="779"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can leave the buildspec section empty if your buildspec file is buildspec.yml as codebuild will look for that file in your repo, if you have named your file otherwise you can mention that in the buildspec name section. Also if you have some additional requirements while building your code you can mention those in the additional build commands.&lt;br&gt;
Will ignore Batch configuration as we do not require that for this blogpost.&lt;br&gt;
It's best practise to export your build logs to Cloudwatch so that it's easier for you to troubleshoot. Additionally you can also export your CodeBuild logs to S3 for later analysis.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvsizizg3z7y58qaotgbz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvsizizg3z7y58qaotgbz.png" alt="Image description" width="704" height="730"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you click on continue to CodePipeline, the CodeBuild Project will be created and you can complete your CodePipeline setup.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In environment variables you can refer to environment values generated from CodePipeline or can add new env variables. On Build Type, we shall be executing a single build on execution.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Skip Deploy stage as codebuild will be taking care of the deployment and create your CodePipeline :)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EKS Cluster: I shall consider you have a running EKS cluster where we shall be doing the deployment, if not, you can deploy a new EKS cluster. In case you need help, refer this previous blog of mine - &lt;a href="https://dev.to/aws-builders/creating-an-amazon-eks-cluster-from-scratch-using-eksctl-540i"&gt;Setup your EKS Cluster from scratch&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To allow CodeBuild to deploy on the EKS cluster we need to modify EKS RBAC by adding the CodeBuild Service Role with the required permission on the aws-auth configmap that is used to manage EKS RBAC.&lt;br&gt;
&lt;a href="https://dev.to/rajitpaul_savesoil/read-only-access-to-specific-resources-in-aws-eks-cluster-via-eks-authentication-authorization-2i13"&gt;To know more about EKS RBAC&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Locate your CodeBuild Service Role:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Open your buildproject, that you shall be using.
In Build details tab, scroll down to Environment where you can see the Service Role hyperlink. 
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4f05qhyby9ouz5vs7ly.png" alt="Image description" width="800" height="126"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Update the aws-auth configmap:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;To edit the configmap run - &lt;b&gt;kubectl edit cm aws-auth -n kube-system&lt;/b&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Under mapRoles we shall add a new entry:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- groups:
    - system:masters
  rolearn: arn:aws:iam::xxxaccidxxx:role/codebuild- microservice-deploy-to-eks-service-role 
  username: CodeBuild Role to Access EKS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; If you directly copy paste the CodeBuild Role ARN from the console to the configmap you will get a "error: You must be logged in to the server (Unauthorized)", make sure your remove the /servicerole path from the ARN.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Additionally to the CodeBuild Service Role attach a policy with eks:DescribeCluster action allowed. This will allow codebuild to download the kubeconfig file onto it's server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Deploy Your Application, Run the Pipeline:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Once you have done all as I mentioned, you would have your application running on EKS with the help of CodeBuild :)&lt;/li&gt;
&lt;/ul&gt;

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

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

&lt;h2&gt;
  
  
  Clean UP
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Delete your CodeBuild Project&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flfikg5ai5hlz0wag44vj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flfikg5ai5hlz0wag44vj.png" alt="Image description" width="800" height="150"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Delete your Pipeline&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8x2mor3uspnv07gqmte4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8x2mor3uspnv07gqmte4.png" alt="Image description" width="800" height="146"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to know more about Kubernetes, DevOps, Serverless follow me, also I would love to have a chat with you on &lt;a href="https://www.linkedin.com/in/rajitpaul/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; :)&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>kubernetes</category>
      <category>serverless</category>
    </item>
    <item>
      <title>ECS Networking - (awsvpc, bridge, host, none)</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Mon, 09 May 2022 14:47:06 +0000</pubDate>
      <link>https://forem.com/aws-builders/ecs-networking-awsvpc-bridge-host-none-4bg9</link>
      <guid>https://forem.com/aws-builders/ecs-networking-awsvpc-bridge-host-none-4bg9</guid>
      <description>&lt;p&gt;Hi folks, &lt;strong&gt;Elastic Container Service&lt;/strong&gt; is one of the container offerings from AWS. ECS helps us to run any number of docker containers across a managed cluster of EC2 instances. It helps to isolate our workloads and helps achieve faster time to market with efficient scaling in place. It is secure and you can easily migrate your on prem container workload to ECS and back.&lt;/p&gt;

&lt;p&gt;Let's deep dive and look into the different network types on ECS and see how they are different from one another.&lt;/p&gt;

&lt;h2&gt;
  
  
  We have Four Network modes in ECS:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;awsvpc&lt;/strong&gt;: It allocates a seperate Elastic Network Interface (ENI) to the task and also allocates a primary IPV4 address to it. The task networking behaves same as an EC2 instance networking. &lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In this you can see a warning which says the containers in the task will share an ENI and port mappings can only specify container ports.&lt;/p&gt;

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

&lt;p&gt;We cannot set host port mappings as the network mode is &lt;strong&gt;awsvpc&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Once you create the service we can check in the task, an ENI is assigned to the task and all the containers inside it.&lt;/p&gt;

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

&lt;p&gt;If we SSH into the instance and curl the private IP associated to the task ENI, we can access the website running on the container.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4fn1xqn5f1cjvp2bw9fb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4fn1xqn5f1cjvp2bw9fb.png" alt="Image description" width="800" height="217"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this network mode we cannot access the website using the Task Host (EC2) Public or Private IP.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;bridge&lt;/strong&gt;: In Bridge Network mode, the task makes use of the built-in Docker VNet (Virtual Network) which also allows the task to communicate with other tasks.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Once we select the bridged network mode for the task we can see an associated host port mapping available with the container port.&lt;/p&gt;

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

&lt;p&gt;If we check task networking the container does not have any additional network as it uses only the Docker Virtual Network.&lt;/p&gt;

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

&lt;p&gt;We shall access the website running on the container using the DockerHost IP (Amazon EC2).&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;host&lt;/strong&gt;: Host network mode facilitates the task to bypass the Docker built-in VNet (Virtual Network) and maps the container port directly to the task host (Amazon EC2) ENI. As a result, we cannot run multiple instances of the same task when Port Mappings are used and the network mode is host.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;The container shall be using in this case the instance network stack.&lt;/p&gt;

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

&lt;p&gt;We can access the website running on the container using the Docker Host Public IP (EC2 Instance Public IP).&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;none&lt;/strong&gt;: Blackhole, the task does not have any external network connectivity. &lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;You shall see a message stating that the container will not have any external connectivity in the network section of the task.&lt;/p&gt;

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

&lt;p&gt;I hope this has helped you get an idea of ECS networking. Follow me for more blogs on AWS &amp;amp; DevOps. &lt;br&gt;
Feel free to connect with me on &lt;a href="https://www.linkedin.com/in/rajitpaul/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>ecs</category>
      <category>containers</category>
      <category>devops</category>
    </item>
    <item>
      <title>Dockerize an API based Flask app and deploy on Amazon ECS</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Sun, 17 Apr 2022 19:46:52 +0000</pubDate>
      <link>https://forem.com/aws-builders/dockerize-an-api-based-flask-app-and-deploy-on-amazon-ecs-2pk0</link>
      <guid>https://forem.com/aws-builders/dockerize-an-api-based-flask-app-and-deploy-on-amazon-ecs-2pk0</guid>
      <description>&lt;p&gt;Hi Folks!&lt;br&gt;
This is the first blog of the series Dockerize Your Application.&lt;/p&gt;

&lt;p&gt;In the age of microservices we want our application code and requirements to be packed in an image and use that in a suitable container orchestration tool for better scalability and availability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-Requisites:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;An EC2 Server with git and docker installed&lt;/li&gt;
&lt;li&gt;Amazon ECR Repository &lt;/li&gt;
&lt;li&gt;AWS CLI configured on your server with sufficient permissions (to push image to ecr) or you can attach a role to your server with sufficient permissions.&lt;/li&gt;
&lt;li&gt;Region: Mumbai(ap-south-1)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  About the API
&lt;/h2&gt;

&lt;p&gt;It's a todo app with two API's one to get the list of to-do tasks and another to post your tasks.&lt;br&gt;
GET-POST api path - /todo/api/v1.0/tasks&lt;/p&gt;

&lt;h2&gt;
  
  
  Source: [Flask_API_App]
&lt;/h2&gt;

&lt;p&gt;(&lt;a href="https://github.com/RajitPaul11/AWS_workshop_2022_data/tree/collate/python_flask_code_in_aws_linux_restful_GET_POST" rel="noopener noreferrer"&gt;https://github.com/RajitPaul11/AWS_workshop_2022_data/tree/collate/python_flask_code_in_aws_linux_restful_GET_POST&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Dockerfile
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM alpine:latest

RUN apk add py3-pip
RUN pip3 install flask

WORKDIR /home

COPY app.py .

EXPOSE 80

ENTRYPOINT ["/usr/bin/flask","run"]

CMD ["--host=0.0.0.0", "--port=80"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Login to your EC2 Server and clone the repo
&lt;/h4&gt;

&lt;p&gt;git clone -b collate &lt;a href="https://github.com/RajitPaul11/AWS_workshop_2022_data.git" rel="noopener noreferrer"&gt;https://github.com/RajitPaul11/AWS_workshop_2022_data.git&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Change directory and build docker image
&lt;/h4&gt;

&lt;p&gt;cd AWS_workshop_2022_data/python_flask_code_in_aws_linux_restful_GET_POST&lt;br&gt;
docker build -t flask_api_app:v1 .&lt;/p&gt;

&lt;h4&gt;
  
  
  Tag your docker image
&lt;/h4&gt;

&lt;p&gt;docker tag flask_api_app:v1 youraccountID.dkr.ecr.ap-south-1.amazonaws.com/flask_api_app:v1&lt;/p&gt;

&lt;h4&gt;
  
  
  Login to your ECR Repo
&lt;/h4&gt;

&lt;p&gt;aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin youraccountID.dkr.ecr.ap-south-1.amazonaws.com&lt;/p&gt;

&lt;h4&gt;
  
  
  Push the docker image
&lt;/h4&gt;

&lt;p&gt;docker push youraccountID.dkr.ecr.ap-south-1.amazonaws.com/flask_api_app:v1&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy to ECS
&lt;/h2&gt;

&lt;p&gt;Select Services and then select ECS&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0n253ojchn5r8o1rkax7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0n253ojchn5r8o1rkax7.png" alt="Image description" width="800" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Create an ECS Cluster
&lt;/h4&gt;

&lt;p&gt;We shall be creating an ECS Cluster with EC2&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6esm057mii97vnrfk3d5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6esm057mii97vnrfk3d5.png" alt="Image description" width="800" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Cluster Config
&lt;/h4&gt;

&lt;p&gt;Choose a suitable name for your cluster, and select a provisioning model, in this case we shall go for Spot.&lt;br&gt;
Choose diversified spot instance allocation strategy so the instances are spread across az's.&lt;br&gt;
Select two instance types on a or basis.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fop9cquaf6rhkmwskqvij.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fop9cquaf6rhkmwskqvij.png" alt="Image description" width="800" height="752"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Specify the Storage spec and select an existing key pair, so that you can ssh later to the EC2 instance and do some modification or troubleshoot from the terminal.&lt;br&gt;
Create a new VPC or you can select an existing VPC.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2oab7a93mhfcku7i1wi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2oab7a93mhfcku7i1wi.png" alt="Image description" width="800" height="743"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cluster created!&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmrhg8hu8q4bu0u1rc4wl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmrhg8hu8q4bu0u1rc4wl.png" alt="Image description" width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a Task Definition
&lt;/h2&gt;

&lt;p&gt;Select the launch type as EC2&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi8mv0rck1s5j13ox1vzm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi8mv0rck1s5j13ox1vzm.png" alt="Image description" width="800" height="467"&gt;&lt;/a&gt;&lt;br&gt;
Provide a suitable task def name, and select the Task Role and network mode (we shall be looking into the different network modes in an upcoming blog, for now let's go ahead with bridge), select a task execution role.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuxnb7xvlie7ix9o9hcuq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuxnb7xvlie7ix9o9hcuq.png" alt="Image description" width="800" height="639"&gt;&lt;/a&gt;&lt;br&gt;
Allocate sufficient task memory and cpu based on your application requirements.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foy0czikg1jtf4zoov74m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foy0czikg1jtf4zoov74m.png" alt="Image description" width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Add a container
&lt;/h4&gt;

&lt;p&gt;Provide a container name and the ecr repo uri along with the version, you can set hard limit for the container in case you have set the task cpu and memory req this is not required, if you want dynamic port mapping, keep the host port as 0, in this case we have set it to 80 same as the container port&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F29oxkvhz3271nauybpmq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F29oxkvhz3271nauybpmq.png" alt="Image description" width="800" height="544"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
As per requirement you can explore advanced details and set container healthcheck, container timeouts, storage, logging and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a Service
&lt;/h2&gt;

&lt;p&gt;Select the launch type as EC2, select your task definition and it's version you can see the latest suffix to denote the latest version, select your cluster and provide a suitable service name, select a service type (in this case we shall go with replica), provide the number of tasks you want to run (keep in mind the instance type you chose and the resource allocated to each task while you designate the number of tasks)&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F23yjaoe3lhhkj18gjq9p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F23yjaoe3lhhkj18gjq9p.png" alt="Image description" width="800" height="460"&gt;&lt;/a&gt;&lt;br&gt;
Select the deployment strategy (we shall go into depth on this in an upcoming blog, in this case we choose Rolling Update), select a Task Placement strategy (AZ Balanced spread will help to spread tasks across instances in different AZ's for high availability)&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvuujt19dg1dtf9xl5qej.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvuujt19dg1dtf9xl5qej.png" alt="Image description" width="800" height="578"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure a Load Balancer
&lt;/h2&gt;

&lt;p&gt;Select your load balancer type(in this case we choose application load balancer), Create a new service IAM role, and select your existing Load Balancer.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpp4k7jczmtr3j47dkly0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpp4k7jczmtr3j47dkly0.png" alt="Image description" width="800" height="462"&gt;&lt;/a&gt;&lt;br&gt;
In your target group you can register the existing ECS instance, and set the health check path as /todo/api/v1.0/tasks&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhbx1d04dk6l7wo85twdw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhbx1d04dk6l7wo85twdw.png" alt="Image description" width="800" height="748"&gt;&lt;/a&gt;&lt;br&gt;
If you want to scale your tasks you can enable autoscaling, in this case we do not want to scale our tasks so we won't enable auto scaling.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkrye8tqr1m5yl40suwpy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkrye8tqr1m5yl40suwpy.png" alt="Image description" width="800" height="251"&gt;&lt;/a&gt;&lt;br&gt;
Select your listener, target group name for the Load Balancer and rest shall be populated&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69hcx5r8vdx6ipcp1puo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69hcx5r8vdx6ipcp1puo.png" alt="Image description" width="800" height="454"&gt;&lt;/a&gt; &lt;br&gt;
Service Created and Task Running!&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs539oeb2xivvcbvnv5yu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs539oeb2xivvcbvnv5yu.png" alt="Image description" width="800" height="330"&gt;&lt;/a&gt; &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqwvjxx2jix22xhhw109z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqwvjxx2jix22xhhw109z.png" alt="Image description" width="800" height="296"&gt;&lt;/a&gt; &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4jdjquwal08ha1e0rimf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4jdjquwal08ha1e0rimf.png" alt="Image description" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Allow Port 80 in EC2 and ALB&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqf7u0qi476kzpjqnw6lb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqf7u0qi476kzpjqnw6lb.png" alt="Image description" width="800" height="327"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwkv0uzt1yh0xqc5dmlbb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwkv0uzt1yh0xqc5dmlbb.png" alt="Image description" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Test API using ALB URL
&lt;/h2&gt;

&lt;h4&gt;
  
  
  GET Request
&lt;/h4&gt;

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

&lt;h4&gt;
  
  
  PUT Request
&lt;/h4&gt;

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

&lt;p&gt;If you have any queries you can connect with me on &lt;a href="https://www.linkedin.com/in/rajitpaul/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>aws</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Creating an Amazon EKS Cluster from scratch using eksctl</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Wed, 30 Mar 2022 14:47:45 +0000</pubDate>
      <link>https://forem.com/aws-builders/creating-an-amazon-eks-cluster-from-scratch-using-eksctl-540i</link>
      <guid>https://forem.com/aws-builders/creating-an-amazon-eks-cluster-from-scratch-using-eksctl-540i</guid>
      <description>&lt;p&gt;Hi folks, to create an EKS cluster, you require a launch pad, for today we shall be using an Amazon Linux 2 EC2 server as our eks launchpad. There are few pre-requisites we require to take care of -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;kubectl: Kubernetes Client to communicate with the Kubernetes API Server.  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Installing kubectl: [Source: &lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html" rel="noopener noreferrer"&gt;Installing kubectl - AWS Docs&lt;/a&gt;]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/kubectl
chmod +x ./kubectl
mkdir -p $HOME/bin &amp;amp;&amp;amp; cp ./kubectl $HOME/bin/kubectl &amp;amp;&amp;amp; export PATH=$PATH:$HOME/bin
echo 'export PATH=$PATH:$HOME/bin' &amp;gt;&amp;gt; ~/.bashrc
kubectl version --client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;eksctl: The official Amazon EKS CLI, used to create and manage multiple EKS Clusters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Installing eksctl: [Source: &lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html" rel="noopener noreferrer"&gt;Installing eksctl - eksctl docs&lt;/a&gt;]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
export PATH=$PATH:/usr/local/bin
echo 'export PATH=$PATH:/usr/local/bin' &amp;gt;&amp;gt; ~/.bashrc
eksctl version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an IAM Role for EC2 with following IAM policies: &lt;br&gt;
&lt;a href="https://eksctl.io/usage/minimum-iam-policies/" rel="noopener noreferrer"&gt;Source : eksctl doc&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the Role is created you can attach the role onto your EKS Launch Pad Server.&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  Once the pre-requisites has been taken care of we can go ahead with cluster creation.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a file named cluster.yaml with the following configuration: &lt;a href="https://github.com/RajitPaul11/AmazonEKS/blob/master/EKS-Managed-NodeGroups-Cluster/cluster.yaml" rel="noopener noreferrer"&gt;Source: My GitHub - cluster.yaml&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run eks create cluster with dry run&lt;br&gt;
&lt;code&gt;eksctl create cluster -f cluster.yaml --dry-run&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;[ This shall help you identify any errors on the config files or related to your permission, make sure you don't have additional aws user configured with less privileges than the privileges allowed in the EC2 attached role. ]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Launch your cluster with
&lt;code&gt;eksctl create cluster -f cluster.yaml&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;You need to wait for a few minutes and you shall see on the screen the CFN Stack is being deployed
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdpognx4qdzdzpng3rrpn.png" alt="Image description" width="800" height="141"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The CFN stack creates the  EKS Control Plane, SG's, Policies and Service Roles. It also creates a single nodegroup or more as mentioned in the cluster config.&lt;/p&gt;
&lt;/blockquote&gt;

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

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

&lt;p&gt;If you encounter any issues check the Cloudformation Console or try:&lt;br&gt;
&lt;code&gt;eksctl utils describe-stacks --region=Your-Region --cluster=Your-Cluster-Name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The EKS cluster has been successfully created 🎉&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F06ekxjqk0dh25mjg8808.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F06ekxjqk0dh25mjg8808.png" alt="Image description" width="800" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can access the EKS cluster from your launch pad using kubectl!&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsdfy339tx52m1op5rehj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsdfy339tx52m1op5rehj.png" alt="Image description" width="800" height="107"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Clean UP
&lt;/h3&gt;

&lt;p&gt;To delete the EKS Cluster run:&lt;br&gt;
&lt;code&gt;eksctl delete cluster your-cluster-name&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffso3t2rp8hwb63hrhb88.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffso3t2rp8hwb63hrhb88.png" alt="Image description" width="800" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you enjoyed the blog, if you face any issues please reach out to me on &lt;a href="https://www.linkedin.com/in/rajitpaul/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; and we can discuss the same, thanks! &lt;/p&gt;

&lt;h3&gt;
  
  
  Wrap Up
&lt;/h3&gt;

&lt;p&gt;You can follow me to get updated on new AWS related blogs in the coming weeks, also I am an earth buddy, don't know what that is, check this out: &lt;a href="https://consciousplanet.org/action-now" rel="noopener noreferrer"&gt;Save our Soil&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Adios!
&lt;/h3&gt;

</description>
      <category>aws</category>
      <category>kubernetes</category>
      <category>cloud</category>
      <category>devops</category>
    </item>
    <item>
      <title>Restric Access to Cloudfront Distribution using Lambda@Edge</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Sat, 26 Mar 2022 06:36:51 +0000</pubDate>
      <link>https://forem.com/aws-builders/restric-access-to-cloudfront-distribution-using-lambdaedge-15ll</link>
      <guid>https://forem.com/aws-builders/restric-access-to-cloudfront-distribution-using-lambdaedge-15ll</guid>
      <description>&lt;p&gt;Hi folks!&lt;br&gt;
Recently I came across a usecase where I had to restrict access to a website in the UAT environment, so that the iterations and changes to the UAT env are not available for public view. The website was served with the CloudFront CDN, so one of the ways we could restrict access was enforcing authentication on the Cloudfront Distribution using Lambda@Edge.&lt;/p&gt;

&lt;h3&gt;How did I achive this?&lt;/h3&gt;

&lt;p&gt;Create a Lambda Function&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to us-east-1 region as that is the only region we can deploy Lambda@Edge functions.&lt;/li&gt;
&lt;li&gt;Go to the AWS Console and choose Lambda from services.&lt;/li&gt;
&lt;li&gt;Create function and author from scratch.&lt;/li&gt;
&lt;li&gt;Provide function name, and select Node JS 14.x as runtime.&lt;/li&gt;
&lt;li&gt;In Change Default Execution Role, create a new role with basic Lambda permissions.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw8flwn1xw7oufgkux5el.png" alt="Image description" width="582" height="691"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Boom! Your function is created.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the below code and replace the user and password with your required username and password.
&lt;a href="https://gist.githubusercontent.com/njofce/3382b0fe51c59ae9038046cd5087e42a/raw/1b6a1b7c477df4b49a2c2a633265d84b4a6ac846/basic-auth.js" rel="noopener noreferrer"&gt;code&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Source: &lt;a href="https://gist.github.com/njofce/3382b0fe51c59ae9038046cd5087e42a" rel="noopener noreferrer"&gt;https://gist.github.com/njofce/3382b0fe51c59ae9038046cd5087e42a&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deploy the code.&lt;/li&gt;
&lt;li&gt;Go to general configuration in Configuration and change the function timeout to 5sec, that's the max allowed timeout for CDN triggered Lambda Function.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favnmq8n5icoc47784vrp.png" alt="Image description" width="800" height="189"&gt; &lt;/li&gt;
&lt;li&gt;Go to Permissions, and open the IAM role, and update the Trust Relationships with the below json snippet, which allows lambda and lambda@edge to assume the role.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;{&lt;br&gt;
    "Version": "2012-10-17",&lt;br&gt;
    "Statement": [&lt;br&gt;
        {&lt;br&gt;
            "Effect": "Allow",&lt;br&gt;
            "Principal": {&lt;br&gt;
                "Service": [&lt;br&gt;
                    "lambda.amazonaws.com",&lt;br&gt;
                    "edgelambda.amazonaws.com"&lt;br&gt;
                ]&lt;br&gt;
            },&lt;br&gt;
            "Action": "sts:AssumeRole"&lt;br&gt;
        }&lt;br&gt;
    ]&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1a4fu1uizkquz97wsyh8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1a4fu1uizkquz97wsyh8.png" alt="Image description" width="800" height="128"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Go to Actions, and under capabilities, select Deploy to &lt;a href="mailto:Lambda@Edge"&gt;Lambda@Edge&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Configure a new Cloudfront Trigger, select your distribution under Cloudfront event and select a Viewer request, then check include body, and confirm deploy to &lt;a href="mailto:Lambda@Edge"&gt;Lambda@Edge&lt;/a&gt;.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdeeo9q5hmiqw9kvdp1nk.png" alt="Image description" width="529" height="329"&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56ids55084iewktigdxm.png" alt="Image description" width="800" height="469"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It shall take few minutes to enforce the authentication, once done we can see a sign in option as we try to access our UAT env website, provide the username and password you used in the code and access your website. (to not disclose our client, I have used a dummy CloudFront URL with my content)&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg3dskdvbb44seqms9zwc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg3dskdvbb44seqms9zwc.png" alt="Image description" width="800" height="177"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0o2v2yyzpp8e9i4khf7i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0o2v2yyzpp8e9i4khf7i.png" alt="Image description" width="800" height="395"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;If you face any challenges please connect and discuss with me on &lt;a href="https://www.linkedin.com/in/rajitpaul/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also I'm currently part of the Save Soil Movement initiated by the Isha Foundation, I know you are aware of the conditions of the soil and as a generation we have to turn this around, Become an &lt;a href="https://consciousplanet.org/action-now?utm_campaign=cp_vol_mob&amp;amp;utm_medium=social&amp;amp;utm_source=vanity" rel="noopener noreferrer"&gt;Earth Buddy&lt;/a&gt;&lt;br&gt;
Stay Joyful! :)&lt;/p&gt;

</description>
      <category>aws</category>
      <category>serverless</category>
      <category>security</category>
    </item>
    <item>
      <title>Bitbucket Branch Based Generic Webhook Trigger on Jenkins</title>
      <dc:creator>Rajit Paul</dc:creator>
      <pubDate>Wed, 02 Mar 2022 13:47:56 +0000</pubDate>
      <link>https://forem.com/rajitpaul/bit-bucket-branch-based-generic-webhook-trigger-on-jenkins-3p8</link>
      <guid>https://forem.com/rajitpaul/bit-bucket-branch-based-generic-webhook-trigger-on-jenkins-3p8</guid>
      <description>&lt;p&gt;Namaskaram!&lt;br&gt;
I faced a recent challenge when I used BitBucket Webhook to trigger a Jenkins build, the challenge was webhooks on bitbucket are based on the entire repository, which means a push to any of the BitBucket Branch will trigger a Jenkins build.&lt;br&gt;
What was I actually looking for was a branch based webhook to trigger Jenkins Build.&lt;/p&gt;

&lt;h3&gt;What you'll need&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Jenkins&lt;/li&gt;
&lt;li&gt;BitBucket&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Configuring BitBucket:&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Go to the Repository Settings of BitBucket and then to Webhooks.&lt;/li&gt;
&lt;li&gt;Add new webhook (Title, URL- &lt;b&gt;&lt;a href="http://JenkinsUsername:JenkinsPassword@Jenkins" rel="noopener noreferrer"&gt;http://JenkinsUsername:JenkinsPassword@Jenkins&lt;/a&gt; PublicIPorPublicDomain:8080/generic-webhook-trigger/invoke&lt;/b&gt;, Status is Active, Triggers on Repository Push).&lt;/li&gt;
&lt;li&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwpmp3r6111kddsr0iqbm.png" alt="Image description" width="785" height="658"&gt;&lt;/li&gt;
&lt;li&gt;Save it.&lt;/li&gt;
&lt;li&gt;Once saved go to view requests, and enable request history collection. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;Update code in the specific branch of BitBucket:&lt;/h3&gt;

&lt;p&gt;In this part you need to make some changes in the branch of BitBucket that you want to trigger the webhook from.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Once the code is updated it will trigger a webhook request.&lt;/li&gt;
&lt;li&gt;Go to repository settings then to webhook, and then to view requests you should see something like this. (The status code may be different 404 is ok, but 301 means you are facing authentication issue)
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh4uyy81cealn9q9g2hwq.png" alt="Image description" width="800" height="70"&gt;
&lt;/li&gt;
&lt;li&gt;Click on view details, and scroll down to the bottom, you can see the Request - headers and body, we need to expand the body.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fscasar77c1m5a78vj64g.png" alt="Image description" width="330" height="670"&gt;
&lt;/li&gt;
&lt;li&gt;Once the body is expanded, copy the entire body from top to bottom.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq9etdauifb9cv3hfs3xb.png" alt="Image description" width="800" height="125"&gt;
&lt;/li&gt;
&lt;li&gt;Go to &lt;a href="https://jsonpath.curiousconcept.com/" rel="noopener noreferrer"&gt;https://jsonpath.curiousconcept.com/&lt;/a&gt; and paste the JSON data you copied in your clipboard.&lt;/li&gt;
&lt;li&gt;Run this Json Path Expression - &lt;b&gt;push.changes[0].new.links.commits.href&lt;/b&gt;
&lt;/li&gt;
&lt;li&gt;In the result you should get the commit link with the repo and it's branch we are pushing to, keep this link saved.
Our job here is done, now we move to Jenkins.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Configuring Jenkins:&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;First we shall install the Generic WebHook Trigger Plugin for Jenkins.
Go to Manage Jenkins - Plugin Manager - and Install this plugin
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmoaxfxvg077fpxwmwyrn.png" alt="Image description" width="800" height="152"&gt;
&lt;/li&gt;
&lt;li&gt;Go to the Configuration of the Jenkins Job you wish to trigger using BitBucket.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9qkbkodgl30t07yowgsn.png" alt="Image description" width="800" height="210"&gt;
&lt;/li&gt;
&lt;li&gt;In Build Triggers you should see Generic Webhook Trigger
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsuuoj9bnyi9r2zg99ee5.png" alt="Image description" width="800" height="240"&gt;
&lt;/li&gt;
&lt;li&gt;Click on add Post content Parameters - Add a variable named branch, in the expression put the JSON Path Expression we used earlier ( push.changes[0].new.links.commits.href ) and select JSONPath.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxlknkxx7os4qu3nejdwz.png" alt="Image description" width="800" height="280"&gt;
&lt;/li&gt;
&lt;li&gt;Scroll down and in Optional Filter, provide the RegEx &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;[.+?(?=repository/commits/branch)] - replace the repository and branch with your repo and branch name.&lt;/p&gt;

&lt;p&gt;You can refer the JSON Path Result that you saved earlier&lt;br&gt;
 &lt;a href="https://api.bitbucket.org/2.0/repositories/project/" rel="noopener noreferrer"&gt;https://api.bitbucket.org/2.0/repositories/project/&lt;/a&gt;&lt;b&gt;repository&lt;/b&gt;/commits/&lt;b&gt;branch&lt;/b&gt;, from this you shall get the repository and branch.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5y9y97k3a74km80xe41k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5y9y97k3a74km80xe41k.png" alt="Image description" width="800" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Considering you have your build setup, you can save the job.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Make some changes in the code in the specific branch and see your Jenkins Job being triggered!&lt;/p&gt;

&lt;p&gt;If you wish to connect or face some issues while performing this demo, you can reach out @ &lt;a href="https://www.linkedin.com/in/rajitpaul/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/rajitpaul/&lt;/a&gt;&lt;br&gt;
See ya!&lt;/p&gt;

</description>
      <category>jenkins</category>
      <category>devops</category>
      <category>bitbucket</category>
    </item>
  </channel>
</rss>
