<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rasanpreet Singh</title>
    <description>The latest articles on DEV Community by Rasanpreet Singh (@rasankhalsa).</description>
    <link>https://dev.to/rasankhalsa</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%2F1038254%2F376369e1-6cb2-4249-be90-134a6e97bbbc.png</url>
      <title>DEV Community: Rasanpreet Singh</title>
      <link>https://dev.to/rasankhalsa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rasankhalsa"/>
    <language>en</language>
    <item>
      <title>Automate CloudWatch Logs Export to S3 using Lambda and Event Bridge</title>
      <dc:creator>Rasanpreet Singh</dc:creator>
      <pubDate>Mon, 19 Jun 2023 06:34:36 +0000</pubDate>
      <link>https://dev.to/rasankhalsa/automate-cloudwatch-logs-export-to-s3-using-lambda-and-event-bridge-2mdd</link>
      <guid>https://dev.to/rasankhalsa/automate-cloudwatch-logs-export-to-s3-using-lambda-and-event-bridge-2mdd</guid>
      <description>&lt;p&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can consolidate the logs from every system, application, and AWS service you use into a single, highly scalable service by using AWS CloudWatch Logs. For each log group, you may modify the retention policy, maintain indefinite retention, or select a retention time between one day and ten years.&lt;/p&gt;

&lt;p&gt;If your organization has to report on CloudWatch data for a period longer than the designated retention duration, exporting CloudWatch data to an S3 bucket is a critical step in many hybrid environment scenarios. As S3 offers extremely long-lasting storage, it may also be connected with other monitoring or logging systems (like Microsoft Sentinel, for example). Additionally, keeping logs in CloudWatch with an extended retention period might be costly.&lt;/p&gt;

&lt;p&gt;There are two ways to push CloudWatch Logs to S3:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Manual process&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using the AWS Management Console, AWS Command Line Interface (CLI), or an SDK, we may export log data to S3 directly without using any other AWS service. This technique is straightforward and perfect when we just need to export logs once. However, using this strategy, we are unable to automatically move CloudWatch logs to S3 after a specific interval. To learn more, kindly click the following link: &lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/S3ExportTasksConsole.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/S3ExportTasksConsole.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Automated process&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this article, we'll go over a step-by-step procedure for utilizing a Lambda function and event bridge to automate the process of exporting CloudWatch log group to an S3 bucket. Here, we've utilized a lambda function with an event bridge trigger on it to automate the export of CloudWatch logs to an S3 bucket as per schedule on the trigger when run every time, which automates the process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;· We have one CloudWatch log group where logs are ingested through any AWS service or application.&lt;br&gt;
· One Amazon S3 bucket with the same region as the cloud watch log group.&lt;br&gt;
· One IAM lambda role with rights for S3, CloudWatch, and lambda execution.&lt;/p&gt;

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

&lt;p&gt;The architecture diagram illustrates the complete deployment architecture, which includes a lambda function, an event bridge rule, CloudWatch logs and an S3 bucket.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps walkthrough&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Go to the AWS Lambda dashboard &amp;gt; Functions&amp;gt; Create function &amp;gt; Choose Author from scratch. Give function a name. Choose runtime as Python 3.7&lt;/p&gt;

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

&lt;p&gt;Under permissions, choose an existing execution role with CloudWatch and S3 permissions and create a lambda function.&lt;br&gt;
Please refer to the below snippet for lambda role permissions.&lt;/p&gt;

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

&lt;p&gt;After creating the lambda function, go to Code window and put the following code there. After updating the following variables as per your environment,&lt;br&gt;
GROUP_NAME = The name of the CloudWatch log group for which you want to export data.&lt;br&gt;
DESTINATION_BUCKET = The name of the S3 bucket for the exported log data&lt;br&gt;
PREFIX = the prefix used to begin each export object's key&lt;/p&gt;

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

import boto3
import os
import datetime

GROUP_NAME = "CloudWatch log group"
DESTINATION_BUCKET = "S3-bucket"
PREFIX = "S3-Prifix"
NDAYS = 1
nDays = int(NDAYS)

currentTime = datetime.datetime.now()
StartDate = currentTime - datetime.timedelta(days=nDays)
EndDate = currentTime - datetime.timedelta(days=nDays - 1)

