<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Prithvi A Parit on Medium]]></title>
        <description><![CDATA[Stories by Prithvi A Parit on Medium]]></description>
        <link>https://medium.com/@prithvilee22?source=rss-12eba527366d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HYUmlCCkAnweidgau8ZCiA.jpeg</url>
            <title>Stories by Prithvi A Parit on Medium</title>
            <link>https://medium.com/@prithvilee22?source=rss-12eba527366d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:59:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prithvilee22/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mastering AWS Cost Management: Analyzing Usage and Optimizing Costs with AWS Billing, Trusted…]]></title>
            <link>https://medium.com/@prithvilee22/mastering-aws-cost-management-analyzing-usage-and-optimizing-costs-with-aws-billing-trusted-c4096927883c?source=rss-12eba527366d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4096927883c</guid>
            <dc:creator><![CDATA[Prithvi A Parit]]></dc:creator>
            <pubDate>Sun, 16 Mar 2025 13:56:30 GMT</pubDate>
            <atom:updated>2025-03-16T13:56:30.887Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mastering AWS Cost Management: Analyzing Usage and Optimizing Costs with AWS Billing, Trusted Advisor, and Compute Optimizer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*U68AzenWyWYVjvKE2hNRoA.png" /></figure><h3>Introduction</h3><p>One of the largest hassles organizations incur while scaling infrastructure on AWS is managing cloud expense effectively. Absent cost analysis and optimization approaches, it becomes simple for your expenses to snowball out of control. Relatively, there are a variety of robust features — AWS Billing and Cost Management, AWS Trusted Advisor, and AWS Compute Optimizer — that allow you to watch, analyze, and minimize AWS expense.</p><p>In this blog, we’ll explore how to use these tools to get a detailed view of your AWS usage and costs, identify opportunities for cost savings, and make data-driven decisions to optimize your cloud infrastructure.</p><h3>🔎 AWS Billing and Cost Management</h3><p>AWS Billing and Cost Management is the go-to hub for tracking and managing your AWS cost. It offers a complete breakdown of your usage of the services and associated costs and allows you to monitor where your money is going and look for trends over time.</p><h3>🚀 Key Features</h3><ol><li><strong>Cost and Usage Reports (CUR):</strong></li></ol><ul><li>Offers granular data about your usage of AWS and the cost, to the hour or even minute.</li><li>Enables you to break down costs by service, region, or associated account.</li></ul><p><strong>2. Budgets:</strong></p><ul><li>Create budgets for service usage, cost, or reserved instance usage.</li><li>Receive alerts when you go over your budget limits.</li></ul><p><strong>3. Cost Anomalies:</strong></p><ul><li>Identifies unusual spikes or dips in your expenditure automatically.</li><li>Assists you in identifying unexpected costs early.</li></ul><p><strong>4. Forecasting:</strong></p><ul><li>Forecasts future cost based on past usage trends.</li><li>Assists you in planning for future charges and provisioning resources accordingly.</li></ul><p>💡 How to Use AWS Billing and Cost Management to Analyze Costs</p><ol><li><strong>Create a Cost and Usage Report:</strong></li></ol><ul><li>Go to the AWS Billing Console → Reports → Create Report.</li><li>Edit the report to show the services, associated accounts, and date range you require.</li></ul><p><strong>2. Set Up a Budget:</strong></p><ul><li>Navigate to AWS Budgets → Create Budget.</li><li>Establish monthly or quarterly thresholds on service usage and cost.</li><li>Configure email or SNS alerts on breaches.</li></ul><p><strong>3. Turn on Cost Anomaly Detection:</strong></p><ul><li>Navigate to AWS Cost Management → Cost Anomaly Detection.</li><li>Select the service and metric you wish to monitor.</li><li>Configure thresholds and notifications.</li></ul><h3>✅ AWS Trusted Advisor</h3><p>AWS Trusted Advisor gives you real-time recommendations about your AWS environment to make it more secure, perform better, be fault-tolerant, and cost-effective. For cost optimization, it makes specific, detailed recommendations on how to cut waste and optimize resource utilization.</p><h3>🚀 Key Cost Optimization Checks</h3><ol><li><strong>Underutilized EC2 Instances:</strong></li></ol><ul><li>Highlights EC2 instances with low CPU usage.</li><li>Suggests resizing or terminating these instances to conserve cost.</li></ul><p><strong>2. Idle Load Balancers:</strong></p><ul><li>Identifies load balancers that are unused or contain minimal traffic.</li><li>Suggests deleting or reconfiguring them.</li></ul><p>3. <strong>Unassociated Elastic IPs:</strong></p><ul><li>Suggests deleting or reconfiguring them.</li><li>Identifies Elastic IP addresses not assigned to any instance.</li><li>Suggests releasing them to prevent charges.</li></ul><p>4. <strong>Unoptimized S3 Storage:</strong></p><ul><li>Identifies S3 buckets with objects that can be migrated to lower-cost storage classes.</li><li>Suggests moving them to S3 Glacier or S3 Infrequent Access.</li></ul><h3>💡 How to Use AWS Trusted Advisor for Cost Savings</h3><ol><li><strong>Go to AWS Trusted Advisor:</strong></li></ol><ul><li>Open the AWS Management Console → Trusted Advisor.</li><li>Choose the “Cost Optimization” category.</li></ul><p><strong>2. Check the Recommendations:</strong></p><ul><li>Look for underutilized resources such as EC2 instances, EBS volumes, and RDS databases.</li><li>Find unused resources that can be deleted or resized.</li></ul><p><strong>3. Take Action:</strong></p><ul><li>Terminate or resize underutilized instances.</li><li>Delete unattached Elastic IPs and unused load balancers.</li><li>Transfer data to lower-cost storage classes.</li></ul><h3>📊 AWS Compute Optimizer</h3><p><strong>AWS Compute Optimizer</strong> uses machine learning to analyze your workloads and recommend the optimal EC2 instance types, EBS volumes, and Lambda configurations to reduce costs and improve performance.</p><h3>🚀 Key Features</h3><ol><li><strong>Instance Right-Sizing:</strong></li></ol><ul><li>Recommends resizing or switching instance families based on utilization patterns.</li><li>Highlights overprovisioned or underutilized instances.</li></ul><p><strong>2. EBS Volume Optimization:</strong></p><ul><li>Analyzes I/O and throughput to recommend the most cost-effective volume type.</li></ul><p><strong>3. Lambda Function Recommendations:</strong></p><ul><li>Suggests changes to memory and timeout settings for better performance and cost-efficiency.</li></ul><p><strong>4. Auto-Scaling Group Recommendations:</strong></p><ul><li>Provides guidance on adjusting scaling policies to handle load more efficiently.</li></ul><h3>💡 How to Use AWS Compute Optimizer</h3><ol><li><strong>Enable Compute Optimizer:</strong></li></ol><ul><li>Open the AWS Management Console → Compute Optimizer.</li><li>Enable recommendations for EC2 instances, EBS volumes, and Lambda functions.</li></ul><p><strong>2. Review Recommendations:</strong></p><ul><li>Review suggestions for resizing or modifying instances.</li><li>Analyze projected savings and performance improvements.</li></ul><p><strong>3. Apply Recommendations:</strong></p><ul><li>Test changes in a non-production environment first.</li><li>Apply resizing or configuration changes gradually.</li></ul><h3>🏆 Best Practices for AWS Cost Management</h3><p>✅ <strong>Tag Your Resources:</strong></p><ul><li>Use consistent tagging to track costs by department, environment, or project.</li><li>Example: Environment = Production, Project = WebApp.</li></ul><p>✅ <strong>Enable Savings Plans and Reserved Instances:</strong></p><ul><li>Purchase savings plans for consistent workloads.</li><li>Use reserved instances to lock in lower rates for predictable usage.</li></ul><p>✅ <strong>Monitor and Automate Cost Optimization:</strong></p><ul><li>Set up automated alerts for budget breaches.</li><li>Use AWS Lambda and CloudWatch to automate cost-saving actions (e.g., stopping idle instances).</li></ul><p>✅ <strong>Review Regularly:</strong></p><ul><li>Review AWS Cost Management reports monthly.</li><li>Adjust resources based on seasonal patterns or usage trends.</li></ul><h3>🚀 Conclusion</h3><p>Effectively managing AWS costs requires a proactive approach — regular monitoring, intelligent analysis, and continuous optimization. AWS Billing and Cost Management helps you track and forecast spending, Trusted Advisor highlights areas to cut costs, and Compute Optimizer ensures you’re using the right resources for the job.</p><p>By using these tools together, you can significantly reduce waste, improve performance, and make the most of your AWS infrastructure. Start analyzing and optimizing today!</p><p>👉 <strong>Ready to take control of your AWS costs? Log into the AWS Management Console and start with Trusted Advisor and Compute Optimizer today!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4096927883c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an AI-Powered Workflow with AWS Bedrock and DeepSeek]]></title>
            <link>https://medium.com/@prithvilee22/building-an-ai-powered-workflow-with-aws-bedrock-and-deepseek-e936596c64fe?source=rss-12eba527366d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e936596c64fe</guid>
            <dc:creator><![CDATA[Prithvi A Parit]]></dc:creator>
            <pubDate>Wed, 05 Mar 2025 17:11:05 GMT</pubDate>
            <atom:updated>2025-03-05T17:11:05.644Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*__2LHom6JuqguOAiaN2pJw.png" /></figure><h3>Introduction</h3><p>AWS Bedrock enables developers to build, fine-tune, and deploy generative AI models with ease. In this guide, we’ll explore how to use AWS Bedrock with a DeepSeek model. We’ll download a DeepSeek model, upload it to Amazon S3, connect it to AWS Bedrock, and use it for querying and training with our data.</p><h3>Prerequisites</h3><p>Before we begin, ensure you have:</p><ul><li>An AWS account with access to Bedrock, S3, and IAM</li><li>AWS CLI installed and configured</li><li>Python and boto3 installed (optional for scripting)</li></ul><h3>Step 1: Downloading the DeepSeek Model</h3><p>DeepSeek provides powerful AI models for various NLP tasks. You can download a pre-trained model from their official repository or Hugging Face.</p><pre>wget https://huggingface.co/deepseek-ai/deepseek-model.tar.gz</pre><p>After downloading, extract the model files:</p><pre>tar -xvzf deepseek-model.tar.gz</pre><p>This will create a directory containing model weights, tokenizer, and configuration files.</p><h3>Step 2: Uploading the Model to Amazon S3</h3><p>To use AWS Bedrock, the model must be stored in an S3 bucket. Create an S3 bucket if you don’t already have one:</p><pre>aws s3 mb s3://my-deepseek-model-bucket</pre><p>Upload the model files:</p><pre>aws s3 cp deepseek-model/ s3://my-deepseek-model-bucket/deepseek-model/ --recursive</pre><h3>Step 3: Configuring AWS Bedrock</h3><p>Once the model is in S3, configure AWS Bedrock to use it. AWS Bedrock allows integrating custom models using foundation models (FMs).</p><ol><li><strong>Create an IAM Role</strong></li></ol><p>The IAM role should have permissions to access S3 and Bedrock:</p><pre>{<br>    &quot;Effect&quot;: &quot;Allow&quot;,<br>    &quot;Action&quot;: [&quot;s3:GetObject&quot;, &quot;s3:ListBucket&quot;],<br>    &quot;Resource&quot;: [<br>        &quot;arn:aws:s3:::my-deepseek-model-bucket&quot;,<br>        &quot;arn:aws:s3:::my-deepseek-model-bucket/*&quot;<br>    ]<br>}</pre><p>Attach this policy to an IAM role named AWSBedrockModelAccess.</p><p><strong>2. Register the Model in AWS Bedrock</strong> Use the AWS SDK or AWS CLI to register the model:</p><pre>aws bedrock register-model \<br>    --model-name deepseek-custom \<br>    --s3-uri s3://my-deepseek-model-bucket/deepseek-model/ \<br>    --role-arn arn:aws:iam::123456789012:role/AWSBedrockModelAccess</pre><h3>Step 4: Querying and Training the Model</h3><p>Once registered, you can query or fine-tune the model using AWS Bedrock’s API.</p><h3>Querying the Model</h3><p>Use the AWS SDK to send prompts:</p><pre>import boto3<br>client = boto3.client(&quot;bedrock-runtime&quot;)<br>response = client.invoke_model(<br>    modelId=&quot;deepseek-custom&quot;,<br>    contentType=&quot;application/json&quot;,<br>    accept=&quot;application/json&quot;,<br>    body=&#39;{&quot;prompt&quot;: &quot;What is AWS Bedrock?&quot;}&#39;<br>)<br>print(response[&quot;body&quot;].read().decode(&quot;utf-8&quot;))Training the Model</pre><h3>Training the Model</h3><p>To fine-tune, first prepare your training dataset in JSONL format and upload it to S3:</p><pre>aws s3 cp training-data.jsonl s3://my-deepseek-model-bucket/training-data/</pre><p>Then, start training:</p><pre>aws bedrock fine-tune-model \<br>    --model-id deepseek-custom \<br>    --training-data-uri s3://my-deepseek-model-bucket/training-data/ \<br>    --output-model-uri s3://my-deepseek-model-bucket/fine-tuned-model/ \<br>    --role-arn arn:aws:iam::123456789012:role/AWSBedrockModelAccess</pre><h3>Conclusion</h3><p>In this guide, we explored how to use AWS Bedrock with a DeepSeek model by:</p><ul><li>Downloading and extracting the model</li><li>Uploading it to Amazon S3</li><li>Registering it in AWS Bedrock</li><li>Querying and fine-tuning it</li></ul><p>By leveraging AWS Bedrock, you can efficiently deploy and scale AI-powered applications. 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e936596c64fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hands-On Kafka Mastery with AWS]]></title>
            <link>https://medium.com/@prithvilee22/kafka-10c32b4985a0?source=rss-12eba527366d------2</link>
            <guid isPermaLink="false">https://medium.com/p/10c32b4985a0</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Prithvi A Parit]]></dc:creator>
            <pubDate>Wed, 03 Jan 2024 17:03:04 GMT</pubDate>
            <atom:updated>2024-03-03T15:47:24.397Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*76cTv2BaeV9QLX2sT0cNRA.png" /></figure><p>Apache Kafka is an event streaming platform that is utilized for collecting, processing, storing, and integrating data at scale. It serves various purposes, including distributed streaming, stream processing, data integration, and pub/sub messaging.</p><h3>Why Kafka? Benefits and Use Cases</h3><p>In the realm of real-time data transfer, Apache Kafka has earned its stripes as a frontrunner, boasting an extraordinary 2ms latency that sets it apart from its peers.</p><p>Kafka is used by over 100,000 organizations across the world and is backed by a thriving community of professional developers, who are constantly advancing the state of the art in stream processing together. Due to Kafka’s high throughput, fault tolerance, resilience, and scalability, there are numerous use cases across almost every industry — from banking and fraud detection, to transportation and IoT. We typically see Kafka used for purposes like those below.</p><h3>Basic Working</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CJ0BJ_1wwyhyYbXb.png" /></figure><p>As the image illustrates, Kafka serves as a data transfer tool, where data is fetched from a source known as a <strong>producer</strong> and pushed to a target resource referred to as <strong>consumers</strong>. <strong>In this process, the producer pushes data to Kafka, and the consumer pulls it.</strong></p><p>Instead of the source sending data to many destinations directly, they can send it once to Kafka. Subsequently, the destinations can come to Kafka to retrieve the data they require.</p><p>In a microservices architecture, if we have tightly coupled services, we can decouple them with the help of Kafka.</p><p>Kafka can also be used for ETL (Extract, Transform, Load), where data is transferred in the required format in real-time, facilitating efficient loading processes.</p><h3>Detailed Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*6EZYO38Ph0OsPFj3.png" /></figure><p>1. Message Broker:<br>Definition: A message broker is an intermediary software that facilitates communication between different systems by managing the routing, storing, and processing of messages.</p><p>2. Publish-Subscribe Model<br>Definition: A messaging pattern where message senders (publishers) distribute messages to a group of recipients (subscribers) without the need for direct communication between the two.</p><p>3. Topic:<br>Definition: In Kafka, a topic is a category or feed name to which messages are published. Producers publish messages to a specific topic, and consumers subscribe to topics to receive the messages.</p><p>4. Producer:<br>Definition: A producer in Kafka is a component that publishes messages to a Kafka topic.</p><p>5. Consumer:<br>Definition: A consumer in Kafka is a component that subscribes to one or more topics and processes the messages published to those topics.</p><p>6. Partition:<br>Definition: Kafka topics are divided into partitions to allow for parallel processing and scalability. Each partition is an ordered, immutable sequence of messages.</p><p>7. Broker:<br>Definition: A Kafka broker is a server that stores and manages the topic partitions. It receives messages from producers, assigns them to partitions, and serves them to consumers.</p><p>8. Offset:<br>Definition: An offset is a unique identifier assigned to each message within a partition. Consumers use offsets to keep track of which messages they have already consumed.</p><p>9. Consumer Group:<br>Definition: A consumer group is a group of consumers that jointly consume a set of topic partitions. Each partition within a group is consumed by only one consumer at a time.</p><p>10. Zookeeper:<br>Definition: Kafka traditionally uses Apache ZooKeeper for distributed coordination and management tasks, such as maintaining configuration information, electing leaders, and managing partition assignments.</p><p>11. Replication:<br>Definition: Kafka supports data replication to ensure fault tolerance. Each partition has one leader and multiple followers, with the followers replicating the data from the leader.</p><p>12. Log Compaction:<br>Definition: A feature in Kafka that ensures that the log retains only the latest update for each key in a topic, reducing storage requirements and facilitating efficient data retrieval.</p><p>13. Producer Acknowledgements:<br>Definition: Configurable options in Kafka producers that determine the level of acknowledgment expected from brokers after a message is sent, ensuring message durability.</p><p>14. Kafka Streams:<br>Definition: Kafka Streams is a library for building real-time, fault-tolerant, and scalable stream processing applications using Kafka.</p><h3>Kafka broker cluster</h3><p>In a Kafka broker cluster, a multi-broker architecture is employed to ensure high fault tolerance. The producer can determine the replicas for each message, distributing them across multiple brokers. The producer sends messages only to the leader broker, which is responsible for replication.</p><p>All brokers are connected with the assistance of Zookeeper, serving as a coordination and synchronization tool. If the leader broker becomes unavailable, a new leader is established to maintain continuous operations and data availability. This design enhances the resilience and reliability of the Kafka cluster.</p><h3>Kafka cluster also provides a number of features:</h3><p>➢Durability: Kafka stores datain a durable way, so it is not lost if there is a problem with one of the servers in the cluster.</p><p>➢High throughput:Kafka can process data at high throughput, which is important for real-time applications.</p><p>➢Low latency: Kafka can deliver data with low latency, which is important for applications that need to respond to events in real time.</p><p>➢Disaster recovery: Kafka clusters can be used to store data for disaster recovery purposes. This ensures that you can recover your data in the event of a hardware failure or other disaster.</p><p>➢Replication: Kafka replicates data across multiple brokers, so you can be sure that your data is always available, even if one broker fails.</p><p>● In Apache Kafka, the leader of a partition within a Kafka cluster is responsible for handling all read and write operations for that partition. Each partition in Kafka has one leader and multiple follower replicas.</p><p>● Kafka uses a replication mechanismto provide fault tolerance and data redundancy. The leader replica receives all write requests and appends them to the partition’s log. It then replicates these messages to the follower replicas, ensuring that the replicas have an identical copy of the data.</p><p>● ZooKeeper is a distributed coordination service that is used to manage Kafka clusters. It provides a way for Kafka brokers to communicate with each other and to keep track of the state of the cluster.</p><p>● ZooKeeper is a critical component of Kafka clusters. It is used for the following:</p><p>➢Leader election:ZooKeeper is used to elect the leader for each partition.</p><p>➢Replication: ZooKeeper is used to keep the data in Kafka topics in sync.</p><p>➢Topic creation: ZooKeeper is used to create new topics.</p><p>➢Topic deletion: ZooKeeper is used to delete topics.</p><p>➢Broker registration:When a new broker joins the cluster, it registers itself with ZooKeeper.</p><p>➢Broker deregistration:When a broker leaves the cluster, it deregisters itself with ZooKeeper.</p><p>● Kafdrop is a web-based UI (User Interface) for monitoring and managing Apache Kafka clusters. It provides a visual interface to explore Kafka topics, partitions, and consumer groups, allowing users to monitor real-time data flow, inspect messages, and manage Kafka resources.</p><p>●Configuring Kafka Cluster:We need the system first, then we can download and install the Kafka cluster. We have to launch the instances on top of the AWS cloud. We have to launch a total of 7 instances.</p><ol><li>3 instances for brokers</li><li>1 instance for zookeeper</li><li>1 instance for kafdrop</li><li>1 instance for producer</li><li>1 instance for consumer</li></ol><h3>Configuring the ZooKeeper on EC2</h3><p>Download the latest version of JDK or Java 11 on your server.</p><p># sudo su -root# yum install java-11-amazon-corretto</p><p>Check if Java is installed. Kafka requires Java to run. You can check if Java is installed by running the following command:# java -version</p><p>Download Kafka. You can download Kafka from the Apache Kafka website.# wget <a href="https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz">https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz</a></p><p>Extract the Kafka Package:# tar -xvzf kafka_2.13–3.4.0.tgz➢Now you can see the zookeeper command in the bin folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S5P-39Lmcr-DYESPfN6D6Q.png" /></figure><p>Start ZooKeeper: # ./bin/zookeeper-server-start.sh config/zookeeper.properties &amp;</p><p>Once Zookeeper is running, the port number is visible</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fg-UofbLxT4vTfbo1V0JCw.png" /></figure><p>IP of zookeeper</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h7HCyJKUkIoqNbRyAUfsyg.png" /></figure><h3>Commands to set broker on EC2</h3><p>➢Download the latest version of JDK or install Java 11 installed on the broker.<br># sudo su -root<br># yum install java-11-amazon-corretto</p><p>Check if Java is installed. Kafka requires Java to run. You can check if Java is installed by running the following command:<br># java -version</p><p>➢Download Kafka. You can download Kafka from the Apache Kafka website.<br># wget <a href="https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz">https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz</a></p><p>➢Extract the Kafka Package:<br># tar -xvzf kafka_2.13–3.4.0.tgz</p><p>➢Now you can see the kafka broker command in the bin folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-XxtWBbt8g5ev_lBbIC6RA.png" /></figure><p>➢To configure a Kafka broker with ZooKeeper, you need to modify the server.properties file of the Kafka broker<br>.➢Open the server.properties file in a text editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ehANsalIVTrL7GinlrlZNg.png" /></figure><p>➢broker.id: Specify a unique ID for the Kafka broker. Each broker in a Kafka cluster must have a unique ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pRvRvKhPv79y9lakd0WZhw.png" /></figure><p>➢zookeeper.connect: Set the connection string for the ZooKeeper. Provide a comma-separated list of ZooKeeper host:port pairs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xXg429XVOQ3YvhzTPNYfcA.png" /></figure><p>➢Start Kafka. To start Kafka, run the following command:<br># ./bin/kafka-server-start.sh config/server.properties</p><p>➢Now, if you go to the Zookeeper system and type the command below, you can see a list of brokers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rX318GxvyUWIpbROALzdZg.png" /></figure><h3>Configure Kafdrop via Docker</h3><p>➢Install docker on your Kafdrop machine<br># yum install docker -y<br>➢Start and enable docker service<br># systemctl enable docker — now3</p><p>➢Launch container in the background:<br># docker run -d — rm -p 9000:9000 \-e KAFKA_BROKERCONNECT=172.31.83.88:9092\-e JVM_OPTS=”-Xms32M -Xmx64M” \-e SERVER_SERVLET_CONTEXTPATH=”/” \obsidiandynamics/kafdrop</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MhYYDZz278pq483bhIOGwQ.png" /></figure><h3>Kafka Producer on EC2:</h3><p>➢Download the latest version of JDK or install Java 11 installed on your server.<br># sudo su -root<br># yum install java-11-amazon-corretto</p><p>➢Check if Java is installed. Kafka requires Java to run. You can check if Java is installed by running the following command:<br># java -version</p><p>➢Download Kafka.<br> You can download Kafka from the Apache Kafka website.<br># wget <a href="https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz">https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz</a></p><p>➢Extract the Kafka Package:<br># tar -xvzf kafka_2.13–3.4.0.tgz</p><p>➢To create a Kafka producer and start sending messages to a topic, use the following command:<br># ./bin/kafka-console-producer.sh — topic lw_sales_log — bootstrap-server 172.31.83.88:9092</p><p>Now after sending a message you can see that message in Kafdrop WebUI.</p><h3>Kafka Consumer on EC2:</h3><p>➢Download the latest version of JDK or install Java 11 installed on your server.<br># sudo su -root<br># yum install java-11-amazon-corretto</p><p>➢Check if Java is installed. Kafka requires Java to run. You can check if Java is installed by running the following command:<br># java -version</p><p>➢Download Kafka. <br>You can download Kafka from the Apache Kafka website.<br># wget <a href="https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz">https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz</a></p><p>➢Extract the Kafka Package:<br># tar -xvzf kafka_2.13–3.4.0.tgz</p><p>➢To create a Kafka consumer and start receiving messages from a topic, use the following command:<br># ./bin/kafka-console-consumer.sh — bootstrap-server localhost:9092 — topic &lt;topic-name&gt; — from-beginning</p><h3>Kafka Connect</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*73oiI6iRlPfP66TDdxJeOw.png" /></figure><p>If you have a large amount of data from producers that needs to be sent to Kafka, you can make use of connectors as intermediate code. Connectors in Kafka are plugins that allow you to integrate Kafka with external systems, databases, or data sources. They help facilitate the seamless transfer of data between Kafka topics and other systems.<br>For instance, Kafka Connect is a framework that enables the creation and deployment of connectors. By using pre-built or custom connectors, you can efficiently ingest or export data between Kafka and various data storage or processing systems, reducing the complexity of integration tasks. Connectors help streamline the flow of data into and out of Kafka, making it an essential component for building scalable and flexible data pipelines.</p><p><strong>In Kafka, there are both source connectors and sink connectors.</strong></p><ol><li>Source Connectors: These connectors enable the ingestion of data from external systems into Kafka topics. Producers send data to Kafka, and source connectors facilitate this process by pulling data from different sources and pushing it into Kafka topics.</li><li>Sink Connectors: On the other hand, sink connectors are used to export data from Kafka topics to external systems. Consumers can retrieve data from Kafka, and sink connectors help to push this data to various destinations or consumers outside of the Kafka ecosystem.</li></ol><p><strong>Kafka Connect can be run in both distributed mode and standalone mode, offering flexibility based on the requirements of your deployment:</strong></p><ol><li><strong>Standalone Mode</strong>: In standalone mode, Kafka Connect runs as a single process on a single machine. It’s suitable for simpler use cases and development scenarios. In this mode, you can deploy and manage connectors individually without the need for a distributed infrastructure.</li><li><strong>Distributed Mode:</strong> In distributed mode, Kafka Connect can be deployed across multiple machines, forming a scalable and fault-tolerant infrastructure. Distributed mode is designed for handling larger workloads and providing high availability. It uses a distributed configuration and coordination mechanism to manage connectors and their tasks across the cluster.</li></ol><p>For production, we mostly use distributed mode for high availability.</p><p><a href="https://www.confluent.io/hub/"><strong>https://www.confluent.io/hub/</strong></a><strong> is the redistributor of Kafka and has many pre-written connectors(intermediate code) and we can use them directly.</strong></p><h3><strong>Practical demo on kafka connect using file connector.</strong></h3><p>The Kafka Connect File Pulse Connector is a popular connector for integrating file-based sources with Kafka topics. It allows you to use files as a source for producing messages to Kafka topics. This connector is part of the Confluent Hub, and you can find more details, including documentation and configuration options, on the Confluent Hub website.</p><p><strong>Let&#39;s make use of docker to have our Kafka cluster.</strong></p><p>docker run -dit — rm — name mykafka -p 2181:2181 -p 3030:3030 -p 8081–8083:8081–8083 -p 9581–9585:9581–9585 -p 9092:9092 -e ADV_HOST=172.17.0.1 lensesio/fast-data-dev:latest</p><p>This command will launch a container that has every component of Kafka and also gives us webui.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xFSml2Mi-pabkmG3Z8ZCsw.png" /></figure><p>We can access web UI at 127.0.0.1:3030</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pURlRJSdTrVO1wT46BqEuw.png" /></figure><p><strong>Creation of topic:</strong></p><p>Login into the container using the command:<br>docker exec -it mykafka bash</p><p>Run command to create topic:<br>kafka-topics — create — topic myfiletopic — partitions 3 — replication-factor 1 — bootstrap-server 127.0.0.1:9092</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KghtHVMp7lShPZkwOeTkSw.png" /></figure><p><strong>Let&#39;s create a connector from GUI:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uCBClizPNL4VbhihSzTjeg.png" /></figure><p>the output of the new connector:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vP3y4Q084iJmdCV1IpdFmA.png" /></figure><p>Let&#39;s create a file myfile.txt and all the data should be mapped to the topic by the connector automatically</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*393bTtS8A-8bR4lCgbGSvw.png" /></figure><p>The final output of topic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gWRY7ZJBq18amiSuIuLVaw.png" /></figure><p>Kafka’s strength lies in its ability to provide real-time event streaming and seamless integration between various data sources and consumers. In the scenario described, using Kafka with a file connector allows you to achieve near real-time data streaming from a file to a Kafka topic.</p><p>As soon as new data is added or modified in the specified file or directory, the File Pulse Connector can detect these changes and instantly produce corresponding messages to the Kafka topic. This capability is crucial for scenarios where timely and accurate data propagation is essential, enabling downstream applications or consumers to react promptly to the latest changes in the data source.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10c32b4985a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Linux: CGroups, Valgrind, Tuna, systemctl, CPU affinity, taskset, and Slice.]]></title>
            <link>https://medium.com/@prithvilee22/mastering-linux-cgroups-valgrind-tuna-systemctl-cpu-affinity-taskset-and-slice-2374206b0d44?source=rss-12eba527366d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2374206b0d44</guid>
            <category><![CDATA[cgroup]]></category>
            <category><![CDATA[limiting-ram-and-cpu]]></category>
            <category><![CDATA[cpu-affinity]]></category>
            <category><![CDATA[advanced-linux-concepts]]></category>
            <dc:creator><![CDATA[Prithvi A Parit]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 15:18:21 GMT</pubDate>
            <atom:updated>2023-08-02T15:18:21.483Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-aBIMy0lf6TbOFHWFuP0-g.png" /></figure><h4>Basic commands</h4><pre>#free -m<br>command to see total ram, used ram and free ram.<br><br>#dmidecode --type memory<br>command to see physical ram details.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*BL76wNd9DTuFu_wl7GKzng.png" /></figure><h4>Valgrind</h4><p>Kernel has different responsibilities like CGroup, memory management, etc and for everything we have a program behind it.</p><p>When our code loads on RAM a new folder is created for it and it&#39;s called <strong>PID. </strong>All the PID’s are under<strong> /proc </strong>folder. We can go inside PID and get all the logs of the process and solve many errors like OOM()out of memory error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z8f26Tk4NJlkyo-FVtPwZw.png" /></figure><p>The space of a process on RAM is divided into 3 parts:</p><ul><li>code session.</li><li>stack memory.</li><li>heap memory.</li></ul><p>When the process gets completed it will stop and it doesn&#39;t exist anymore but the heap memory still exists.</p><p>Kernel gives heap memory, but even after process finishes, according to kernel the heap space is still reserved and this increases memory usage like anything.</p><p>This problem is called <strong>memory leakage </strong>and when we reboot server this heap memory becomes free.</p><p>To solve this we use the command <strong>valgrind.</strong></p><pre>#include &quot;iostream&quot;<br> using namespace std;<br><br> int main(){<br>         char *y = (char*) malloc(100);<br> }<br>This code we run which results in memory leak and we solve using valgrind.<br><br>#valgrind --leak-check=full --tool=memcheck ./mycmd<br>This checks if we have memor leak or not for the command we ran mycmd.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*pRi1rASdYlkiyEtMml4FKQ.png" /></figure><h4>CGroup and systemctl</h4><p>I have launched an httpd server and now we will give dedicated RAM, CPU, network, HD, etc</p><p>We can use CGroup only by <strong>unit file. </strong>Please go through my older blog where I have explained CGroup and unit file in detail<strong>.</strong></p><p>We can control and manage unit files using <strong>systemctl</strong> and behind systemctl we have <strong>systemd</strong> which do everything.</p><p>For httpd server <strong>httpd.service</strong> is the unit file and can follow these steps</p><pre>#cd /etc/systemd/system<br>Main folder of systemd which CGroup will look for.<br><br>#mkdir httpd.service.d<br>we create new foler for new unit file <br><br>#cd httpd.service.d/<br>#vim test.conf<br>[Service]<br>MemoryLimit=1G      -&gt; We say to give only 1Gib ram<br>CPUAffinity=1       -&gt; We say to particularly use cpu 1<br><br>#systemctl daemon-reload<br>reload the daemon<br><br>#systemctl restart httpd.service<br>reload the httpd service<br><br>#systemctl show httpd.service | grep Memory<br>we can see the memory limit is change to igib</pre><blockquote>CPUAffinity: We can have one or more CPU the process can use all cpu’s but we can restrict to use any one particular cpu</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*czWhhiB3UPcPWxBbtyhubg.png" /></figure><h4>Important CPU-related commands.</h4><pre>#dmidecode --string processor-frequency<br>to check clock speed<br><br>#lscpu -e<br>cpu information<br><br>#nproc<br>no. of cpu we have<br><br># ps -o pid,stat,comm,rss -C httpd --sort=rss<br>to sort processes in order.</pre><h3>Tuna</h3><pre># tuna -t httpd -P<br>To check CPUAffinity by httpd process i.e., to find if httpd using howmany cpu.</pre><h4><strong>date command</strong></h4><p>A few commands run quickly and stop. Therefore we set limits at time of execution only.</p><pre><br>[root@ip-172-31-38-127 ~]# systemd-run -p  MemoryLimit=1G -p CPUAffinity=1 date<br>Running as unit: run-r5576a888dcee4a5694c91d613aaabcdd.service<br><br>[root@ip-172-31-38-127 ~]# journalctl -u run-r5576a888dcee4a5694c91d613aaabcdd.service<br>May 22 13:31:53 ip-172-31-38-127.ap-south-1.compute.internal systemd[1]: Started run-r5576a888dcee4a5694c91d613aaabcdd.service - /usr/bin/date.<br>May 22 13:31:53 ip-172-31-38-127.ap-south-1.compute.internal date[34023]: Mon May 22 13:31:53 UTC 2023<br>May 22 13:31:53 ip-172-31-38-127.ap-south-1.compute.internal systemd[1]: run-r5576a888dcee4a5694c91d613aaabcdd.service: Deactivated successfully.</pre><h4>Locate</h4><p>Command to locate any files. We have to create a database for locate command for that we use updatedb.</p><pre>[root@ip-172-31-38-127 ~]# updatedb<br>[root@ip-172-31-38-127 ~]# locate -n 2 *.png<br>/usr/lib/python3.9/site-packages/sepolicy/help/booleans.png<br>/usr/lib/python3.9/site-packages/sepolicy/help/booleans_more.png</pre><h4>Taskset</h4><p>This is the command used to find affinity and change affinity of a process. On fly we can switch in between CPU. This method is temporary and we use unit file to make permanent.</p><blockquote>Affinity: The process is being allotted by a CPU.</blockquote><pre>[root@ip-172-31-38-127 ~]# taskset -p -c 30120<br>pid 30120&#39;s current affinity list: 0,1<br><br>[root@ip-172-31-38-127 ~]# taskset -p -c 0,1 30120<br>pid 30120&#39;s current affinity list: 0,1<br>pid 30120&#39;s new affinity list: 0,1<br><br>[root@ip-172-31-38-127 ~]# taskset -c 1 date<br>Mon May 22 13:56:45 UTC 2023<br>[root@ip-172-31-38-127 ~]# </pre><blockquote>echo 3 &gt; /proc/sys/vm/drop_caches<br>command to remove caches from ram</blockquote><h4>Kernel</h4><pre>Kernel is just a software<br>[root@ip-172-31-38-127 ~]# rpm -q kernel<br>kernel-6.1.25-37.47.amzn2023.x86_64<br><br>kernel version<br>[root@ip-172-31-38-127 ~]# uname -r <br>6.1.25-37.47.amzn2023.x86_64<br><br>place where kerel maintains all information<br>[root@ip-172-31-38-127 ~]# cd /sys/devices<br>[root@ip-172-31-38-127 devices]# ls<br>LNXSYSTM:00  breakpoint  kprobe  msr  pci0000:00  platform  pnp0  software  system  tracepoint  uprobe  vbd-51712  vif-0  virtual<br><br>all cpu info kernel maintains here.<br>[root@ip-172-31-38-127 devices]# cat /proc/cpuinfo | grep processor<br>processor       : 0<br>processor       : 1</pre><h4>Slice</h4><p>The entire physical resources is divided into 2 parts. One part is given to <strong>user</strong> and other part for <strong>systemd</strong>. This division is called slice.</p><pre>[root@ip-172-31-38-127 ~]# systemctl  -t slice<br>  UNIT                                     LOAD   ACTIVE SUB    DESCRIPTION<br>  -.slice                                  loaded active active Root Slice<br>  system-getty.slice                       loaded active active Slice /system/getty<br>  system-modprobe.slice                    loaded active active Slice /system/modprobe<br>  system-policy\x2droutes.slice            loaded active active Slice /system/policy-routes<br>  system-refresh\x2dpolicy\x2droutes.slice loaded active active Slice /system/refresh-policy-routes<br>  system-serial\x2dgetty.slice             loaded active active Slice /system/serial-getty<br>  system-sshd\x2dkeygen.slice              loaded active active Slice /system/sshd-keygen<br>  system.slice                             loaded active active System Slice<br>  user-1000.slice                          loaded active active User Slice of UID 1000<br>  user.slice                               loaded active active User and Session Slice<br><br>LOAD   = Reflects whether the unit definition was properly loaded.<br>ACTIVE = The high-level unit activation state, i.e. generalization of SUB.<br>SUB    = The low-level unit activation state, values depend on unit type.<br>10 loaded units listed. Pass --all to see loaded but inactive units, too.<br>To show all installed unit files use &#39;systemctl list-unit-files&#39;.</pre><p>Further resources gets divided under systemd user.</p><p><strong>systemctl -t slice </strong>command give live status of all slice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Zf_R4V_AEYXnLYLigEQGw.png" /></figure><p>Suppose we have only one CPU and 2 process needs 100% CPU, CPU at a time can execute only one instruction. Here CPU gives equal time for both process by using <strong>FIFO(first come first server)</strong> method. This is called <strong>CFS(Completely Fair Scheduler).</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2374206b0d44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Linux: CGroups, NetCat, Systemcall, and Terminal Multiplexer.]]></title>
            <link>https://medium.com/fasal-engineering/mastering-linux-cgroups-netcat-systemcall-and-terminal-multiplexer-1b1df46faa84?source=rss-12eba527366d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b1df46faa84</guid>
            <category><![CDATA[linux-kernel]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[linux-tutorial]]></category>
            <dc:creator><![CDATA[Prithvi A Parit]]></dc:creator>
            <pubDate>Thu, 25 May 2023 04:58:14 GMT</pubDate>
            <atom:updated>2023-05-25T04:58:14.245Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*E1ytwzFIwc9H1UvOu-APaQ.png" /></figure><h4>Basic information</h4><p>We all know the CPU executes all the instructions only when our code loads on top of RAM. The kernel is the one which loads our code on top of RAM. <strong>By default, Kernel gives all the RAM, CPU, network speed, and storage if a process asks.</strong> We will learn how to limit these resources.</p><blockquote>When program loads on top of RAM its called process.</blockquote><h4>Session</h4><p>Each time we log in to our server from the same account or a different account a new session is created. we can use loginctl command to check all the sessions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*3fI9xzWSMXRaV53ef_rkHw.png" /></figure><h4>Limiting the number of tasks/processes and RAM for each session.</h4><p><strong>CGroup: Control group is the capability of Linux that we can use to set limits for resources.</strong></p><p>CGroup can be applied for each user also.</p><p><strong>Scope</strong>: Each session has a Scope associated with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*ivCuNZGWNb06bkI_efdOpw.png" /></figure><blockquote>We can set constraints directly on users also but now we do on session.</blockquote><p><strong>#loginctl user-status ec2-user</strong> command can be used to see all sessions of a user and process under each session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*BTmN_xSlLHt_EFeAqBOkKg.png" /></figure><blockquote>We can also limit total sessions a user can create by editing a file /etc/systemd/login.conf</blockquote><p><strong>Unit file: CGroup every time looks for this file, so we have to edit this file and set limits. We perform this using systemctl command</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*apmet2SHgFjy5_q8s49Y7A.png" /></figure><p><strong>systemctl edit session-18.scope this command we use to edit the unit file. We run systemctl edit session-18.scope and write these 3 lines.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*nE3QMWgQkAgwJR6ijthlCQ.png" /></figure><p>Here we have proof as we have set the limit to only 8 processes as we run a few extra processes it fails.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lad2r9-5sAcROXctcs4bLQ.png" /></figure><p><strong>Slice:</strong> if we have 7 tasks running and the limit is 8 then we say 7 slices. Slices provide a flexible way to manage and allocate system resources in a hierarchical manner, allowing administrators to prioritize and control the resource allocation for different types of processes or groups of processes within a Linux system.</p><blockquote>Docker internally uses CGroups.</blockquote><p>Difference between Slice and Scope.</p><p>In summary, while both scope and slice provide mechanisms for grouping and managing processes within the cgroup hierarchy, the scope is primarily used for managing resources within a specific context (such as systemd units), while slice is used for hierarchical resource allocation and management across the system</p><h4><strong>user-1000.slice:</strong></h4><p><strong>T</strong>his we edit directly which applies to all users and sessions.</p><p>systemctl edit user-1000.slice — force this command we run first and this 3 lines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*jhAogRIQ0dkTUSqV0lM0sw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*NjZy3mgp2y5gH_xjAfB0Jw.png" /></figure><p>We can also edit in other ways:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*4AL7779eYPyoTfy9Y1hDTg.png" /></figure><p>#systemctl daemon-reload<br>we must run this after running the above command.</p><pre>Some important commands<br>#journalctl -u session-18.scope<br>every record of all users and sessions.<br><br>#loginctl session-status<br>complete info of present session.<br><br>#systemctl show  user-1000.slice -p MemoryCurrent<br>Command to see memory used by present user<br><br>#systemctl set-property user-1000.slice MemoryLimit=10G<br>edit user-1000.slice directly<br><br>#systemctl daemon-reload<br>we must run this after running above command.<br><br>#last<br>Which user loged in.<br><br>#lastb<br>All people trying to attack.</pre><h4>tlog</h4><p>This command records whatever we perform in cli and we can play it later.</p><pre>#tlog-rec --file-path=mylog<br>#tlog-play --file-path=my.log<br>#exit </pre><p><strong>ps -aux</strong></p><p>Command to see all processes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*0mEZGpfDDPn11APhR-LltA.png" /></figure><p><strong>top</strong></p><p>Command to live tracking processes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*ea-KItQ3LH3jMsoOZyUk4g.png" /></figure><h4><strong>Terminal Multiplexer(tmux)</strong></h4><p>This we can use to have multiple windows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*YmYWodb-HtUoHCPuoPz4gQ.png" /></figure><p>We can use:</p><ul><li>ctrl+b and arrow marks to switch.</li><li>ctrl+b and “ for a new division.</li><li>ctrl+b and d to detach.</li></ul><h4>Systemcall/syscall</h4><p>Every command we run goes to the kernel as instructions, this is called <strong>syscall</strong>. Whatever happens in the kernel we say <strong>kernel space/system space</strong>.</p><p><strong>Context Switching: </strong>Kernel uses syscall to do its work. <strong>Strace</strong> is the command to check this.</p><p>#strace -c cat /etc/passwd. This command we run to see all context switching.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*Qck3KVVOXxfpmNTynQA6jQ.png" /></figure><p><strong>Auditing: </strong>We can audit syscall and try to optimize things.</p><p>/var/log/audit This folder has all the logs of syscalls.</p><p>we use <strong>auditctl</strong> command to fetch all syscall logs respective to /etc/passwd.</p><p># auditctl -w /etc/passwd -p rwa -k mynewkey<br> # ausearch -k mynewkey<br> # tail -f /var/log/audit/audit.log</p><p><strong># auditctl -a always,exit -F arch=b64 -S write -S bind -k mync</strong></p><p>anyone creates write, bind syscall then we capture that. Detailed information <a href="https://www.kernel.org/doc/html/v4.19/userspace-api/seccomp_filter.html">https://www.kernel.org/doc/html/v4.19/userspace-api/seccomp_filter.html</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5z0q6hFPN3misHczhhB7oA.png" /></figure><h4>Netcat(nc)</h4><p>This is used to send and receive messages from other servers by exposing a port number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cETvABWcxQEjHvWAIi_GaQ.png" /></figure><p>The left side terminal is an ec2 instance we make it a server. The right side terminal is the base os we connect to the server. After connection, we can send and receive messages.</p><p>#nc — exec /bin/bash — keep-open -l 1234</p><p>This is a very dangerous command by this client can connect and run commands on the server and see the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GhicjETd2bXlCw1-tpb4IQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b1df46faa84" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fasal-engineering/mastering-linux-cgroups-netcat-systemcall-and-terminal-multiplexer-1b1df46faa84">Mastering Linux: CGroups, NetCat, Systemcall, and Terminal Multiplexer.</a> was originally published in <a href="https://medium.com/fasal-engineering">Fasal Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mojo]]></title>
            <link>https://medium.com/@prithvilee22/mojo-97a6d983a751?source=rss-12eba527366d------2</link>
            <guid isPermaLink="false">https://medium.com/p/97a6d983a751</guid>
            <dc:creator><![CDATA[Prithvi A Parit]]></dc:creator>
            <pubDate>Sat, 20 May 2023 17:08:41 GMT</pubDate>
            <atom:updated>2023-05-21T07:20:26.153Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*TaQ8kHvC6gyHAIYqfUQOoA.png" /></figure><ul><li>35,000 times faster than Pyton.</li><li>3 times faster than TensorFlow.</li><li>2 times faster than Pytorch.</li><li>Faster than c/c++.</li></ul><p>Fastest AI engine by <a href="https://www.modular.com/">Modular</a>. The primary goal is to create the fastest, most secure, and simple programming code for AI/ML.</p><h4>Yes, Mojo is a new programming language by Modular.</h4><h4>🔴Best thing is syntax is precisely the same as Python. But the underline engine is entirely different</h4><p><strong>A Mojo code compared to Python code</strong></p><ul><li>2 times faster on an Intel processor.</li><li>3 times faster on an AMD processor.</li><li>4 times faster on a Graviton processor.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*PH8Di6uMlcLuNtLQNavLtw.png" /></figure><h3>How Mojo is so fast?</h3><h4>Mojo is built from scratch.</h4><h4>Compute fragmentation / Floating point precision.</h4><ul><li>CPU going to ram and taking data is called <strong>memory wall/memory latency.</strong></li><li>This is a bottleneck and we have to solve memory latency.</li><li><strong>Floating point precision: </strong>Let&#39;s say we are storing 60000000, 700, and 1000 on top of RAM so we convert them into 60 * 10⁶, 70*10¹, and 10*10², now we store these on RAM this is called floating point precision.</li><li>Python uses 64bit floating point precision and c/c++ uses 32bit floating point precision.</li><li><strong>Data from memory gets stored on the local registry of CPU, more data in the local registry faster CPU processing, and the smaller the floating point precision size more data gets stored on the local registry of the CPU</strong>.</li><li><strong>Yes, Mojo supports 16-bit</strong> <strong>floating point precision size.</strong></li><li>The best way to measure CPU speed is FLOPS-floating point operations per second.</li></ul><h4>Data type.</h4><ul><li>We don&#39;t define data type in Python and Python uses its intelligence to find data type which is time-consuming. So we can define data type in Mojo.</li><li>We cant make variables immutable in python but in python, we can.</li></ul><h4>LLVM (Low Level Virtual Machine)</h4><ul><li>LLVM is a collection of modular and reusable compiler and toolchain technologies.</li><li>Compiler converts every programming code into LLVM code before then CPU executes it.</li><li>Compiler takes time in this process.</li><li><strong>To solve this Mojo is built in such a way there is no time wasted in compiling to LLVM, Mojo engine directly works on LLVM i.e., Mojo engine converts code directly into LLVM code.</strong></li></ul><h4>Matrix Multiplication.</h4><ul><li>50–60% of the time in a Neural Network program is taken for Matrix Multiplication.</li><li>Time complexity is O(n³).</li><li><strong>Mojo solved this by SIMD(Single instruction multiple data) and its possible because 16-bit floating point.</strong></li><li>Concurrency and parallelism are supported by Mojo which is a must for matrix multiplication.</li></ul><p>Class is not present in Mojo because it works on <strong>runtime</strong> <strong>polymorphism /dynamic dispatch</strong> which is time consuming , we have <strong>struct</strong> to perform OOPS concept in Mojo which is exactly same as class .</p><p><strong>fn </strong>can be used as same as def to increase speed.</p><p>All these together make Mojo Super Fast.</p><p>Mojo is still in the development phase so it&#39;s not publicly released to Download.</p><p>We can use Mojo Playground at <a href="https://www.modular.com/">https://www.modular.com</a>/ we get console and Jupyter Notebook.</p><p>var x: F16 = 18.</p><p>This is the syntax to define floating data type and 16bit Floating point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XCVdqxLb6tj8u2TfLWxOhw.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F-3Kf2ZZU-dg%3Fstart%3D2%26feature%3Doembed%26start%3D2&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D-3Kf2ZZU-dg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-3Kf2ZZU-dg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4db80612c508d2351b7dfb23338dc80a/href">https://medium.com/media/4db80612c508d2351b7dfb23338dc80a/href</a></iframe><p>Try watching at least the first 8 minutes of this video.</p><p><strong>Chris Lattner </strong>creator<strong> </strong>of Swift, LLVM, PyTorch, TensorFlow is the man behind <strong>Mojo</strong>.</p><p>Big hats off to <strong>Chris Lattner</strong>👏.</p><p>Tried explaining as much as possible.</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97a6d983a751" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Developer’s Guide to Terraform]]></title>
            <link>https://medium.com/fasal-engineering/a-developers-guide-to-terraform-3db29ed261a8?source=rss-12eba527366d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3db29ed261a8</guid>
            <category><![CDATA[terraform-best-practices]]></category>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[iac]]></category>
            <dc:creator><![CDATA[Prithvi A Parit]]></dc:creator>
            <pubDate>Fri, 10 Feb 2023 06:35:05 GMT</pubDate>
            <atom:updated>2023-02-10T07:48:04.412Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*sAADfSkJvsVfMeY_B-ny1Q.png" /></figure><h3><strong>What is Terraform?</strong></h3><p>Terraform is <strong>an infrastructure as code(IaC) open-source software tool that enables you to safely and predictably change, create, and improve infrastructure</strong>. By IaC we can automate every service we deploy on multiple providers.</p><h3>Why do we need Terraform?</h3><p>Terraform <strong>lets you use the same workflow to manage multiple providers and handle cross-cloud dependencies</strong>. This simplifies management and orchestration for large-scale, multi-cloud infrastructures.</p><h3>Why do we need a multi or hybrid cloud?</h3><p>Multi-cloud is the combination of two or more public cloud providers which we use to deploy our services and hybrid cloud stands for private cloud and public cloud combination, these are nothing but the strategy where an organization leverages two or more cloud computing platforms <strong>to perform various tasks</strong>. The organization wants to compare the services given by each provider with a perspective (e.g. price) and wants to use the best.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VgOOBynUXOVV10KwknmLrA.png" /></figure><h3>How to start with Terraform?</h3><p><a href="https://developer.hashicorp.com/terraform/downloads"><strong>Install Terraform</strong></a> on Mac, Linux, or Windows by downloading the binary or using a package manager. Then we need to start coding with HashiCorp Configuration Language (HCL) which is a <strong>unique configuration language</strong>. It was designed to be used with HashiCorp tools, notably Terraform, but HCL has expanded as a more general configuration language and it is visually similar to JSON.</p><p><em>In this blog, I will be using AWS as my cloud provider to explain various syntax, and the syntax and method of writing the code remain the same for any provider.</em></p><blockquote>Terraform has 2805 providers till date among them AWS, GCP, Azure, Kubernetes, Alibaba cloud, Oracle cloud are mainly used ones.</blockquote><p>Once you have installed Terraform let’s learn some main components of Terraform which can help us get more familiar with the tool.</p><h3>Providers</h3><p>Provider plugins like the <a href="https://registry.terraform.io/providers/hashicorp/aws/latest">AWS provider</a> act as a translation layer that allows Terraform to communicate with many different cloud providers, databases, and services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JuXl5I4VXjVJnO1a" /></figure><p>Terraform uses providers to provision <a href="https://developer.hashicorp.com/terraform/language/resources">resources</a>, mentioning providers is the basic first requirement to run any IaC code and the following is an example.</p><p>The following block of code means we want to use AWS to launch our infrastructure. “~&gt;” means any version after 4.16.</p><pre>terraform {<br>  required_providers {<br>    mycloud_aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 4.16&quot;<br>    }<br>  }<br>}</pre><h4>Configure the AWS Provider</h4><p>The next step is to authenticate to AWS and we do this with help of an access key and a secret key.</p><pre>provider &quot;mycloud_aws&quot; {<br>  region = &quot;us-east-1&quot;<br>  access_key = &quot;my-access-key&quot;<br>  secret_key = &quot;my-secret-key&quot;<br>}</pre><p><em>Warning: Hard-coded credentials are not recommended in any Terraform configuration and risk secret leakage should this file ever be committed to a public version control system.</em></p><p>We can use <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs#shared_config_files"><em>terraform recommended methods</em></a> as best practices or we can make use of <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html">AWS CLI</a> and give the configured name.</p><pre>//AWS cli configured <br>provider &quot;mycloud_aws&quot; {<br>  region = &quot;us-east-1&quot;<br>  profile= &quot;default&quot; //this is by default<br>}</pre><h3>Resources</h3><p><em>Resources</em> are a very important element in the Terraform language. Each resource block describes one or more infrastructure objects we desire to configure, such as virtual networks, compute instances, container services, and much more.</p><p>Syntax: <strong><em>block name “resource type” “resource name”</em></strong></p><p>Following is an example to launch an EC2 instance, the resource we used here is aws_instance. We use Terraform argument reference to give our requirements to launch resources.</p><pre>resource &quot;aws_instance&quot; &quot;foo&quot; {<br>  ami           = &quot;ami-005e54dee72cc1d00&quot; # us-west-2<br>  instance_type = &quot;t2.micro&quot;<br><br>  tags = {<br>    Name = &quot;HelloWorld&quot;<br>  }<br>}</pre><h3>Argument Reference</h3><p>Inside each resource block, we have to mention the resource respective argument that Terraform has and give the key values according to our requirement. This is mainly to configure Terraform resources.</p><blockquote>Search technique: In the doc we always search with the resource name in the search option at the left of the screen and under the resource(aws_instance) we have Resources, we click on this and at the right we have Argument Reference and examples.</blockquote><h3>Provisioners</h3><p>Provisioners can be used to execute specific actions on the local machine or on a remote machine in order to prepare servers or other infrastructure objects for service.</p><p>When we deploy virtual machines or other similar computing resources, we often need to pass in data about other related infrastructure that the software on that server will need to do its job and this can be done using provisioners.</p><p><strong>How to use Provisioners</strong></p><pre>resource &quot;aws_instance&quot; &quot;web&quot; {<br>  # ...<br><br>  # Establishes connection to be used by all<br>  # generic remote provisioners (i.e. file/remote-exec)<br>  connection {<br>    type     = &quot;ssh&quot;<br>    user     = &quot;root&quot;<br>    password = var.root_password<br>    host     = self.public_ip<br>  }<br><br>  provisioner &quot;remote-exec&quot; {<br>    inline = [<br>      &quot;puppet apply&quot;,<br>      &quot;consul join ${aws_instance.web.private_ip}&quot;,<br>    ]<br>  }<br>}</pre><p><strong>remote-exec: </strong>This provisioner invokes a script on a remote resource after it is created. This can be used to run a configuration management tool, bootstrap into a cluster, etc.</p><p>Similarly to invoke a local process, we can use <strong>local-exec</strong> provisioner instead. The remote-exec provisioner requires a connection and supports both ssh and WinRM.</p><h3>Connection Block</h3><p>We can create one or more connection blocks that can connect and access the remote resource. Connection blocks don’t take a block label and can be nested within either a resource or a provisioner. (Refer to the above code.)</p><blockquote>We can give the file names as our wish but extension should be .tf and terraform is intelligent to find what is the order of the code.</blockquote><h3><strong>Variables</strong></h3><p>We have 3 types:</p><ol><li><strong>Input Variables</strong></li></ol><p>It’s just like user-defined variables. Input variables will let us customize aspects of Terraform modules without altering the module’s own source code. This helps us to share modules across different Terraform configurations, making the module composable and reusable.</p><p><strong>Declaring an Input Variable</strong></p><pre>variable &quot;image_id&quot; {<br>  type = string<br>}<br><br>variable &quot;availability_zone_names&quot; {<br>  type    = list(string)<br>  default = [&quot;us-west-1a&quot;]<br>}<br><br>variable &quot;docker_ports&quot; {<br>  type = list(object({<br>    internal = number<br>    external = number<br>    protocol = string<br>  }))<br>  default = [<br>    {<br>      internal = 8300<br>      external = 8300<br>      protocol = &quot;tcp&quot;<br>    }<br>  ]<br>}</pre><p>Type here means data type and default stands for the default value.</p><p>2. <strong>Attribute references</strong></p><p>These can be the information related to the infrastructure we are configuring which we can obtain only after our code is applied, but here we may have to use those information elsewhere and we can use it as attribute references.</p><p>Few examples:</p><ul><li>The ami argument set in the configuration can be used elsewhere with the reference expression aws_instance.example.ami.</li><li>The id attribute exported by this resource type can be read using the same syntax, giving aws_instance.example.id.</li></ul><p><strong>Syntax: value = &lt;resource type&gt;.&lt;resource name&gt;.&lt;attribute reference&gt;</strong></p><pre>output &quot;o1&quot;{<br>value=aws_instance.os1.public_ip<br>}</pre><blockquote>Search technique: In the doc we always search with the resource name in the search option at the left of the screen and under the resource(aws_instance) we have Resources, we click on this and at the right we have Attribute Reference and examples.</blockquote><p>3. <strong>Filesystem and Workspace Info</strong></p><p>Following we have: path.module, path.root, path.cwd, terraform.workspace</p><pre>module &quot;example&quot; {<br>  # ...<br><br>  name_prefix = &quot;app-${terraform.workspace}&quot;<br>}</pre><h3>null_resource</h3><p>This resource implements the standard resource lifecycle but takes no further action. The code written outside any resource may not rerun every time so those can be placed inside null_resource.</p><p>Provisioner and connection can be well executed inside null_resource.</p><p><strong>Triggers</strong>: This is a block we can use to trigger the null_resource i.e., each time its values change then the null_resource will run.</p><pre>resource &quot;aws_instance&quot; &quot;cluster&quot; {<br>  count = 3<br><br>  # ...<br>}<br><br>resource &quot;null_resource&quot; &quot;cluster&quot; {<br>  # Changes to any instance of the cluster requires re-provisioning<br>  triggers = {<br>    cluster_instance_ids = join(&quot;,&quot;, aws_instance.cluster.*.id)<br>  }<br><br>  # Bootstrap script can run on any instance of the cluster<br>  # So we just choose the first in this case<br>  connection {<br>    host = element(aws_instance.cluster.*.public_ip, 0)<br>  }<br><br>  provisioner &quot;remote-exec&quot; {<br>    # Bootstrap script called with private_ip of each node in the cluster<br>    inline = [<br>      &quot;bootstrap-cluster.sh ${join(&quot; &quot;,<br>      aws_instance.cluster.*.private_ip)}&quot;,<br>    ]<br>  }<br>}</pre><h3>Functions</h3><h3>The Meta-Argument</h3><p>These are some special constructs in Terraform that can be used in modules or resource blocks.</p><ol><li><strong>The depends-on Meta-Argument: </strong>This is used to<strong> </strong>handle hidden resource or module dependencies that Terraform cannot automatically infer.</li><li><strong>The count Meta-Argument: </strong>By default, a resource block configures one real infrastructure object, to configure more than one we can use count.</li><li><strong>The for_each Meta-Argument: </strong>If a resource or module block includes a for_each argument whose value is a map or a set of strings, Terraform creates one instance for each member of that map or set.</li><li><strong>The provider Meta-Argument: </strong>The provider meta-argument specifies which provider configuration to use for a resource, overriding Terraform&#39;s default behavior of selecting one based on the resource type name.</li><li><strong>The lifecycle Meta-Argument: </strong>The Resource Behavior page will give us the general lifecycle for resources. Some details of that behavior can be customized using the special nested lifecycle block within a resource block body. We have the following arguments: <strong>create_before_destroy, prevent_destroy, ignore_changes, and replace_triggered_by.</strong></li></ol><h3>Failure Behaviour</h3><p>By default, provisioners that fail make Terraform apply itself to fail. The on_failure setting can be used to change this. The values used are:</p><p><strong>continue</strong>: Ignore the error and continue applying the code.</p><p><strong>fail:</strong> Raise the error and stop execution.</p><h3>Output Values</h3><p>Output values make information about the infrastructure available on the command line, and can expose information for other Terraform configurations to use. Output values are similar to return values in programming languages.</p><p><strong>Declaring an Output Value</strong></p><pre>output &quot;instance_ip_addr&quot; {<br>  value = aws_instance.server.private_ip<br>}</pre><h3>State</h3><p>Terraform will have the complete information of its target infrastructure and its called state. This state is used by Terraform to map real-world resources to the configuration, keep track of metadata, and improve performance for large infrastructures.</p><p>This state is stored by default in a local file named “terraform.tfstate” and this file is called the current state, but it can also be stored remotely, which works better in a team environment.</p><p>The code we have written to configure is nothing but the desired state.</p><p>Terraform will compare both the current state and desired state and take a decision on what changes have to be made and display for us in the plan.</p><h3>Data Types and Values</h3><p><strong>Data types: string, number, bool, list, map</strong></p><h3>Module Blocks</h3><p>A <em>module</em> is a container for multiple resources that are used together. It’s the best way to reuse the code in multiple projects. We write the code and store it in a folder and use it in every other code we need.</p><p>A module can call other modules, which lets you include the child module’s resources in the configuration in a concise way.</p><pre>module &quot;servers&quot; {<br>  source = &quot;./app-cluster&quot;<br><br>  servers = 5<br>}</pre><h3>Exporting</h3><p>To use the output block inside our module block we have to write a new output block with a different syntax.</p><p><strong>syntax: value= module.&lt;module name&gt;.&lt;output block name in real code&gt;</strong></p><h3>Data Sources</h3><p>For Terraform AWS is the source and Terraform will retrieve all information of the source its called Data Source. This information is used before applying the code.</p><p>This information we can use to further automation, we write a separate block called data and retrieve this information by applying filters. We can also use custom condition checks and regex can be used.</p><pre>data &quot;aws_ami&quot; &quot;example&quot; {<br>  most_recent = true<br><br>  owners = [&quot;self&quot;]<br>  tags = {<br>    Name   = &quot;app-server&quot;<br>    Tested = &quot;true&quot;<br>  }<br>}</pre><blockquote>Data Source: Info before deploying resources.</blockquote><blockquote>Attribute Reference: Info before deploying resources.</blockquote><h3>Conditional Expressions</h3><p>It’s just like the ternary operator which uses the value of a boolean expression to select one of two values.</p><p><strong>Syntax:</strong> condition ? true_val : false_val</p><p><strong>Example:</strong> var.a != “” ? var.a : “default-a”</p><h3>Built-in Functions</h3><p>The Terraform language includes a number of built-in functions that can be used within expressions to transform and combine values. The general syntax for function calls is a function name followed by comma-separated arguments in parentheses: <strong>max(5, 12, 9) </strong>gives the highest valued number as output. Like this, we have lots of functions that can be found <a href="https://developer.hashicorp.com/terraform/language/functions"><strong>here.</strong></a></p><h3>Local Values</h3><p>It’s just like variables but we can define multiple values within the same value.</p><p><strong>Declaring local values.</strong></p><pre>locals {<br>  service_name = &quot;forum&quot;<br>  owner        = &quot;Community Team&quot;<br>}</pre><p><strong>Using local values.</strong></p><pre>resource &quot;aws_instance&quot; &quot;example&quot; {<br>  # ...<br><br>  tags = local.common_tags<br>}</pre><blockquote>Variables wont support function but local values does.</blockquote><blockquote>In modules we cant change local values value but in variables we can.</blockquote><h3>Element Function</h3><p>It gets a single element from the list. <strong>Syntax: element(list, index)</strong></p><p><strong>Example:</strong></p><pre>&gt; element([&quot;a&quot;, &quot;b&quot;, &quot;c&quot;], 1)<br>b<br><br><br>&gt; element([&quot;a&quot;, &quot;b&quot;, &quot;c&quot;], 3)<br>a</pre><h3><strong>Taint</strong></h3><p>When we re-apply the code we want some resources to get deployed from scratch that&#39;s why we tell Terraform to destroy that resource and create it again.</p><p>eg: terraform taint aws_instance.os4</p><h3>Target</h3><p>When we re-apply the code we want only specific resources to get deployed.</p><p>eg: terraform apply -target=aws_instance.os4</p><h3>Debugging Terraform</h3><p>Terraform has detailed logs that can be used by setting the TF_LOG environment variable to any value. Enabling this setting causes detailed logs to appear on the output.</p><p>TF_LOG can be set to one of the log levels INFO, ERROR, WARN, DEBUG, or TRACE.</p><h3>for Expressions</h3><p>A for <em>expression</em> creates a complex type value by transforming another complex type value. We can use it just like for the loop we have in programming.</p><p>Syntax: <strong>[for s in var.list : upper(s)]</strong></p><p>Eg: <strong>{for s in var.list : s =&gt; upper(s)}</strong></p><p>output: {<br> foo = “FOO”<br> bar = “BAR”<br> baz = “BAZ”<br>}</p><h3><strong>Dynamic blocks</strong></h3><p>This can be used within blocks like resources. It can usually be used only when assigning a value to an argument using the name=expression form. It’s more like for expression but gives nested blocks for each element of that complex value.</p><pre>resource &quot;aws_elastic_beanstalk_environment&quot; &quot;tfenvtest&quot; {<br>  name                = &quot;tf-test-name&quot;<br>  application         = &quot;${aws_elastic_beanstalk_application.tftest.name}&quot;<br>  solution_stack_name = &quot;64bit Amazon Linux 2018.03 v2.11.4 running Go 1.12.6&quot;<br><br>  dynamic &quot;setting&quot; {<br>    for_each = var.settings<br>    content {<br>      namespace = setting.value[&quot;namespace&quot;]<br>      name = setting.value[&quot;name&quot;]<br>      value = setting.value[&quot;value&quot;]<br>    }<br>  }<br>}</pre><h3>State Locking</h3><p>When we are working in a team multiple times we make changes for the same code by different people, in this scenario there might be chances of applying the code in the same team and this leads to problems, to avoid this Terraform has a remote state locking mechanism and when one code is applied we cant apply same code from different repo or terminal. Terraform has .tfstate file to maintain the state, this locking is by default behavior and we can change it.</p><h3>Backend Configuration</h3><p>The backend is nothing but where Terraform stores its state file. When working in a team we make sure the state file is present in the cloud.</p><p><strong>Eg: S3. </strong>Stores the state as a given key in the bucket on Amazon S3. S3 alone won&#39;t support state locking and we can use DynamoDB for this.</p><pre>terraform {<br>  backend &quot;s3&quot; {<br>    bucket = &quot;mybucket&quot;<br>    key    = &quot;path/to/my/key&quot;<br>    region = &quot;us-east-1&quot;<br>  }<br>}</pre><h3>Terraform Cloud</h3><p>It’s a cloud platform given by <a href="https://www.hashicorp.com/">hashicorp</a> where multiple users can work together, and version update and bug update is done automatically. We can create policies with the help of <a href="https://docs.hashicorp.com/sentinel">sentinel</a>. We can also get the price estimation of our deployment. We get a graphical look and feel where we can give the variables, apply, destroy, etc can be done in a single click without giving commands. Click <a href="https://cloud.hashicorp.com/products/terraform">here</a> to know more.</p><h3>Splat Expressions</h3><p>Splat expression can be used to express a common operation which otherwise is performed using for expression.</p><p>The special [*] symbol iterates over all of the elements of the list given to its left and accesses from each one the attribute name given to its right.</p><p>Eg: <strong>var.list[*].id</strong>, this is equivalent to <strong>[for o in var.list : o.id]</strong></p><h3>alias: Multiple Provider Configurations</h3><p>We might have the requirement of having multiple regions in the same account, this we can have by alias.</p><pre># The default provider configuration; resources that begin with `aws_` will use<br># it as the default, and it can be referenced as `aws`.<br>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}<br><br># Additional provider configuration for west coast region; resources can<br># reference this as `aws.west`.<br>provider &quot;aws&quot; {<br>  alias  = &quot;west&quot;<br>  region = &quot;us-west-2&quot;<br>}</pre><h3>zipmap Function</h3><p>zipmap creates a map with help of two lists</p><p>syntax: <strong>zipmap(keyslist, valueslist)</strong></p><pre>&gt; zipmap([&quot;a&quot;, &quot;b&quot;], [1, 2])<br>{<br>  &quot;a&quot; = 1<br>  &quot;b&quot; = 2<br>}</pre><h3>time_sleep (Resource)</h3><p>This can be used to have delays between resources during application or destruction.</p><pre># This resource will destroy (potentially immediately) after null_resource.next<br>resource &quot;null_resource&quot; &quot;previous&quot; {}<br><br>resource &quot;time_sleep&quot; &quot;wait_30_seconds&quot; {<br>  depends_on = [null_resource.previous]<br><br>  create_duration = &quot;30s&quot;<br>}<br><br># This resource will create (at least) 30 seconds after null_resource.previous<br>resource &quot;null_resource&quot; &quot;next&quot; {<br>  depends_on = [time_sleep.wait_30_seconds]<br>}</pre><h3>Vault Provider</h3><p>The Vault provider allows Terraform to use <a href="https://vaultproject.io/">HashiCorp Vault</a>. The main purpose behind the vault is security.</p><h3>Terraform basic commands</h3><ol><li><strong>Terraform version</strong></li></ol><p>This command we run after we install Terraform on top of our base OS to check if installed properly and also to check the version.</p><p><strong>2. Terraform init</strong></p><p>This command we run after we create new code, it will download the plugin/driver.</p><p><strong>3. Terraform validate</strong></p><p>This command we run to check the syntax of the code.</p><p><strong>4. Terraform plan</strong></p><p>This command we run to get an execution plan, which lets us preview the changes that Terraform plans to make to our infrastructure.</p><p><strong>5. Terraform </strong><a href="https://developer.hashicorp.com/terraform/cli/commands/apply"><strong>apply</strong></a></p><p>This command we run to deploy our code, when we run this without passing a saved plan file it will create a new execution plan and prompts you to approve that plan, and takes the indicated actions.</p><p>We can pass the -auto-approve option to instruct Terraform to apply the plan without asking for confirmation.</p><p><strong>6. Terraform </strong><a href="https://developer.hashicorp.com/terraform/cli/commands/destroy"><strong>destroy</strong></a></p><p>This command is the best way to destroy all remote objects managed by a particular Terraform configuration.</p><p><strong>7. Terraform refresh</strong></p><p>This command is used to update the terraform.tfstate file, terraform objects can change outside terraform and this command helps to get all the fresh info.</p><p><strong>8. Terraform workspace</strong></p><p>We can set the workspace and use it as a parameter inside the code to automate.</p><p>Usage: terraform workspace &lt;subcommand&gt; [options] [args]</p><p><strong>9. Terraform console</strong></p><p>This gives live IDE we can run and test our syntax.</p><p><strong>10. Terraform fmt</strong></p><p>This command gives proper look and feel to our code.</p><p><strong>11. Terraform taint</strong></p><p>To destroy and recreate specific resources.</p><p><em>That’s the End! Hopefully, after this, you would feel more confident starting with Terraform. For any suggestions/queries please free feel to address in the comments!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3db29ed261a8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fasal-engineering/a-developers-guide-to-terraform-3db29ed261a8">A Developer’s Guide to Terraform</a> was originally published in <a href="https://medium.com/fasal-engineering">Fasal Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Serverless Framework]]></title>
            <link>https://medium.com/fasal-engineering/aws-serverless-framework-8f5f71f45caf?source=rss-12eba527366d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f5f71f45caf</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-step-functions]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <dc:creator><![CDATA[Prithvi A Parit]]></dc:creator>
            <pubDate>Thu, 01 Sep 2022 04:52:22 GMT</pubDate>
            <atom:updated>2022-09-01T04:52:22.004Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QnO4seuXjzViEnIk" /></figure><p>The Serverless Framework has got an open-source CLI and a hosted dashboard and together we get full serverless application lifecycle management. We can develop, deploy, troubleshoot, and secure our applications with radically less overhead and cost by making use of the Serverless Framework.</p><h3>Serverless Framework with AWS</h3><p>The Serverless Framework can be used for deploying our code to many cloud providers like AWS, Apache OpenWhisk, Cloudflare Workers, Microsoft Azure, and Google Cloud Platform.</p><p>At Fasal we make use of the serverless framework to deploy and manage our AWS services. The Serverless Framework helps in deploying our <a href="https://serverless.com/aws-lambda/">AWS Lambda</a> functions, along with the AWS infrastructure resources which are required. It’s a CLI that gives us structure, automation, and best practices out-of-the-box, allowing you to focus on building polished, event-driven, serverless architectures, comprised of events that trigger the functions.</p><p>The Serverless Framework differs from other app frameworks because:</p><ul><li>It manages both code and infrastructure</li><li>It supports Node.js, Python, Java, and much more languages.</li></ul><h3>Core Idea</h3><h4>Functions</h4><p>A Function is an AWS Lambda function. AWS Lambda is a serverless, event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers. You can trigger Lambda from over 200 AWS services and software-as-a-service (SaaS) applications and only pay for what you use.</p><h4>Events</h4><p>Framework as an Event is anything that triggers an AWS Lambda Function to run. Events are infrastructure events on AWS such as:</p><ul><li><em>An AWS API Gateway HTTP endpoint request (e.g., for a REST API)</em></li><li><em>A CloudWatch timer (e.g., run every 5 minutes)</em></li><li><em>An AWS S3 bucket upload (e.g., for an image)</em></li><li><em>A CloudWatch Alert (e.g., something happened)</em></li><li><em>An AWS SNS topic (e.g., a message)</em></li></ul><h4>Resources</h4><p>Resources are AWS infrastructure components that our lambda function needs such as:</p><ul><li><em>An AWS S3 Bucket.</em></li><li><em>An AWS DynamoDB Table.</em></li><li><em>An AWS SNS Topic.</em></li><li><em>Anything that can be defined in CloudFormation is supported by the Serverless Framework</em></li></ul><h4>Services</h4><p>It&#39;s like a project file, and we can have multiple services for a single app. A Service is the Framework’s unit of organization. It’s where we define our Functions, the Events that trigger them, and the Resources. A file named serverless.yml or serverless.json can be used to describe a service in YAML or JSON format, at the root directory of the project.</p><h3>Serverless Use Cases</h3><p>Below are some of the use cases for the AWS Serverless Framework:</p><h4>Image Processing</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*WJ4QR93S00A_O2avxLPwZQ.png" /></figure><h4>Workflow Automation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*o_46FsNgTiChTsCj_kLIzw.png" /></figure><h4>Scheduled Tasks</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*ewy0OC4IpwVLkVkoNby-xg.png" /></figure><h4>Web and Mobile Apps and APIs</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*cxMKgGZ9L0pTi39lJkic1w.png" /></figure><h4>IoT</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*2a57R-jDVzzZCK2qNaySFA.png" /></figure><h3>Serverless Use Cases at Fasal</h3><h4>Plugins in Serverless Framework</h4><p>The Serverless Frameworks&#39; new features can be extended using a plugin and the plugin is custom JavaScript code. At Fasal, we use a specific workflow so we install a pre-written plugin or we can also write one to customize the framework as we need.</p><h4>Automating CI/CD workflow for serverless apps with CircleCI</h4><p>At Fasal, to minimize redundant communication across teams and manual scrutiny we need to invest in automating CI/CD processes. We make use of CircleCI as a CI/CD tool. Know more about <a href="https://medium.com/fasal-engineering/an-introduction-to-circleci-37d0d3efa00a">CircleCI</a>.</p><h4>Automating complex workflows</h4><p>As an AI-powered company, we are constantly developing complex workflows that include continuous incoming data, processing these data, and analyzing this data in a timely fashion. In this respect, we have made use of the <a href="https://aws.amazon.com/step-functions/?step-functions.sort-by=item.additionalFields.postDateTime&amp;step-functions.sort-order=desc">AWS Step Functions</a> to develop and manage such complex workflows. In the next section, I will be discussing more AWS Step Functions.</p><h3>AWS Step Functions</h3><p>AWS Step Functions is a service from Amazon Web Services that makes it easier to orchestrate multiple AWS services to fulfill tasks. Step Functions help to create steps in a flow where the output of one step becomes the input for another degree. The best part is all using a visual workflow editor.</p><p>Step Functions gives quite a bit of favorable functionality, such as automatic retry handling, triggering, and tracking for each workflow step, and ensures whether the order of steps is correct. Although that list might at first seem unexceptional, it turns out it’s not at all insignificant to ensure all these things happen correctly in workflows that contain dozens of steps and hundreds of parallel executions. Step Functions take on a lot of the tasks that had to have previously happened in the application.</p><h4>How do AWS Step Functions work?</h4><p>Behind the scene, Step Functions is a state machine, and its primary abstractions are called states. A Step Functions configuration constitutes a map of all possible steps and the transitions between them.</p><p>Amazon States Language is based on JSON is proprietary to Amazon and is used to define the states and their transitions.</p><h4>Why are AWS Step Functions integral to the Serverless ecosystem?</h4><p>‍When building Serverless applications, we have our growing workloads and developers usually want to scale the application according to it, while we also need multiple teams to work simultaneously on different parts of the application at low cost. In the Serverless model, we have one of the best practices to accomplish these goals is by separating the business logic of an application into a set of decoupled services. A large Serverless application can consist of tens or hundreds of Serverless services.</p><p>The challenge comes when many services all need access to various parts of a shared state. To manage these services efficiently, the teams must also be able to organize the flow of data through all application services in a single place, and this is exactly what AWS Step Functions handles. Step Functions have become an essential part of the Serverless ecosystem because of all the state and data management needed to keep Serverless systems working effectively at scale.</p><h4>How do AWS Step Functions integrate with other AWS services?</h4><p>Step Functions can be used for task execution — with synchronous or asynchronous execution models (wait vs. callback) using the following AWS services:</p><ul><li>Invoking Lambda functions</li><li>Running AWS Batch jobs</li><li>Running a task in Amazon Elastic Container Service (ECS)</li></ul><p>Step Functions can also be used to insert or fetch an item from your databases such as Amazon DynamoDB. They can be also used for messages and notifications e.g. by publishing a topic in Amazon SNS or sending a message in Amazon SQS.</p><h4>How do AWS Step Functions work with the Serverless Framework?</h4><p>‍We can do it in two ways:</p><ul><li>First, by using the Serverless Step Functions plugin, you can include Amazon State Language for Step Functions in your serverless.yml file and deploy it using the Serverless Framework.</li><li>Second, we can use the Serverless Framework to create the AWS Lambda Functions-based services that Step Functions will orchestrate.</li></ul><h4>Benefits of using AWS Step Functions</h4><ul><li>Quickly create complex sequences of tasks</li><li>Manage state between executions of various stateless functions</li><li>Decouple application workflow logic from business logic</li><li>More efficient workflows with parallel executions</li></ul><h4>Fasal’s use case on developing Serverless Framework using AWS Step Functions</h4><p>At Fasal, we use <a href="https://medium.com/fasalapp/crop-health-assessment-using-satellite-imagery-2dcc57f76f33">satellite data for crop health assessment</a>. The satellite data pipeline is a complex workflow and includes the following key processes:</p><blockquote><em>Step 1- Getting polygon coordinates of the field</em></blockquote><blockquote><em>Step 2 — Pre Processing the shape of the plot using boundary coordinates.</em></blockquote><blockquote><em>Step 3 — Data Capturing (Sentinel 2A Data for processing)</em></blockquote><blockquote><em>Step 4 — Data Processing &amp; Generating NDVI, SAVI, SIPI, EVI images</em></blockquote><blockquote><em>Step 5 — Clipping of shape-file of geotagged fields</em></blockquote><blockquote><em>Step 6 — Generating Colour coded Image with improved image quality.</em></blockquote><p>To perform this operation we make use of the following methodology.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*PP4_zdziGx0nkRmYQEUnPg.png" /></figure><blockquote>As mentioned earlier, we can use the Serverless Framework to create the AWS Lambda Functions based services that Step Functions will orchestrate. We then use CircleCI to automate the complete flow.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ES7OPmXG561S62Qafs0QIA.png" /></figure><p>These are the jobs running in parallel in CircleCI where the three lambdas we need are configured using the Step Functions and they run in parallel. After the lambdas are launched the code of the Serverless Framework for configuring the Step Functions using the Lambda Functions is launched our entire workflow is ready.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*gziXoBs4nEW5l-n_CRdr5g.png" /></figure><p>I hope this article helped you to see how powerful and seamless deploying with AWS Serverless Framework is. AWS Serverless Framework is evolving very rapidly and its adoption is also growing exponentially. There are many tools and services already present making the adaptation of this technology easy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f5f71f45caf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fasal-engineering/aws-serverless-framework-8f5f71f45caf">AWS Serverless Framework</a> was originally published in <a href="https://medium.com/fasal-engineering">Fasal Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An introduction to CircleCI]]></title>
            <link>https://medium.com/fasal-engineering/an-introduction-to-circleci-37d0d3efa00a?source=rss-12eba527366d------2</link>
            <guid isPermaLink="false">https://medium.com/p/37d0d3efa00a</guid>
            <category><![CDATA[circleci]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Prithvi A Parit]]></dc:creator>
            <pubDate>Thu, 03 Feb 2022 09:29:34 GMT</pubDate>
            <atom:updated>2022-02-03T09:29:34.861Z</atom:updated>
            <content:encoded><![CDATA[<p>CircleCI is the continuous integration &amp; delivery platform that helps the development teams to automate the build, test, and deployment of their codes. CircleCI can be configured to run very complex pipelines efficiently with caching, docker layer caching, resource classes, and many more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YiBabfoQ4osOVpWMcwzKMg.jpeg" /></figure><h3>What is Continuous Integration?</h3><p>Continuous Integration is a practice that encourages developers to push small, frequent changes in their code into the main branch of a shared repository. Instead of building out features in isolation and integrating them at the end of a development cycle, code is integrated with the shared repository by each developer continuously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v70pX8F_UK_YNJxKzW9jOA.png" /></figure><h3>Salient features of CircleCI</h3><ul><li>Serves around 30000 clients and is capable of running a million tasks per day.</li><li>Offers performance-based scaling options.</li><li>Incorporates SSH into the build and test runs to debug.</li><li>Enables setting up parallel builds for faster execution of the process.</li><li>Runs every task as a new container which prevents stale build data from causing issues.</li><li>Announces the end of task execution via Email Notification.</li><li>Offers numerous orbs (plugins) that help in connecting the existing tools setup.</li></ul><p>Next, we will go over some key elements of CircleCI.</p><h3>- Pipelines</h3><p>CircleCI pipelines are the highest-level unit of work and a full set of processes you run when you trigger work on your projects. Pipelines contain workflows that coordinate your jobs. They have a fixed, linear lifecycle, and are associated with a specific actor. Pipelines trigger when a change is pushed to a project that has a CircleCI configuration (.circleci/config.yml) file included. can also be scheduled, triggered manually through the CircleCI app, or using the API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*co20dUt-QhQI75jdyNfqtQ.png" /></figure><h3>- Workflows</h3><p>Workflows are a collection of jobs and a set of rules to define their run order. CircleCI workflows provide much more advanced configurations for running a single set of jobs. Below are some workflow examples:</p><ul><li>Sequential workflow: This type of workflow follows a sequential order where each job starts only when a required job finishes successfully as shown in the diagram.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QZSAm1WEEaFLL-vZhQs0QA.png" /><figcaption>Sequential workflow</figcaption></figure><ul><li>Fan-out/fan-in workflow: This type of workflow runs a common build job, then fans-out to run a set of acceptance test jobs concurrently, and finally fans-in to run a common deploy job.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7wi5CbIru7JmD02qIUbqXA.png" /><figcaption>Fan-out/fan-in workflow</figcaption></figure><h3>- Caching and Artifacts</h3><p>Caching allows reusing the data from expensive fetch operations from previous jobs. It is usually used to avoid downloading content, like dependencies or libraries, each time you run a job. After the initial job run, future instances of the job will run faster by not redoing work.</p><p>Artifacts are used for longer-term storage of the outputs of your build process. They are the files created by the build process, such as distribution packages, WAR files, logs, and reports. E.g., a .apk file required to package and upload an Android app to Google Play is an artifact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5EqAFCQE32psavLReIBmQ.png" /></figure><h3>- Executors</h3><p>CircleCI offers several execution environments also called executors. An executor defines the underlying technology or environment in which to run a job. You can set up to run your jobs in the docker, machine, macOS, or windows executor and specify an image with the tools and packages they need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zJd-zROdt-sbTMag_H1_UQ.png" /></figure><h3>- Resource classes</h3><p>The <strong><em>resource_class</em></strong> feature of CircleCI allows one to configure the CPU and RAM for each job. Different resource classes are available for different executors.</p><h3>- Orbs</h3><p>CircleCI orbs are open-source, shareable packages of parameterizable reusable configuration elements, including jobs, commands, and executors. They are used to reduce configuration complexity and are easy to integrate with other software and services stack quickly across many projects.</p><h3>How does CircleCI work?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iG37rU2M-YenGXPo0DD-_A.png" /></figure><p>A software repository on a supported version control system needs to be authorized and added as a project on circleci.com. CircleCI integrates with GitHub, GitHub Enterprise, and Bitbucket. Every time a code commit is made, CircleCI creates a pipeline. Every code change then triggers automated tests in a clean container or virtual machine. CircleCI runs each job in a separate container or virtual machine.</p><p>CircleCI then sends an email notification of success or failure after the tests are complete. CircleCI also includes integrated slack and IRC notification.</p><p>Code test coverage results are available from the details page for any project for which a reporting library is added.</p><p>CircleCI may be configured to deploy code to various environments, including:</p><ul><li>AWS CodeDeploy</li><li>AWS EC2 Container Service (ECS)</li><li>AWS S3, Google Kubernetes Engine (GKE)</li><li>Microsoft Azure</li><li>Heroku</li></ul><p>In conclusion, CircleCI is a powerful continuous integration and continuous delivery platform to automate your software builds, tests and deployments efficiently.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37d0d3efa00a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fasal-engineering/an-introduction-to-circleci-37d0d3efa00a">An introduction to CircleCI</a> was originally published in <a href="https://medium.com/fasal-engineering">Fasal Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CircleCI]]></title>
            <link>https://medium.com/fasal-engineering/circleci-aa4f16cabebd?source=rss-12eba527366d------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa4f16cabebd</guid>
            <dc:creator><![CDATA[Prithvi A Parit]]></dc:creator>
            <pubDate>Fri, 28 Jan 2022 13:12:34 GMT</pubDate>
            <atom:updated>2022-01-28T13:16:05.333Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YiBabfoQ4osOVpWMcwzKMg.jpeg" /></figure><p>CircleCI is the continuous integration &amp; delivery platform that helps the development teams to release code rapidly and automate the build, test, and deploy. CircleCI can be configured to run very complex pipelines efficiently with caching, docker layer caching, resource classes and many more.</p><h3>What is continuous integration?</h3><p>Continuous integration is a practice that encourages developers to integrate their code into a main branch of a shared repository early and often. Instead of building out features in isolation and integrating them at the end of a development cycle, code is integrated with the shared repository by each developer multiple times throughout the day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v70pX8F_UK_YNJxKzW9jOA.png" /></figure><h3>Salient features of CircleCI</h3><ul><li>Serves around 30000 clients and is capable of running a million tasks per day.</li><li>Offers performance-based scaling options.</li><li>Incorporates SSH into the build and test runs to debug.</li><li>Enables setting up of parallel builds for faster execution of the process.<br>Runs every task as a new container which prevents stale build data causing issues.</li><li>Announces the end of task execution via Email Notification.</li><li>Offers numerous orbs (plugins) that help in connecting the existing tools setup.</li></ul><h3>Pipelines Overview.</h3><p>CircleCI pipelines are the highest-level unit of work, encompassing a project’s full .circleci/config.yml file. Pipelines include your workflows, which coordinate your jobs. They have a fixed, linear lifecycle, and are associated with a specific actor. Pipelines trigger when a change is pushed to a project that has a CircleCI configuration file included, and can also be scheduled, triggered manually through the CircleCI app, or using the API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*co20dUt-QhQI75jdyNfqtQ.png" /></figure><blockquote>Using Workflows to Schedule Jobs.</blockquote><ul><li>Sequential job execution example</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QZSAm1WEEaFLL-vZhQs0QA.png" /></figure><ul><li>Fan-out/fan-in workflow example</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7wi5CbIru7JmD02qIUbqXA.png" /></figure><h3>Executors and Images.</h3><p>CircleCI offers several execution environments. We call these executors. An executor defines the underlying technology or environment in which to run a job. Set up your jobs to run in the docker, machine, macos or windows executor and specify an image with the tools and packages you need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zJd-zROdt-sbTMag_H1_UQ.png" /></figure><h3>Orbs</h3><p>CircleCI orbs are open-source, shareable packages of parameterizable reusable configuration elements, including jobs, commands, and executors. Use orbs to reduce configuration complexity and help you integrate with your software and services stack quickly and easily across many projects.</p><h3>Writing to the cache in workflows</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5EqAFCQE32psavLReIBmQ.png" /></figure><p>Jobs in one workflow can share caches. This makes it possible to create race conditions in caching across different jobs in workflows.</p><p>Cache is immutable on write. Once a cache is written for a specific key like node-cache-main, it cannot be written to again. Consider a workflow of 3 jobs, where Job3 depends on Job1 and Job2: {Job1, Job2} -&gt; Job3. They all read and write to the same cache key.</p><p>In a run of the workflow, Job3 may use the cache written by Job1 or Job2. Since caches are immutable, this would be whichever job saved its cache first. This is usually undesirable, because the results are not deterministic. Part of the result depends on chance. You could make this workflow deterministic by changing the job dependencies. For example, make Job1 and Job2 write to different caches, and Job3 loads from only one. Or ensure there can be only one ordering: Job1 -&gt; Job2 -&gt;Job3.</p><h3>How CircleCI Works</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iG37rU2M-YenGXPo0DD-_A.png" /></figure><ul><li>VCS integration:<br>CircleCI integrates with GitHub, GitHub Enterprise, and Bitbucket. Every time you commit code, CircleCI creates a pipeline.</li><li>Automated testing:<br>CircleCI automatically runs our pipeline in a clean container or virtual machine, allowing us to test every commit.</li><li>Notifications:<br>Your team is notified if a pipeline fails so issues can be fixed quickly. Automate notifications with our Slack integration.</li><li>Automated deployment:<br>Passing pipelines are deployed to various environments so our product goes to market faster.</li></ul><h3>CircleCI in your workflow</h3><p>A software repository on a supported version control system needs to be authorized and added as a project on circleci.com. Every code change then triggers automated tests in a clean container or virtual machine. CircleCI runs each job in a separate container or virtual machine.</p><p>CircleCI then sends an email notification of success or failure after the tests complete. CircleCI also includes integrated slack and IRC notification.</p><p>Code test coverage results are available from the details page for any project for which a reporting library is added.CircleCI may be configured to deploy code to various environments, including:</p><ul><li>AWS CodeDeploy</li><li>AWS EC2 Container Service (ECS)</li><li>AWS S3, Google Kubernetes Engine (GKE)</li><li>Microsoft Azure</li><li>Heroku</li></ul><h3>Benefits of CircleCI</h3><p>CircleCI can be configured to run very complex pipelines efficiently with sophisticated caching, docker layer caching, and resource classes for running on faster machines.</p><p>As a developer using CircleCI we can:</p><ul><li>SSH into any job to debug our build issues.</li><li>Set up parallelism in your .circleci/config.yml file to run jobs faster.</li><li>Configure caching with two simple keys to reuse data from previous jobs in our workflow.</li><li>Configure self-hosted runners for unique platform support.</li><li>Access Arm resources for the machine executor.</li><li>Use orbs, reusable packages of configuration, to integrate with third parties.</li><li>Use pre-built Docker images in a variety of languages.</li><li>Use the API to retrieve information about jobs and workflows.</li><li>Use the CLI to access advanced tools locally.</li><li>Get flaky test detection with test insights.</li></ul><p>As an operator or administrator of CircleCI installed on our own servers, CircleCI provides monitoring and insights into your builds and uses Nomad for scheduling.</p><h3>Powerful Features:</h3><ul><li>Faster performance</li><li>Complete control</li><li>Flexible job orchestration</li><li>Unparalleled flexibility</li><li>Choose the CPU/RAM we need</li><li>Language-agnostic support</li><li>Powerful caching</li><li>SSH or run local builds for easy debugging</li><li>Unmatched security</li><li>Insights dashboard</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa4f16cabebd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fasal-engineering/circleci-aa4f16cabebd">CircleCI</a> was originally published in <a href="https://medium.com/fasal-engineering">Fasal Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>