fromDate = int(StartDate.timestamp() * 1000)
toDate = int(EndDate.timestamp() * 1000)

BUCKET_PREFIX = os.path.join(PREFIX, StartDate.strftime('%Y{0}%m{0}%d').format(os.path.sep))

def lambda_handler(event, context):
    client = boto3.client('logs')
    response = client.create_export_task(
         logGroupName=GROUP_NAME,
         fromTime=fromDate,
         to=toDate,
         destination=DESTINATION_BUCKET,
         destinationPrefix=BUCKET_PREFIX
        )
    print(response)


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

&lt;/div&gt;

&lt;p&gt;The lambda code screen will look as below&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Create CloudWatch Event bridge rule.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go to CloudWatch dashboard &amp;gt; Events &amp;gt; Create rule. Give the rule name. Choose rule type as schedule and select next.&lt;/p&gt;

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

&lt;p&gt;In the schedule pattern option, set the rate expression to run every 5 minutes and go next.&lt;/p&gt;

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

&lt;p&gt;Next, for target type, select AWS Service. Select the lambda function as the target and mention the lambda name that we created in the above steps. Verify the configurations and create a rule.&lt;/p&gt;

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

&lt;p&gt;In order to allow CloudWatch to store items in the target S3 bucket, update the bucket policy. Add the following bucket policy with the correct S3 bucket ARN and AWS region details.&lt;/p&gt;

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

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "uploadcloudwatchlogs",
            "Effect": "Allow",
            "Principal": {
                "Service": "logs.us-east-1.amazonaws.com"
            },
            "Action": "s3:GetBucketAcl",
            "Resource": "arn:aws:s3:::s3-bucket"
        },
        {
            "Sid": "uploadcloudwatchlogs",
            "Effect": "Allow",
            "Principal": {
                "Service": "logs.us-east-1.amazonaws.com"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3::: s3-bucket/*"
        }
    ]
}


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

&lt;/div&gt;

&lt;p&gt;Now the lambda function will execute every 5 minutes and push the CloudWatch logs to S3 buckets. After successful lambda execution, you can view the CloudWatch logs exported to the S3 bucket.&lt;/p&gt;

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

</description>
      <category>aws</category>
      <category>serverless</category>
      <category>cloudwatch</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Deploying Kubernetes cluster with YAML on AWS EKS</title>
      <dc:creator>Rasanpreet Singh</dc:creator>
      <pubDate>Sun, 14 May 2023 03:35:31 +0000</pubDate>
      <link>https://dev.to/rasankhalsa/deploying-kubernetes-cluster-with-yaml-on-aws-eks-2561</link>
      <guid>https://dev.to/rasankhalsa/deploying-kubernetes-cluster-with-yaml-on-aws-eks-2561</guid>
      <description>&lt;p&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;br&gt;
A managed service called Amazon EKS makes it easier to set up Kubernetes on AWS. In order to manage containerized workflows, Kubernetes gives businesses a wide range of advantages, therefore, all startup and enterprise IT organizations are trying to adopt it.&lt;br&gt;
The official CLI tool for Amazon EKS is eksctl. It facilitates the creation of nodegroups and clusters. There are two ways to start an EKS cluster using eksctl.&lt;/p&gt;

&lt;p&gt;• eksctl CLI and parameters by a single command. It is straightforward. Refer to this blog for more details. &lt;a href="https://medium.com/aws-tip/build-aws-kubernetes-eks-cluster-with-eksctl-9040411badcb" rel="noopener noreferrer"&gt;https://medium.com/aws-tip/build-aws-kubernetes-eks-cluster-with-eksctl-9040411badcb&lt;/a&gt; &lt;br&gt;
• eksctl CLI and YAML configuration.&lt;/p&gt;

&lt;p&gt;However, in this post, we favour the YAML configuration as it allows for declarative cluster configuration that is reusable. YAML files, which specify the requirements for the application and enable reproducible setup and deployment, are the source of Kubernetes' magic. Your Kubernetes cluster can be declaratively configured using this method. The fundamental benefit of YAML over other comparable formats is that it is human readable. In addition to building EKS clusters, eksctl also includes best practices for tagging, annotation, addons, policies, and other things.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
You must prepare and install the following requirements on your local system before you begin the EKS installation:&lt;br&gt;
• AWS CLI&lt;br&gt;
• Kubectl&lt;br&gt;
• Eksctl&lt;br&gt;
For installation steps details please refer the link shared in overview section&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create EKS Cluster&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Create the YAML Recipe for the EKS Cluster&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You must produce a YAML file with the EKS cluster's configuration information to utilize eksctl. You must set the following parameters in the yaml file:&lt;/p&gt;

&lt;p&gt;name:  mention name for the cluster &lt;br&gt;
region: Name of the Amazon Region where the Cluster should be created.&lt;br&gt;
vpc: The VPC where the cluster should be configured. A new VPC will be generated automatically if you don't set this.&lt;/p&gt;

&lt;p&gt;Create a file named cluster.yaml&lt;br&gt;
vim cluster.yaml&lt;/p&gt;

&lt;p&gt;Copy the following contents to the file. You need to replace the region, cluster name, nodegroup name, SSH keypair name etc. as per your requirement.&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: eks-cluster
  region: us-east-1


managedNodeGroups:
  - name: eks-cluster-ng
    instanceType: t3.small
    minSize: 1
    maxSize: 3
    desiredCapacity: 2
    volumeSize: 20
    volumeType: gp3
    ssh:
      allow: true
      publicKeyName: kube-ssh
    tags:
      Env: Dev
      k8s.io/cluster-autoscaler/enabled: 'true'
    iam:
      attachPolicyARNs:
        - arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
        - arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
        - arn:aws:iam::aws:policy/ElasticLoadBalancingFullAccess
        - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
        - arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
      withAddonPolicies:
        autoScaler: true`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run eks create cluster with dry run option. This will help to identify any errors on the config files or related to any permissions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eksctl create cluster -f cluster.yaml --dry-run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Launch your cluster with following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eksctl create cluster -f cluster.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the creation process has finished you will receive a message that says EKS Cluster "eks-cluster" in "us-east-1" region is ready:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjnmiwa9vwwuc4lr7ade3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjnmiwa9vwwuc4lr7ade3.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
The CloudFormation templates are deployed at the backend when you run the cluster creation command mentioned above. The clusters should ideally be deployed using CloudFormation templates. You can see that a CloudFormation Stack has been set up for provisioning control plane and node groups in the image below in the CloudFormation dashboard. we need to wait for 10-15 minutes. &lt;/p&gt;

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

&lt;p&gt;*&lt;em&gt;VPC information *&lt;/em&gt;&lt;br&gt;
When using the above YAML, eksctl will automatically configure a new VPC in your AWS account with all the configurations and setup necessary for a EKS VPC.&lt;br&gt;
If you needed to use an existing VPC, you can use a config file like this with updating the respective subnet id details:&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: eks-cluster
  region: us-east-1
  version: "1.24"

vpc:
  subnets:
    public:
      pub-ap-south-1a: 
        id: "xxxxxxxx"
      pub-ap-south-1b: 
        id: "xxxxxxxx"
      pub-ap-south-1c: 
        id: "xxxxxxxx"
managedNodeGroups:
  - name: eks-cluster-ng
    instanceType: t3.small
    minSize: 1
    maxSize: 3
    desiredCapacity: 2
    volumeSize: 20
    volumeType: gp3
    subnets:
      - pub-ap-south-1a
      - pub-ap-south-1b
      - pub-ap-south-1c
    ssh:
      allow: true
      publicKeyName: kube-ssh
    tags:
      Env: Dev
    iam:
      attachPolicyARNs:
        - arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
        - arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
        - arn:aws:iam::aws:policy/ElasticLoadBalancingFullAccess
        - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
        - arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
      withAddonPolicies:
        autoScaler: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Connect to EKS cluster&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Once the cluster is provisioned, you can use the following AWS CLI command to get or update the kubeconfig file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws eks update-kubeconfig --region us-east-1 --name &amp;lt;cluster_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Get List of clusters
              kubectl cluster-info
              eksctl get clusters --region us-east-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Congratulations, your Amazon EKS Cluster is now operational and ready for usage!! You can verify the cluster status on the EKS dashboard.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Cleaning Up&lt;/strong&gt;&lt;br&gt;
We can delete the whole cluster (about 15 minutes) with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eksctl delete cluster --name &amp;lt;clusterName&amp;gt; --region us-east-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

</description>
      <category>aws</category>
      <category>eks</category>
      <category>kubernetes</category>
      <category>containers</category>
    </item>
    <item>
      <title>Network Security with Amazon Network Firewall</title>
      <dc:creator>Rasanpreet Singh</dc:creator>
      <pubDate>Thu, 23 Mar 2023 12:04:13 +0000</pubDate>
      <link>https://dev.to/rasankhalsa/network-security-with-amazon-network-firewall-25e7</link>
      <guid>https://dev.to/rasankhalsa/network-security-with-amazon-network-firewall-25e7</guid>
      <description>&lt;p&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;br&gt;
At AWS, cloud security is "job zero" task. Security is given high attention while developing AWS services and features. Network-level traffic filtration is one level of defense that can be used to protect your network and computers from security events. For all Amazon Virtual Private Cloud Infrastructure, Network Firewall is a highly available, managed solution that makes it simple to establish essential network security. To safeguard your virtual networks on AWS, it helps you to quickly create and manage stateful inspection, intrusion prevention and detection, and web filtering. With no additional customer investment in security infrastructure, Amazon Network Firewall automatically scales with your traffic to ensure high availability.&lt;br&gt;
AWS Network Firewall consists of three essential parts.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Rule Groups&lt;/strong&gt;: It stores criteria for inspecting traffic and processing packets and traffic flows that match the inspection criteria.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Policy&lt;/strong&gt;: It specifies some policy-level behavior parameters as well as a reusable collection of stateless and stateful rule groups.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Firewall&lt;/strong&gt;: It enforces the firewall policy's inspection rules to the VPC that the rules are designed to defend. One firewall policy is necessary for each firewall. The firewall also specifies options for stateful traffic filtering and how to log information about your network traffic.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Deployment models for AWS Network Firewall&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With AWS Network Firewall, various deployment types are possible. The appropriate model will rely on the requirements and use case. The following models are the most widely used:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Distributed model&lt;/strong&gt;: Amazon Network Firewall is deployed using a distributed deployment strategy in each VPC that needs security. Each VPC is independently secured, and VPC isolation reduces the explosion radius.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Centralized AWS Network Firewall deployment mode&lt;/strong&gt;l: In this for North-South (internet egress and ingress, on-premises) and/or East-West (VPC-to-VPC) traffic, a centralized VPC is used to deploy the AWS Network Firewall. AWS Transport Gateway is a requirement in this model. As a network hub, AWS Transit Gateway streamlines connectivity between VPCs.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DbrEpKB5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bq1isot66f8zjf0hulpr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DbrEpKB5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bq1isot66f8zjf0hulpr.png" alt="Image description" width="737" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps walkthrough&lt;/strong&gt;&lt;br&gt;
Under firewall creation, we will be creating Network Firewall Rule Group and Firewall policy first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create Firewall RuleGroup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this exercise, we will create two sets of rules:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Alerting ICMP traffic&lt;/li&gt;
&lt;li&gt; Domain filter
Go to VPC &amp;gt; Amazon Network Firewall &amp;gt; Network Firewall rule groups and click on Create Network Firewall rule group&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s50Nj52g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zmfm75efxymsptputb7t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s50Nj52g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zmfm75efxymsptputb7t.png" alt="Image description" width="880" height="329"&gt;&lt;/a&gt;&lt;br&gt;
Under Rule group type:&lt;br&gt;
• Select Stateful rule group&lt;br&gt;
• Specify Name&lt;br&gt;
• Set Capacity to 100&lt;br&gt;
• Choose 5-tuple from the Stateful rule group selections.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a9NmTSp8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9qeeip9oecube414iys.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a9NmTSp8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9qeeip9oecube414iys.png" alt="Image description" width="880" height="369"&gt;&lt;/a&gt;&lt;br&gt;
Choose ICMP as the protocol under "Add rule" and in action select alert; otherwise, leave everything else as is. Then, click "Add rule."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7zJ1IyE---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4c1qf31ykzc31b7cokho.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7zJ1IyE---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4c1qf31ykzc31b7cokho.jpg" alt="Image description" width="880" height="582"&gt;&lt;/a&gt;&lt;br&gt;
After adding the rule, scroll down and select Create stateful rule. Icmp-alert rule has successfully been created for group.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VdSAZW22--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tggj9ewxg580felh9k4e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VdSAZW22--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tggj9ewxg580felh9k4e.png" alt="Image description" width="880" height="371"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Create domain filter rule group&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To filter/allow particular domains, a rule will now be created:&lt;br&gt;
Go to VPC &amp;gt; Amazon Network Firewall &amp;gt; Network Firewall rule groups and click on Create Network Firewall rule group&lt;br&gt;
Under Rule group type:&lt;br&gt;
• Select Stateful rule group&lt;br&gt;
• Specify Name&lt;br&gt;
• Set Capacity to 100&lt;br&gt;
• Choose Domain list under Stateful rule group options.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--of7lpSN9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/263063z455ki2hwn459i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--of7lpSN9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/263063z455ki2hwn459i.png" alt="Image description" width="880" height="398"&gt;&lt;/a&gt;&lt;br&gt;
Under Domain list:&lt;br&gt;
• Add .amazon.com&lt;br&gt;
• Choose both HTTP and HTTPS under Protocols.&lt;br&gt;
• Under Action select Allow&lt;br&gt;
select Build stateful rule group&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OfqfEtkA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zf6vadpaj7lqzuneq1ab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OfqfEtkA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zf6vadpaj7lqzuneq1ab.png" alt="Image description" width="880" height="453"&gt;&lt;/a&gt;&lt;br&gt;
We have now created two rules.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9g6wUyQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6jpt5cr4xqy7l3vez4u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9g6wUyQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6jpt5cr4xqy7l3vez4u.png" alt="Image description" width="880" height="355"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Create Firewall Policy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To filter network traffic, you will construct firewall policies in this activity.&lt;br&gt;
Go to VPC &amp;gt; Amazon Network Firewall &amp;gt; Firewall policies and click on Create firewall policy&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XLzqUAwL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sewqf9napo0dcfzetcc5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XLzqUAwL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sewqf9napo0dcfzetcc5.png" alt="Image description" width="880" height="268"&gt;&lt;/a&gt;&lt;br&gt;
Under Describe firewall policy:&lt;br&gt;
Specify Name and click on Next&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J2SGDLcf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sk8is7q9d4ayytzqvcch.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J2SGDLcf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sk8is7q9d4ayytzqvcch.png" alt="Image description" width="880" height="411"&gt;&lt;/a&gt;&lt;br&gt;
Under Add rule groups:&lt;br&gt;
• Select for all packets, take the same step&lt;br&gt;
• Under Action select Forward to stateful rule groups&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qGfXhBNi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m8kxpmk9curpyui6o88x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qGfXhBNi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m8kxpmk9curpyui6o88x.png" alt="Image description" width="880" height="371"&gt;&lt;/a&gt;&lt;br&gt;
Add rule groups by selecting both the domain-allow-centerlized and icmp-centerized rules under Stateful rule group.&lt;br&gt;
Click Next, go over the information, and then select Build firewall policy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Dxd5ruq8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74m2zt48fqt83xbmywbs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Dxd5ruq8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74m2zt48fqt83xbmywbs.jpg" alt="Image description" width="880" height="771"&gt;&lt;/a&gt;&lt;br&gt;
At this point we currently have one firewall policy created&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TJlN9uTe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dkjtq58hkp2fkc0x6eso.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TJlN9uTe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dkjtq58hkp2fkc0x6eso.png" alt="Image description" width="880" height="193"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Create Firewall&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will build a firewall in this activity to inspect and filter network traffic. &lt;br&gt;
Go to VPC &amp;gt; Amazon Network Firewall &amp;gt; Firewalls and click on Create firewall&lt;br&gt;
Under Firewall details:&lt;br&gt;
• Specify Name&lt;br&gt;
• Under VPC, select inspection (VPC name, where the firewall &lt;br&gt;
needs to be deployed)&lt;br&gt;
• Under Availability Zone, select respice zones&lt;br&gt;
• Under Subnet select firewall subnet and click on Next&lt;br&gt;
Note: Right now we are going with one AZ deployment&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_prtOO1j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1ab26si777w7yesl3yz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_prtOO1j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1ab26si777w7yesl3yz.png" alt="Image description" width="880" height="456"&gt;&lt;/a&gt;&lt;br&gt;
Under Associated firewall policy:&lt;br&gt;
• Select Associate an existing firewall policy and select inspction-firewall-centerlized&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qxYxerrb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f3wmwmu81d3uil4tbh27.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qxYxerrb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f3wmwmu81d3uil4tbh27.png" alt="Image description" width="880" height="398"&gt;&lt;/a&gt;&lt;br&gt;
We currently have a Firewall that is provisioning. Be patient; it can take a while.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configure Logging&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's configure logging while your firewall is being provisioned:&lt;br&gt;
Scroll down to Logging and click on Edit:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VTm2VBss--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ftofr16k5wqay4h4yzsv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VTm2VBss--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ftofr16k5wqay4h4yzsv.jpg" alt="Image description" width="880" height="486"&gt;&lt;/a&gt;&lt;br&gt;
In the Firewall logging configuration edit box:&lt;br&gt;
• For Log type select both Alert and flow&lt;br&gt;
• Choose the CloudWatch log group under Log destination for alerts. &lt;br&gt;
/network-firewall-centrlized&lt;br&gt;
• Under Log destination for flows select CloudWatch log group and select  /network-firewall-centrlized&lt;br&gt;
and click Save:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kG-4_igu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t62rx9xgyvlkca9qhclh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kG-4_igu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t62rx9xgyvlkca9qhclh.jpg" alt="Image description" width="880" height="809"&gt;&lt;/a&gt;&lt;br&gt;
At this point, we have a firewall in Ready state&lt;br&gt;
Once firewall is in Ready state, we need to collect firewall endpoint id. These are the endpoints that will serve as targets for traffic directed at your firewall. Next, update the route table. Next, update the routing table adding the endpoint id with the respective availability zone route table.&lt;br&gt;
You can inspect firewall logs after everything is linked and traffic is passing via the network firewall. The CloudWatch logs may take three to six minutes to update.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1a5wocSo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zy5ol1j2bn03y2h3p8ni.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1a5wocSo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zy5ol1j2bn03y2h3p8ni.png" alt="Image description" width="610" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reference link: &lt;a href="https://catalog.workshops.aws/networkfirewall/en-US/setup/centralmodel/create-anfw/create-firewall-rule-group"&gt;https://catalog.workshops.aws/networkfirewall/en-US/setup/centralmodel/create-anfw/create-firewall-rule-group&lt;/a&gt; &lt;/p&gt;

</description>
      <category>aws</category>
      <category>security</category>
      <category>firewall</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Finding unused Amazon EBS volumes using AWS Lambda, EventBridge, and SNS for cost optimization</title>
      <dc:creator>Rasanpreet Singh</dc:creator>
      <pubDate>Mon, 06 Mar 2023 04:38:44 +0000</pubDate>
      <link>https://dev.to/rasankhalsa/finding-unused-amazon-ebs-volumes-using-aws-lambda-eventbridge-and-sns-for-cost-optimization-43mo</link>
      <guid>https://dev.to/rasankhalsa/finding-unused-amazon-ebs-volumes-using-aws-lambda-eventbridge-and-sns-for-cost-optimization-43mo</guid>
      <description>&lt;p&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;br&gt;
Cloud cost control is one of the top goals for customers across all sectors and industries. With respect to the AWS EBS storage service, unused resource expenses may be incurred if the lifecycle of volumes is not fully observable. Hence, Amazon EBS volumes that are unused or are forgotten about, add to AWS charges.&lt;br&gt;
In this article, we'll show you how to utilize AWS Lambda, Amazon EventBridge, and AWS SNS to discover EBS volumes that are idle and disconnected from an EC2 instance by receiving alerts through email notifications. This strategy will aid in cost reduction and cost optimization.&lt;br&gt;
In order to list all the unused EBS volumes and send email notifications using SNS topics, we will build a lambda function for this solution. In the following steps, we will establish an Amazon EventBridge rule that will automatically call the lambda function once a week. As a result, we can compile a list of all unused EBS volumes on a weekly basis in a particular AWS region.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CiQiczcO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hes00rg6lxhwiat9fh8z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CiQiczcO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hes00rg6lxhwiat9fh8z.png" alt="Image description" width="880" height="276"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Prerequisite&lt;/strong&gt;&lt;br&gt;
To receive email notifications, we require one subscribed AWS SNS topic. We will utilize the SNS topic ARN in Lambda code.&lt;br&gt;
The Lambda IAM role includes SNS publish, EBS volume describe, list and basic lambda execution permissions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create Lambada function&lt;/strong&gt;&lt;br&gt;
· Visit the Lambda Service Dashboard using the Amazon Management Console. On the Lambda dashboard, select &lt;strong&gt;Create Function&lt;/strong&gt;.&lt;br&gt;
· After that, click &lt;strong&gt;Author from Scratch&lt;/strong&gt;, specify the name of the function, and select &lt;strong&gt;Python 3.7&lt;/strong&gt; as the runtime. Then pick the lambda service role and select the Create option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Soziml8O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4i3o53g2a6lf67fvd9gq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Soziml8O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4i3o53g2a6lf67fvd9gq.png" alt="Image description" width="829" height="456"&gt;&lt;/a&gt;&lt;br&gt;
Note: Please ensure that the SNS and EBS permissions policies are associated with the lambda execution role.&lt;br&gt;
· Then open a code editor, begin writing the code&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--brrdOsjU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hdbrj4lqiaylyv1i0gzq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--brrdOsjU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hdbrj4lqiaylyv1i0gzq.png" alt="Image description" width="712" height="521"&gt;&lt;/a&gt;&lt;br&gt;
· Enter the following code into the Lambda function with the correct SNS topic ARN and then choose &lt;strong&gt;Deploy&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;import boto3
def lambda_handler(event, context):
    ec2_client = boto3.client('ec2')
    sns_client = boto3.client('sns')
    volumes = ec2_client.describe_volumes()
    sns_arn = '&amp;lt;SNS Topic ARN&amp;gt;'

    unused_vols = []
    for volume in volumes['Volumes']:
        if len(volume['Attachments']) == 0:
            unused_vols.append(volume['VolumeId'])
            print(volume)


    email_body = "##### Unused EBS Volumes ##### \n"

    for vol in unused_vols:
        email_body = email_body + f"VolumeId = {vol} \n"


    # Send Email

    sns_client.publish(
        TopicArn = sns_arn,
        Subject = 'Unused EBS Volumes List',
        Message = email_body
    )
    print(email_body)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Now the lambda function is ready for execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create EventBridge Schedule Lambda on Weekly Basis&lt;/strong&gt;&lt;br&gt;
· Navigate Amazon EventBridge service and open rules. And click on &lt;strong&gt;create rule&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0uhG-5OT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zw1ixizu1d4iejf2zit.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0uhG-5OT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zw1ixizu1d4iejf2zit.png" alt="Image description" width="880" height="361"&gt;&lt;/a&gt;&lt;br&gt;
· Mention the &lt;strong&gt;rule name&lt;/strong&gt;, select the schedule option, and specify a &lt;strong&gt;Cron expression&lt;/strong&gt; by selecting the &lt;strong&gt;cron-based schedule&lt;/strong&gt;. Here we are using the cron expression which will trigger once a week.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OhXtFeZg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2y9ypfd9yzd5hxcinydr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OhXtFeZg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2y9ypfd9yzd5hxcinydr.png" alt="Image description" width="786" height="848"&gt;&lt;/a&gt;&lt;br&gt;
· In the Targets details, select the &lt;strong&gt;AWS Lambda&lt;/strong&gt; option and select our lambda function which we build in the earlier step and then choose Create rule.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GQP2lpD8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bj2vgk9vt2j4woo2qm9e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GQP2lpD8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bj2vgk9vt2j4woo2qm9e.png" alt="Image description" width="714" height="750"&gt;&lt;/a&gt;&lt;br&gt;
· The Lambda function will now automatically get triggered every week to identify the unused EBS volumes and send email alerts using the SNS topic as below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i8e4k1P4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xrnlcd0ccu1olqaz3yyv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i8e4k1P4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xrnlcd0ccu1olqaz3yyv.png" alt="Image description" width="880" height="299"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this article, we showed you how to receive email notifications about a list of unused EBS volumes so you may check them out for further action and delete them if they're not required to minimize the cost of your monthly Amazon bill.&lt;/p&gt;

</description>
      <category>lambda</category>
      <category>cloud</category>
      <category>python</category>
      <category>aws</category>
    </item>
  </channel>
</rss>
