<?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 Asna Siji on Medium]]></title>
        <description><![CDATA[Stories by Asna Siji on Medium]]></description>
        <link>https://medium.com/@asnakhader?source=rss-bc29b083f17a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qYREhbV3j3npCoXdgMDp_w.jpeg</url>
            <title>Stories by Asna Siji on Medium</title>
            <link>https://medium.com/@asnakhader?source=rss-bc29b083f17a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 00:29:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@asnakhader/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[Building an Intelligent Document Processing System — Part 1]]></title>
            <link>https://awstip.com/building-an-intelligent-document-processing-system-part-1-7dc180fe3a93?source=rss-bc29b083f17a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dc180fe3a93</guid>
            <category><![CDATA[sagemaker]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Asna Siji]]></dc:creator>
            <pubDate>Wed, 21 Jan 2026 17:16:19 GMT</pubDate>
            <atom:updated>2026-01-22T08:33:39.699Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Building an Intelligent Document Processing System — Part 1</strong></h3><p><strong>Image Classification using Machine Learning &amp; Amazon SageMaker</strong></p><p><em>“The real innovation is not what users see, but what they no longer have to worry about.”</em></p><p>In today’s digital-first world, document-heavy processes such as visa verification, identity checks, and compliance validation still rely heavily on manual review. These processes are time-consuming, error-prone, and difficult to scale.</p><p>This article is Part 1 of a two-part series where we build an intelligent document processing system using Machine Learning and AWS.<br> In this first part, the focus is on image classification — identifying and classifying visa documents using ML models and deploying them as a real-time endpoint using Amazon SageMaker.</p><p><strong>Why Machine Learning for Document Processing?</strong></p><p>Traditional rule-based systems struggle with document images due to:</p><ul><li>Variations in layout and format</li><li>Noise, lighting, orientation issues</li><li>Different countries issuing visas with different templates</li></ul><p>Machine Learning models, especially those trained on images, can <strong>learn patterns automatically</strong> and generalize better to unseen data.</p><h3>How can we use ML in Document Processing Systems</h3><ul><li>To identify the type of document (Ex:- Visa of Which Country)</li><li>To Extract the field value pairs (Ex:- Name, Date of Expiry etc. from the document)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*f77gKZoT_zD3t7xVlPFgeA.png" /></figure><h3>AWS Services in Spotlight</h3><p>Let’s have a quick look athe AWS services that are commonly while implementing real-world machine learning systems.</p><h4>Amazon SageMaker</h4><p>Amazon SageMaker is a fully managed service designed to support the complete machine learning lifecycle, from data preparation and experimentation to training, deployment, and monitoring. It provides built-in tools for notebooks, training jobs, model management, and MLOps, making it easier for teams to build and operate machine learning systems at scale. In summary,</p><p>Amazon SageMaker is a fully managed service that enables:</p><ul><li>Model training</li><li>Model hosting</li><li>Scalable real-time inference</li></ul><p>It removes the heavy lifting of infrastructure management.</p><h4>SageMaker Endpoint</h4><p>SageMaker Endpoints are used to host trained machine learning models as real-time, scalable APIs. They allow applications to send inference requests and receive predictions. Endpoints are commonly used to turn machine learning models into production-ready services.</p><p>A SageMaker Endpoint allows you to:</p><ul><li>Deploy trained ML models</li><li>Invoke predictions via API</li><li>Scale automatically based on traffic</li></ul><p>This makes it ideal for integrating ML into production applications.</p><h4>Amazon S3</h4><p>Amazon S3 is AWS’s object storage service and is widely used as the data backbone of machine learning systems. It is commonly used to store training datasets, model artifacts, logs, and inference inputs and outputs.</p><h4>AWS CloudTrail</h4><p>AWS CloudTrail is a service used for governance, auditing, and operational visibility. It records API calls made across AWS services, including SageMaker. In machine learning systems, CloudTrail is often used to track activities such as model deployments and endpoint invocations, helping teams monitor usage, investigate issues, and meet compliance requirements.</p><p>Before diving into the solution, let’s briefly understand the <strong>types of Machine Learning problems</strong>.</p><h3><strong>Types of Machine Learning Problems</strong></h3><p><strong>1. Classification</strong></p><p>Classification problems aim to <strong>assign an input to a category or label</strong>.</p><p>Examples:</p><ul><li>Is this image a <em>visa</em> or <em>non-visa</em>?</li><li>Which country’s visa was uploaded?</li></ul><p>👉 <strong>Visa image classification falls under this category.</strong></p><p><strong>2. Regression</strong></p><p>Regression predicts a <strong>continuous numerical value</strong>.</p><p>Examples:</p><ul><li>What will be the price of a 2BHK Townhouse in Dubai in 2030?</li><li>Estimating document approval probability</li></ul><p><strong>3. Clustering</strong></p><p>Clustering groups data points based on similarity <strong>without predefined labels</strong>.</p><p>Examples:</p><ul><li>Grouping similar document layouts</li><li>Identifying unknown document types</li></ul><p><strong>A Note on Neural Networks</strong></p><p>Neural Networks are inspired by the human brain and consist of interconnected layers of neurons. For image-related tasks, <strong>Convolutional Neural Networks (CNNs)</strong> are widely used because they can:</p><ul><li>Capture spatial patterns</li><li>Learn edges, textures, and shapes</li><li>Perform well on visual data</li></ul><p>However, more complex models don’t always guarantee better results — especially when data is limited. This becomes evident in the experiments below.</p><h3><strong>Dataset Preparation</strong></h3><ul><li>❌ <strong>No public dataset available</strong></li><li>✅ <strong>Data manually collected and labeled</strong></li><li>For the POC, mainly we have targeted the visa of 3 countries</li></ul><p>To improve robustness and reduce overfitting, <strong>data augmentation</strong> techniques were applied:</p><ul><li>Image rotations</li><li>Horizontal and vertical flips</li><li>Brightness and contrast adjustments</li></ul><p>This helped simulate real-world variations such as scanning issues and camera angles.</p><h3><strong>Experiments Conducted</strong></h3><p><strong>Experiment 1: CNN Model Trained from Scratch</strong></p><p>A custom CNN model was trained directly on the visa image dataset.</p><p><strong>Observation:</strong></p><ul><li>Training accuracy was high</li><li>Validation accuracy dropped significantly</li></ul><p><strong>Issue:</strong><br> ➡️ <strong>Overfitting</strong>, due to limited dataset size</p><p><strong>Experiment 2: Pre-trained ImageNet Model + SVM</strong></p><p><strong>ImageNet</strong> : A large, public dataset of millions of labeled images used to train many popular computer vision models and learn general visual features.</p><p><strong>SVM (Support Vector Machine)</strong> : A supervised learning algorithm that finds the optimal boundary between classes and is especially effective in classification tasks.</p><p>In this experiment:</p><ul><li>A pre-trained CNN (trained on ImageNet) was used for <strong>feature extraction</strong></li><li>An <strong>SVM classifier</strong> was trained on these extracted features</li></ul><p><strong>Result:</strong></p><ul><li>Reduced overfitting</li><li>However, overall accuracy was <strong>still low</strong></li></ul><p><strong>Reason:</strong><br> General image features were not sufficiently focused on visa-specific regions.</p><p><strong>Experiment 3: ROI-based Feature Extraction + SVM</strong></p><p>To improve performance:</p><ul><li><strong>Regions of Interest (ROI)</strong> were identified (key areas of the visa)</li><li>Features were extracted specifically from these regions</li><li>An SVM classifier was trained on the ROI features</li></ul><p><strong>Result:</strong></p><ul><li>✅ Improved accuracy</li><li>✅ Better generalization on unseen data</li></ul><p>🏆 <strong>This approach delivered the best performance among all experiments.</strong></p><p><strong>Final Model Choice</strong></p><p><strong>ROI-based feature extraction + SVM</strong></p><ul><li>Higher accuracy</li><li>Better generalization</li><li>Computationally efficient</li><li>Suitable for real-time inference</li></ul><p>This model was selected for deployment.</p><h3><strong>Model Deployment Overview</strong></h3><p>I used the Jupyter Notebooks running in my local Anaconda to train and test the ML Models. Please note that this can be done through Notebooks SageMaker Studio as well. Once we have obtained the desired accuracy from the model, it can be hosted in AWS for real time inference.</p><p>The deployment flow includes:</p><ol><li>Model artifacts and inference code packaged together</li><li>Uploaded to <strong>Amazon S3</strong></li><li>Model created in <strong>SageMaker</strong></li><li>Endpoint configuration defined</li><li>Real-time endpoint deployed</li><li>Endpoints invoked from Lamda and Log monitored in CloudTrail</li></ol><p><strong>Step 1 : Model artifacts Packaging</strong></p><p>Once the training is completed, its time to pack the artifacts for deployment.</p><p><strong>Pickle (Serialize) the Model and Label Encoder</strong></p><pre>import pickle<br>import os<br><br># Create model folder if it doesn&#39;t exist<br>os.makedirs(&quot;model&quot;, exist_ok=True)<br><br># Save trained model<br>with open(&quot;model/model.pkl&quot;, &quot;wb&quot;) as f:<br>    pickle.dump(trained_model, f)<br><br># Save label encoder<br>with open(&quot;model/label_encoder.pkl&quot;, &quot;wb&quot;) as f:<br>    pickle.dump(label_encoder, f)</pre><p><strong>Create Folder Structure</strong></p><p>Below shows a sample structure of the artifacts before packaging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*pHQEYsLDpgu8GM9GNc7zuQ.png" /><figcaption>Folder structure</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*SPGNwKPKot-7Ft4kNR6F4w.png" /></figure><p><strong>model/model.pkl</strong></p><ul><li>Pickled trained machine learning model (SVM or any model)</li></ul><p><strong>model/label_encoder.pkl</strong></p><ul><li>Maps numeric outputs ↔ class names</li></ul><p><strong>code/inference.py</strong></p><ul><li>Loads model &amp; encoder</li><li>Processes input images</li><li>Runs predictions and returns results</li></ul><p><strong>requirements.txt</strong></p><ul><li>Lists Python libraries required at runtime</li><li>Example:</li></ul><pre>numpy==1.21.6<br>pillow==9.2.0<br>scikit-learn==1.0.2<br>joblib==1.1.0</pre><p><strong>Create </strong><strong>model.tar.gz</strong></p><p>From the prtoject root folder, run below command to create the tar file</p><pre>tar -czvf model.tar.gz model code requirements.txt</pre><p>This will create a model.tar file.</p><p><strong>Step 2: Uploading Artifacts to S3</strong></p><p>Now that we have the tar file, we can upload it to an S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O7IVN8IEhf3MGqqJYtLOBQ.png" /></figure><p>Model artifacts and inference scripts were uploaded to an S3 bucket, which SageMaker accesses during deployment.</p><p><strong>Step 3: Creating the SageMaker Model</strong></p><p>Navigate to Amazon SageMaker AI console.</p><p>Under the Deployments and inference link,select Deployable models. List of already available models will be displayed. Click Create model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wEb5zltMbLqzc3sz8klU0Q.png" /></figure><p>On the Create model page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P8NL8ezEKMGjwSr35iYBzg.png" /></figure><p>Give the model a Name that identifies your model.For Model artifacts, enter the S3 URI where your packaged model (model.tar.gz) lives (for example s3://your-bucket/your/model.tar.gz).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*44BLviqEOEQSJwJmueSTtw.png" /></figure><p>For Container image, either choose a SageMaker provided image (for common frameworks) or provide the ECR image URI that contains your custom inference code. I used the first option. I used</p><p><em>763104351884.dkr.ecr.us-east-1.amazonaws.com/pytorch-inference:2.2.0-cpu-py310-ubuntu20.04-sagemaker</em></p><p>This is an official AWS-managed SageMaker PyTorch inference container. We used it because it provides a ready-made, production-grade runtime for serving machine learning models without having to build and maintain our own Docker image.</p><p>Under Execution role, select an IAM role that has permissions for SageMaker to access your S3 artifacts and create the resources needed.</p><p>I had difficulty bring the model up without specifying the enviornment variables. I used below ones, which indicates the file to look for and the location of the code etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2024t05AEJdhfk25SPS-CQ.png" /></figure><p>Click Create model.<br>→ This registers a SageMaker Model object that points to your S3 artifact.</p><p>Step 4 : Define an Endpoint Configuration</p><p>Endpoint configurations encapsulate which model to serve and what compute resources to use.In the left menu, click Endpoint configurations. Click Create endpoint configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ixsitt5O2DbSnn086eJY2g.png" /></figure><p>On the creation page:</p><p>Enter a Name for the endpoint configuration and select the type of endpoint. I tried with Serverless first, but my inference.py was bit heavy and was not loading properly. Hence switched to Provisioned endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BjI6De-ORZyjiOYe81xqIA.png" /></figure><p>Under Variants, select the model which we defined previously. We can also choose the instance type here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jLaCpGV53tUFNELfVZxFnw.png" /></figure><p>Click Create endpoint configuration.</p><p>Step 5: Deploy the Endpoint</p><p>In the left navigation pane, click Endpoints. Click Create endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*cgo-xXm3I1NG5fkTeisfVg.png" /></figure><p>On the Create endpoint page: Enter a unique Endpoint name. For Attach endpoint configuration, select Use an existing endpoint configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*LXTflTKkP15OW8xp6FpcLQ.png" /></figure><p>Choose the Endpoint configuration created earlier. Click Create endpoint.<br> This calls the SageMaker service to provision the compute and deploy your model as a fully managed HTTPS endpoint.</p><p>Step 6 : After Deployment</p><p>SageMaker will take a few minutes to launch the infrastructure hosting our model. Check the status of the deployment under Endpoints. It will go from Creating to InService. Once in service, your endpoint can accept inference requests.</p><p>Side Note : Try Invoking the sagemaker endpoint from lambda and monitor Cloud Watch logs to see the prediction coming in!</p><h4>What’s Next?</h4><p>In Part 2 of this series, we will:</p><ul><li>Integrate the SageMaker endpoint into a document processing pipeline</li><li>Invoke Textract for OCR</li><li>Assemble all parts to create an end-to-end intelligent doc processing system</li></ul><p>See ya!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dc180fe3a93" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/building-an-intelligent-document-processing-system-part-1-7dc180fe3a93">Building an Intelligent Document Processing System — Part 1</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating an end-to-end data pipeline in AWS]]></title>
            <link>https://awstip.com/creating-an-end-to-end-data-pipeline-in-aws-45df2af60cae?source=rss-bc29b083f17a------2</link>
            <guid isPermaLink="false">https://medium.com/p/45df2af60cae</guid>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[aws-glue]]></category>
            <category><![CDATA[amazon-athena]]></category>
            <dc:creator><![CDATA[Asna Siji]]></dc:creator>
            <pubDate>Sat, 08 Mar 2025 08:03:04 GMT</pubDate>
            <atom:updated>2025-03-10T16:46:49.605Z</atom:updated>
            <content:encoded><![CDATA[<p>Data comes in many formats. It can be structured, as in relational database tables; semi-structured, like JSON documents; or unstructured, as in social media posts. It is also available in various file formats, such as CSV, PDF, and other document types. Sometimes, to derive meaningful insights, we may need to process data coming from multiple files and sources. Data preparation hence becomes an important steps in the Data Analytics eco system.</p><p><strong>Data preparation</strong> is the process of cleaning, transforming, and organizing raw data to make it suitable for analysis or machine learning. It involves steps like data cleaning (handling missing values and errors), transformation (normalization, encoding), integration (merging datasets), and reduction (removing irrelevant features). Proper data preparation improves data quality, enhances model performance, and ensures accurate insights. Without it, raw data may contain inconsistencies and noise, leading to misleading results and poor decision-making.</p><p>This is exactly where AWS Glue comes to help. AWS Glue is a <strong>serverless and scalable</strong> data preparation tool, eliminating the need for infrastructure management. It is a fully managed ETL (Extract, Transform, Load) service that helps in discovering, cleaning, transforming, and organizing data. It features <strong>automated schema detection</strong>, which saves time in structuring raw data. It integrates seamlessly with <strong>AWS services</strong> like <strong>S3, Athena, and SageMaker</strong>, making it a powerful choice for data transformation and analytics.</p><p>Let’s consider a sample use case. You have two datasets, energy data of different countries including year, GDP, population, source of production (gas, hydro, coal, solar etc.) and another dataset with % of renewable share per country over years. Suppose we want to derive insights like this</p><ol><li>Is the Renewable Share of the country is impacting its GDP?</li><li>Is there any relationship between population of a country and its renewable energy share?</li></ol><p>In scenarios like this, we will have to combine different datasets and preprocess it to understand what data is trying to tell us. Let’s get glued to AWS Glue to understand this better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DbJB6cn908eS4Y64A2Nysw.png" /><figcaption>Data Pipeline — Overview</figcaption></figure><h3>How AWS Glue Supports Data Preparation:</h3><ol><li><strong>Data Discovery</strong> — Uses the <strong>AWS Glue Data Catalog</strong> to automatically detect and catalog metadata from different data sources.</li><li><strong>Data Cleaning</strong> — Handles missing values, deduplication, and schema corrections.</li><li><strong>Data Transformation</strong> — Converts data formats (e.g., CSV to Parquet), normalizes data, and applies business rules.</li><li><strong>Data Integration</strong> — Combines and joins data from multiple sources like <strong>S3, RDS, DynamoDB, and Redshift</strong>.</li><li><strong>Data Loading</strong> — Loads processed data into analytics-ready destinations, such as <strong>Amazon Redshift, S3, or Athena</strong>.</li></ol><p>Let’s dive deep…</p><p>Login into AWS management console and type S3 in the search bar to navigate to S3 service. Create a bucket. As my data is in 2 different formats, I have created 2 sub folders to keep it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*DFVPvcVo_gtk-FZs4h6DgQ.png" /></figure><p>AWS Glue expects a consistent schema when crawling a folder. If multiple CSVs in the same folder have different structures (different columns or data types), Glue gets confused and only extracts headers.</p><p><strong>Lesson Learnt </strong>: If both CSV files are kept in same folder, Glue crawler will extract only the headers and not data.</p><p>After creating the bucket, create 2 subfolders to keep the datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kzOLd9uNMa2Ylgigp8s0Tw.png" /></figure><p>Now, navigate to the AWS Glue console. Navigate to the ‘<strong>Crawlers’ </strong>under the Data Catalog section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9INF5-NmpXMDgw15My2Rw.png" /></figure><p>Let’s add a new crawler. It is a 5 step process. Peoceed by giving a name to the crawler and an optional description / tag if required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BjlH5hFosWi13aZSbcMFPA.png" /></figure><p>In step 2, provide the data source details. As we have kept our data files in S3, provide the S3 path till the subfolder. Note : End the path with ‘/’. There are options to crawl all subfolders or newly created subfolders only. Crawling can also be enabled based on S3 events.Select option to crawl all sub folders on subsequent runs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I_JogAWU54DeUquGQMwz9g.png" /></figure><p>There is provision to optionally provide customs classifiers. Here we can specify the format (ex:-csv), row and column delimiters etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fQRITOivNTF9YVmnXfIvpg.png" /></figure><p>In step 3, Configure the security setting by providing an IAM role. Click on Create new IAM role and provide necessary permissions to access S3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rv8A7Ms67LVBHoG6dvrc-A.png" /></figure><p>In step 4, provide the target database and table name.Also specify the schedule in which crwaler has to run. I have opted for On Demand crawling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lCpW6Z2QmKADN_I3V_urow.png" /></figure><p>Review the crawler setting and create the crawler. A success message pops up as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kqc4_P9V2AHhXlHYHtO1Lg.png" /></figure><p>In a similar fashion, create another crawler for the second dataset by specifying its S3 subfolder location. All the crawlers get listed under the Data Catalog section as shown. Select the crawler and click ‘Run’ to start the data processing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CTuARJh4NLWrIv0EHNFU5g.png" /></figure><p>After the crawler successfully completes its run, it creates tables under the Databases section. We can see that 2 tables got created with 2 different schemas. Let’s open the renewable scema.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ELIlUOSGWTute6EIJ5Sb6Q.png" /></figure><p>The columns from the csv file got extracted and is dispalyed here with its data type.There is provision to modify the schema as approriate. You can add a calculated field (say age from DOB), edit or delete fields.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P7J6ORbgOyEiR1NQMzX57g.png" /></figure><p>Let’s change the column name of renewables (% equivalent…) to a more appropriate one. After making the necessary changes, this can be saved as a different version of the schema.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LGkxnGxuttIOCKyfkRwxLA.png" /></figure><p>In addition to schema, Glue crawler extracts the data from the files. This is available in the View data option under the Tables. Clicking on it will take you to the Amazon Athena where we can run queries against the extracted data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KQ3K6gY5HgwT1f0JCdDr1w.png" /></figure><p>Let’s run a query joining data from both tables. If you run into any issues with Query syntax, Amazon Q is here to help. It will provide the correct syntax and ease lot of our pain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dswiYTnK2eK_SX2tHaZjUQ.png" /></figure><p>After the necessary columns from both tables are selected, we can create a View in Athena, which will have more appropriate representation for further analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KfQI_B6Hpjb80pbXE8JDEg.png" /></figure><p>Once we have the processed data in Athena, it can be used as input for further visualization and deriving insights in Quicksight. A detailed post on this one is <a href="https://medium.com/aws-tip/creating-an-interactive-data-visualization-dashboard-with-amazon-quicksight-c03dd63d4c0e">here</a>.</p><p>And by this we have created an end to end data pipeline in AWS. Cool. And never forget the Tips and Tricks!</p><h3>Tips and Tricks:</h3><p>✅ Store CSVs with different schemas in separate S3 folders<br>✅ Create separate Glue Crawlers for each schema<br>✅ Use AWS Glue Schema Registry or manually define schema in AWS Glue ETL Jobs if working with mixed schemas</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45df2af60cae" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/creating-an-end-to-end-data-pipeline-in-aws-45df2af60cae">Creating an end-to-end data pipeline in AWS</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How SageMaker helped me with my ML experiments]]></title>
            <link>https://awstip.com/how-sagemaker-helped-me-with-my-ml-experiments-a70f784efc04?source=rss-bc29b083f17a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a70f784efc04</guid>
            <category><![CDATA[sagemaker]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[sagemaker-studio]]></category>
            <dc:creator><![CDATA[Asna Siji]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 16:56:29 GMT</pubDate>
            <atom:updated>2025-02-10T18:06:25.282Z</atom:updated>
            <content:encoded><![CDATA[<p>26000 high quality images. Multiple feature extractions and feature fusions. Experiments that take days to complete. My personal laptop doing its best but still panting to cope up with the load. That&#39;s when I remembered, Amazon SageMaker. End.. Sorry beginning of the story.</p><p>Amazon SageMaker is a fully managed service that simplifies the complexities of machine learning.It helps to build, train, and deploy machine learning (ML) models at scale. From data preparation to model deployment, it offers many flavours of services to make your ML experiments easy. Some of them are</p><p><strong>SageMaker Data Wrangler : </strong>Your Data Preparation assistant in the cloud which has tools for data labeling, preprocessing, and transformation.</p><p><strong>Jupyter Notebooks</strong> : Train ML models by runniung your Jupyter notebooks at scale, leveraging built-in algorithms, or third-party frameworks like TensorFlow, PyTorch, etc.</p><p><strong>SageMaker Debugger:</strong> Provides real-time insights into the model’s behavior during training and inference, helping to debug and optimize the model.</p><p>Once the model is trained, SageMaker provides managed deployment options that provide scalability and availability. There are options to deploy real-time, serverless, asynchronous and batch inference. It can handle incoming requests and return predictions within milliseconds, for applications requiring low-latency responses.</p><p><strong>SageMaker Endpoint:</strong> Deploy trained models for getting real-time inferences using SageMaker Endpoint .</p><p><strong>SageMaker Pipelines:</strong> Automates the end-to-end machine learning workflow, including model monitoring and retraining. It integrates with monitoring tools to trigger updates and ensure continuous model evaluation and deployment.</p><p><strong>SageMaker Model Metrics:</strong> Tracks custom-defined performance metrics for deployed models, such as precision or recall. It allows for real-time monitoring and sends alerts if model performance drops below acceptable thresholds.</p><p><strong>SageMaker Model Monitor:</strong> Automatically tracks data drift and model quality by comparing incoming prediction data with baseline data. It helps detect performance issues such as accuracy degradation and identifies when model retraining is needed.</p><h4>Overview of Machine Learning Experiments</h4><p>ML experiments can be broadly classified into</p><p><strong>Supervised Learning</strong> : The model is trained on a dataset containing labelled data, input-output pairs.It learns patterns from this data and can predict outputs for unseen data.</p><p>Example :- <strong>Classification</strong> — The model classifies the input into a category.(Identifying paddy disease category from an input image), <strong>Regression</strong> — The model predicts a value (Predicting house prices based on features like size and location).</p><p><strong>Unsupervised learning</strong> : No explicit labels or categories are provided to the model. The model analyzes input data to identify structures or patterns.</p><p>Example:- <strong>Clustering</strong> — Grouping similar data points together (Customer segmentation in sales), <strong>Dimensionality Reduction</strong> — (Reducing feature complexity while retaining important information)</p><p><strong>Reinforcement Learning</strong> : Model learns to make decisions by interacting with the environment in a trial and error fashion. It subsequently learns an optimal policy to maximize rewards.</p><p>Examples include teaching robots to walk or manipulate objects, AI agents playing Chess etc.</p><p>As part of my experiment, I was trying to do classification of paddy leaves into 13 disease categories. So we have a dataset of images, 80% of which will be used to train the model. The model learns the different patterns in the image and associates it with each defect category. Once the model is trained, we test the model with the remaining 20% and validates its accuracy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*1QKuF1wfD2v6eaxD8HPaAQ.png" /><figcaption>ML — Experiment</figcaption></figure><p>There are many ways to extract different type of features from the input images. I was trying out a combination of hand crafted and deep feature (from pretrained models) extraction algorithms. The fused features given as input to classification algorithms to evaluate accuracy.</p><p>Now let’s get started with the Amazon SageMaker.</p><p>Login to AWS management console and type SageMaker in the search bar. SageMaker console will open with options for creating Unified Studio Domain or DataZone domain. AWS has totally revamped the look and feel of SageMaker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z1_LEiod72srygjtPwQkMA.png" /></figure><p>Amazon SageMaker Studio is an integrated development environment (IDE) for machine learning (ML) that provides tools for building, training, and deploying ML models. It offers a user-friendly interface where all stages of the ML workflow can be managed in one place, from data preparation to model deployment and monitoring.</p><p>Let’ s create a Unified Studio Domain by clicking the button. The page opens up which provides options for quick setup or manual setup for fine grained control.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sNp2alXVoVyZm-3AGCc1cg.png" /></figure><p>Word of caution : Quick setup can incur additional charges. So if you are looking for cost effective option, it is better to go for the manual setup. Always remember to select options which are absolutely required for the experiment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OLuvwRdIcsuAtwnvuZQ3eQ.png" /></figure><p>The Unified Studio requires a VPC to be created. Create the VPC and select atleast 3 subnets in different availability zones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mZUPlRAXjaB3_qIBvAMv7g.png" /></figure><p>The domain will be created and you are good to start with your experiment by logging into the unified studio. Loved this images! A creative collaboration between human and a machine :-)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*AAMpfqsuvGXYDOcBa0Vhfw.png" /></figure><p>Click on ‘Open unified studio’ button land in the home page for your machine learning and AI experiments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SduAXOi2XT18mMywUbPJHA.png" /></figure><p>As shown, Unified Studio offers a single consolidated environment for</p><ol><li>ML and Generative AI model development (run jupyter notebooks, train / deploy ML models)</li><li>Generative AI app development (ex:- building chat agents)</li><li>Data Processing and SQL Analytics (prepare and analyse data using Athena, EMR, Glue, Redshift etc)</li><li>Data and AI Governance</li></ol><p>As our experiments fall under the ML model development, we need to create a notebook, which in turn requires a project to be created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SoMhuGw_s5EKnh3EXcxCtg.png" /></figure><p>We are experimenting with an image classification task, hence give appropriate name that suits it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wqPoHbjrb1Vjhxk7mSih9w.png" /></figure><p>Choose Data analytic and AI-ML model development as the project profile. Review and complete all steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x8-zO1hwnc9GHgurs4iuAg.png" /></figure><p>The project got created. AWS automatically created a Git branch in CodeCommit as you can see in below image. The branch is created within the <strong>AWS CodeCommit repository</strong> associated with your project.</p><p>AWS gives the flexibility to integrate external Git repositories as well. During the project creation phase, it also creates an AWS CodeConnection for this purpose.</p><p>Some bites on <strong>AWS CodeCommit / AWS CodeConnection</strong></p><p>AWS <strong>CodeCommit</strong> is a fully managed <strong>private Git repository service</strong>, similar to GitHub, or Bitbucket. It allows teams to <strong>store, manage, and version control</strong> their code securely within AWS.</p><p>AWS <strong>CodeConnection</strong> is a <strong>Git repository integration service</strong> that connects <strong>external Git services</strong> (GitHub,Bitbucket etc.) to AWS tools like CodePipeline, and SageMaker Studio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bzQ6GcU7mcx8IU8LGdgMtA.png" /></figure><p>Now click on ‘New’ button at the corner and create a new Jupyter Notebook. Let’s start with our ML experiments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PI74VUoVBqiI8ioZ2_17IQ.png" /></figure><p>As we are conducting an image classification task, there are 2 ways to access images from the Jupyter Notebook in SageMaker.</p><p><strong>Notebook Workspace : </strong>As you can see, create folders with in the Notebook workspace , and upload images. Access them directly in Notebook as if accessing from a local drive.</p><p><strong>S3 :</strong> Upload your training and test images to S3 and access from Jupyter Notebook. Ensure that SageMaker is provided with appropriate roles for S3 access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z6eQgfUpHucpgRKh1Xw_Vg.png" /></figure><p>There is a built in support for <strong>Amazon Q</strong> which is integrated with the SageMaker Studio for providing natural language assistance for queries related to AWS services, Python, Jupyter notebooks etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wp94JU3Um2Qm7YY5amBoyw.png" /><figcaption>Amazon Q</figcaption></figure><p>Amazon Q is AWS’s AI-powered assistant, designed to help with ML workflows, coding, and troubleshooting in SageMaker Studio. Click on the highlighted icon to open the chat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*qEh1sJ3d1cYDMuz5cGjr9Q.png" /><figcaption>Type in question for Amazon Q</figcaption></figure><p>There are 2 ways to get support from Amazon Q. Either you can ask a generic question like</p><p>“Give me sample python cod to list buckets in my S3” or</p><p>Select any piece of code and click on the down arrow and ask contextual questions like “explain this piece of code”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*elMMaVXlbmTi49-am3OZ5Q.png" /></figure><p>I asked the python code to list the S3 buckets and trying it out gave me error (AccessDenied) because my SageMaker role is not having enough permissions to perform ListBuckets operation. After assigning the correct permissions, you will be able to list all your buckets.</p><p>Yes. Now we are good to go with our ML experiments. Go on, build your own ML story.</p><p>Sample Notebooks for experimenting:</p><p><a href="https://github.com/asnakhader/Notebooks">https://github.com/asnakhader/Notebooks</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a70f784efc04" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/how-sagemaker-helped-me-with-my-ml-experiments-a70f784efc04">How SageMaker helped me with my ML experiments</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating an interactive Data Visualization Dashboard with Amazon QuickSight]]></title>
            <link>https://awstip.com/creating-an-interactive-data-visualization-dashboard-with-amazon-quicksight-c03dd63d4c0e?source=rss-bc29b083f17a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c03dd63d4c0e</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Asna Siji]]></dc:creator>
            <pubDate>Wed, 27 Sep 2023 16:01:25 GMT</pubDate>
            <atom:updated>2023-09-28T18:48:52.975Z</atom:updated>
            <content:encoded><![CDATA[<h4>“We are surrounded by data, but starved for insights.”</h4><p>Effective data viz. helps organizations to looks at their large volume of data and derive meaningful insights which help in taking better business decisions.</p><h3>Amazon QuickSight</h3><p>Amazon QuickSight is a business intelligence (BI) service in the cloud that helps to create interactive visualization dashboards by connecting data from multiple sources. Data can be from AWS Cloud, third party sources, big data, spread sheet etc. It’s a fully managed service which can scale easily for thousands of users and can be deployed without worrying about an infrastructure to manage.</p><p>There is no code to write or no application to install. The viz. dashboards created can be published, shared and can be accessed from any device while ensuring secure access.</p><h3>Use Case</h3><p>After the COVID pandemic, many parts of the world went through serious energy crisis. This is caused by several factors including the rapid post-pandemic economic rebound and wars which caused the demand to outpace the energy supply. In this context, let’s take a use case of creating a viz. dashboard for world reusable share energy data.</p><p>Let’s try to answer.</p><ol><li><em>Compare the renewable energy share between selected countries in the 21st century.</em></li><li><em>Visualize the changes in renewable energy between 2 selected countries after 2010.</em></li><li><em>Develop an interactive visualization to compare the progression in renewable energy share between countries over time. Selecting a particular country should yield a detailed visualization.</em></li><li><em>What insight you can derive from this renewable energy data over the past 20 years?</em></li></ol><p>Legend: viz. -&gt; Visualization</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cn3BdZ8X9RzpdodV271Ziw.png" /><figcaption>Sample Illustration of the process</figcaption></figure><h3><strong>Data Set</strong></h3><p>Open data is <strong>data that can be freely used, re-used and redistributed. </strong>There are many sources to get open data and <a href="https://ourworldindata.org/">Our World in Data</a> is one of them. The data set used in this exercise is available <a href="https://github.com/asnakhader/DVA-Energy/blob/main/renewable-share-energy.csv">here</a>.</p><h3>Let’s Dive In</h3><h4>1. Signing up</h4><p>To use QuickSight, you need to sign up. When you first sign up for Amazon QuickSight, you get a free trial subscription for four users for 30 days. this <a href="https://docs.aws.amazon.com/quicksight/latest/user/signing-up.html">link</a> will help you with the process.</p><h3>3. Data Storytelling</h3><p>Data storytelling uses the data to create new knowledge and new decisions or actions. This helps in identifying the patterns in a dataset that we wouldn’t otherwise see. Also, this aids in explaining those patterns to a wider audience.</p><h4>3. 1. Start with Data</h4><p>Step 1: Log into the QuickSight Console and click on ‘Datasets’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bJ-vStR3FR3X54jS81n6ig.png" /></figure><p>The screen will display existing data sources. Click on ‘New dataset’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U4021uX3KQLjvsZJ4GeXSg.png" /></figure><p>QuickSight allow us to import data from a lot many sources. There are options to upload the file directly (ex:- csv, json etc.), S3, Athena(Query Service for S3) or connect to any database like Oracle, MySQL etc. That’s a lot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ia0afyw4BnxRDCGjqUBKg.png" /></figure><p>For this exercise, the data was obtained in CSV format and was uploaded to S3(AWS Simple Storage Service for object storage). This was extracted, filtered into a table structure using AWS Glue (Extract Transform Load — ETL Service) and saved as a table in Athena. I will be detailing about these steps in an upcoming blog post :-).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ySgJw3t9Xu8TUw5HAlBz5A.png" /></figure><p>I am selecting Athena as my data source. Fill in the DS details accordingly. Choose your database and table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*fXkfGpXVtNkxsypCWyc3ng.png" /></figure><p>Finish the data set creation by choosing the way in which you will query the data. I am going to directly query the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LGrg2-mgBpUX-_Afi8s4EA.png" /></figure><h4>3. 2. Filter (Analysis/Process)</h4><p>Now the data is imported, all the available fields in the data set is displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jii8SKXi3KH4gk8aG3IBFg.png" /></figure><p>Let’s apply some filters to the dataset. Let’s perform this analysis only for some selected countries say India, China, USA etc. To filter the data, Click on Filters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*StajTxMvblQorn4BLKC3VQ.png" /></figure><p>Add a custom filter list on the country code by including the codes that you would like to visualize. After applying necessary filters, click on ‘Publish and Visualize’ to start creating the graphs.</p><h4>3.3. Develop Visualizations</h4><p>In the Visualization page, there is option to select the type. We can either go for an Interactive viz. or can create paginated reports as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oIny7vwKFmfLtw9FI7Y89w.png" /></figure><p>All the fields from our data set is listed in the left corner. Now we can choose the type viz. we would like to have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*w-fz_oIdbNSLQfTTDREWmg.png" /></figure><p>How to select a chart?.</p><p>The decision can be made based on following parameters.</p><p>· <strong>Type of data being visualized</strong></p><p><em>— Numerical</em></p><p><em>— Non-numerical</em></p><p><em>— Time series</em></p><p><em>— Geospatial</em></p><p>· <strong>What is being visualized</strong></p><p>— Comparison</p><p>— Relationship</p><p>— Composition</p><p>— Distribution</p><p>As our data is primarily numerical on the renewable energy share of, countries, let’s go for a Comparison / Composition model analysis.</p><p><strong>Vertical Bar Chart</strong></p><p><em>Compare the renewable energy share between selected countries from 2000 to 2022.</em></p><p>We can select the fields in X axis (say year) and Y axis (Renewable Share) and group each bar based on the country code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*LaHqdYOxzIukLD8konpPiw.png" /></figure><p>The chart is displayed with the selected details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*quF-mVGroG436hzHQEBJ-w.png" /></figure><p>We can format the visual by editing the title, legends, color schema, sort order etc. by editing the visual.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*jqEmw4bs5tKYMh9Tlog7Yg.png" /></figure><p><strong>Area Line Chart</strong></p><p><em>Visualize the changes in renewable energy between 2 selected countries in the years after 2010.</em></p><p>An <strong>area</strong> chart is a graph that combines a <strong>line chart</strong> and a bar chart to show changes in quantities over time.</p><p>Let’s add additional filters on the data set to achieve this. We will add filter on entity (to select 2 countries say China and India) and year( to viz. data from years &gt; 2010).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*i7I-XFwu3QxFB9XOQzbcgg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*UQiXxVHH9gkG4MG7CFi3cg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*yMcKlfA1parFhXXWxrUDlQ.png" /></figure><p>Format the Visual by editing the title and adjusting the sort order of the years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*kSDD8i3aEvfE6dNvAlYErw.png" /></figure><p><strong>Adding Insight</strong></p><p><em>What insight you can derive from this renewable energy data over the past 20 years?</em></p><p>QuickSight derives meaningful insights from the data set. It analyses the data and provides a crisp statistical modelling which can be incorporated easily into visualizations.<br>Click on the insight tab. It displays the list of insights available. select the appropriate analysis to be added to the dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5-50boizyxq6XZKaOoLXog.png" /></figure><p><strong>Interactive Visualizations</strong></p><p><em>Develop an interactive visualization to compare the progression in renewable energy share between countries over time. Selecting a particular country should yield a detailed visualization.</em></p><p>A multi line chart is a type of chart used to show information that changes over time. Let’s select this chart type to draw the comparison.</p><p>QuickSight provides an option to duplicate the visual.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*uCZ1OSn08ZJhFx31uSj0cw.png" /></figure><p>Select that option from the first graph and change the graph type to draw the multi line chart. Quick and easy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*mIXD-W3RBxN1_tEOoyR-nQ.png" /></figure><p>Now, let’s bring some interaction. Clicking on each country’s line should bring up a detailed chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3JcNPBnZBlfRZP6CCsxcQ.png" /></figure><p>Click on ‘Actions’ to define a custom action. Define a filter action on the field ‘entity’ to bring another graph with details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZPgVG6Aj5YpvUToiEW41Q.png" /></figure><p>Now click on country ‘Unites States’. This brings up a detailed bar chart on the country’s data. Wonderful!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yuyCsSk27rVlrK9l8YY-zw.png" /></figure><p><strong>Save / Export / Share</strong></p><p>There are option to save the analysis, export the results and share it with team members. Look at the right corner for the details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aq31F_Ev9l_krDiV1xt0oA.png" /></figure><h4>3. 4. Stories</h4><p>Insights alone yield little value, if you don’t combine them with a story that conveys the significance of the data.</p><p><em>“It is predicted that we will run out of fossil fuels in this century. Oil can last up to 50 years, natural gas up to 53 years, and coal up to 114 years. Yet, renewable energy is not popular enough, so emptying our reserves can speed up”.</em></p><p>Hence, it is important that we strive to increase our share of energy production from renewable sources. Analyzing this data gives some hope in this field as we can see that the renewable share has increased considerable over the past few years.</p><p>Countries like China had made significant and steady progress where as many other countries still need to work seriously on this matter. Overall renewable share of Argentina looks promising but showing a decline of 3% compared to 2000, that to be looked upon.</p><p>Increasing the renewable share will have significant effect on countries economic growth and environment. Let’s hope we have access to more cleaner and greener energy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c03dd63d4c0e" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/creating-an-interactive-data-visualization-dashboard-with-amazon-quicksight-c03dd63d4c0e">Creating an interactive Data Visualization Dashboard with Amazon QuickSight</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Principles driving Dynamo: Amazon’s highly available key-value store]]></title>
            <link>https://awstip.com/principles-driving-dynamo-amazons-highly-available-key-value-store-3956212553cf?source=rss-bc29b083f17a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3956212553cf</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[dynamodb]]></category>
            <dc:creator><![CDATA[Asna Siji]]></dc:creator>
            <pubDate>Tue, 13 Jun 2023 17:19:08 GMT</pubDate>
            <atom:updated>2023-06-13T17:34:05.798Z</atom:updated>
            <content:encoded><![CDATA[<p>A sturdy database in the cloud. Dynamo was born out of the need for a highly reliable and ultra-scalable key/value database.</p><p>Dynamo handles with ease millions of checkouts in a single day and hundreds and thousands of concurrent active sessions.</p><p>This non-relational, or NoSQL datastore is core to the Amazon ecommerce operation, such as the shopping cart, session service, best seller lists, customer preferences, product catalogue, etc.</p><h3>CAP and Dynamo</h3><p>As dynamo is a distributed peer-to-peer key-value DB that runs on a cluster of servers, its is important to know where it stands in the CAP space.</p><h4>CAP Theorem (or Pick Any Two :-) )</h4><p>A distributed system can deliver only two of three desired characteristics: <em>consistency, availability, </em>and<em> partition tolerance</em> (the ‘C,’ ‘A’ and ‘P’ in CAP).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*Q0glIcfQVtlClMENh7x4Pg.png" /></figure><p>Dynamo falls under AP category according to CAP, ie. it offers high availability at the expense of consistency even if it was partitioned in some way. For instance, if one or more nodes went down by a network outage,<br>the remaining database nodes would remain available and continue to respond to requests for data. However, its data would become inconsistent across the cluster during the partitioned state.</p><p>It is an always-on datastore and replicates key ranges to multiple nodes . The consistency levels can be chosen for the read requests(eventually consistent to strongly consistent). Consistency determines the manner in which a successful write is reflected in a subsequent read operation. The eventual consistency option is the default in Amazon DynamoDB and maximizes the read throughput.</p><p>Let’s take a deep dive into the principles driving this amazing distributed database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*NhqwTne2qMEroqzVzhKCoQ.png" /></figure><h4>Partitioning and replication using <strong>consistent hashing</strong></h4><p>The key and value in dynamo DB is treated as opaque objects. A hash algorithm is applied on the key that generates 128-bit identifier, which is used to determine the storage nodes that are responsive for serving the key.</p><p><strong>Consistent hashing</strong></p><p>Distributed database systems require horizontal scale to ensure availability and some dynamic partition mechanisms to determine nodes for storing data.</p><p>The number of nodes changes dynamically. Nodes can get added or removed any time and hence modulo-based partition (Hash(key) % numberOfNodes) is not efficient. This will require rehashing and relocation of data resulting in lost time and reduced availability.</p><p>Consistent hashing is an answer to this need. Nodes assigned positions on the ring and each node responsible for data between it and its predecessor. If a node fails, only data held by it will be remapped. If a node is added, only data between its position and next data node remapped.</p><h4>Eventual consistency using <strong>object versioning</strong></h4><p>For high availability, each data item is replicated on multiple hosts. The number of replicas is configurable (N). The first replica is stored regularly with consistent hashing. The other N-1 replicas are stored in the N-1 physical successor nodes (called preferred list). The coordinator node is responsible for replicating that data items within its range. It replicates the keys at the N-1 successor nodes walking the ring clockwise.</p><p><strong>Lazy Replication and eventual consistency</strong></p><p>Any server in the preference list can handle read/write. Operation walks over the ring: try B, then C, then D…. The server that handles the request propagates the update.</p><p>With eventual consistency, replication is said lazy (asynchronous). The write operation returns immediately and does not wait until update is propagated to all replicas. This can lead to inconsistency. Subsequent read operations may return values that are not the latest write.</p><p><strong>Object versioning</strong></p><p>Write should succeed at all time as long as there is at least one server reachable. Example, ”add to cart” must always be written to database. However in case of partition, inconsistency occurs.</p><p>Object versioning consists in treating each modification to a data as a new <strong>immutable version </strong>of that data. Partition causes different versions of the object to be present in the system at the same time.</p><p>The system uses a reconciliation mechanism based on the vector clock technique to decide which is the latest version.</p><p><strong>Vector Clocks</strong></p><p>Vector clocks uses an algorithm to generate ordering of events in a distributed system. This can be used to analyze causality (which event caused a subsequent event).</p><p>It uses a logical timestamp called Lamport Clock. An integer propagated through the network with every message sent between nodes. Each node keep the highest Lamport Clock value it receives from any other node. Every time a write operation is done, the responsible node attaches to it its Lamport clock + 1.</p><p>Vector clocks are a more sophisticated variant of the Lamport Clock which gives us more guarantees, including knowledge of concurrency &amp; causal history.</p><p>A vector clock is associated to every version of a data. Examining the vector clocks, the system determines if two versions are from parallel branches or have causal ordering.</p><p>If all clocks of first object are &lt;= all clocks of second =&gt; First anterior to second, second can be ignored. Otherwise, it indicates a conflict and need reconciliation .</p><h4>Consistency among replicas using sloppy quorums</h4><h4><strong>Quorum based replica control</strong></h4><p>Quorum is the minimum number of votes to consider an operation in a networked database to be consistent. It is used to control replicas. Each replica (out of N) is assigned a read quorum (R) and a write quorum (W).</p><p>When a write happens, the coordinator for a data (usually the first in the preference list of N nodes), writes the update locally and issues an update request to all N-1 replicas. Then waits for W&lt;N replicas to acknowledge the update.</p><p>During a read operation, the coordinator requests versions from N-1 replicas and waits for R &lt;N responses. When (W+ R) &gt; N, consistency is assumed guaranteed. This protocol is called strict quorum.</p><p><strong>Sloppy Quorum</strong></p><p>Dynamo applied a modified version of the quorum protocol called sloppy quorum.</p><p>When a write operation is requested and that some (X&lt;N) nodes from the preferred list of the target key are unavailable, the system will write to the next nodes clockwise in the key ring.</p><p>Example, with N=3, a write to A,B,C where B and C would be unreachable would be done on D and E. In this case, W+R &gt; N is not a sufficient condition for consistency.</p><p>Dynamo uses hinted handoffs to solve this. The system informs D that the write was meant for B and informs E that the write was meant for C.D and E will keep polling B and C for availability. When B and C become available, D and E will send them the writes.</p><h4>Conflict detection and resolution using Merkle trees</h4><p>Dynamo uses vector clock to resolve conflicts while serving read requests. In situations where a replicas has many conflicts, it might take long time to resolve all conflicts using only vector clock. Dynamo uses other techniques to resolve conflicts in the background.</p><p>This is done by quickly comparing two copies of data residing on different replicas and find out which parts are different. Merkel trees are used for this.</p><p><strong>Merkel trees and Anti-entropy</strong></p><p><strong>Merkel trees is a t</strong>ree of hashes which is used to verify data blocs stored and transferred between computers</p><p>Its leaves are hashes of data blocs. Other nodes up are hashes of their respective children. The root is the top hash, similar to that obtained for the whole file.</p><p>The typical scenario consists of obtaining the top hash from a trusted source. The hash tree is obtained from untrusted peer. The top hash is compared to the root. If the tree is damaged, another tree is obtained from another peer. In addition, the damaged tree can be analyzed to find the damaged part.</p><p><strong>Anti-entropy</strong></p><p>It is the process of comparing replicas through Merkel trees. A Merkel tree is built for each key-range on each node. The root summarizes the data in each node. Merkel trees are exchanged between nodes instead of whole dataset of the replicas (that can be large).</p><p>Roots are first compared and if found equal, comparison stops. Branches are compared recursively. Ultimately, replicas know which parts are different. Only that data is exchanged for resolving the conflict. Trees needs to be recalculated when key ranges change, due to network nodes (servers) joining or leaving.</p><h4>Failure and membership managed using Gossip protocol</h4><p>In dynamo, there is no central node that keeps track of member node information . Dynamo uses GOSSIP protocol that enables node to keep track of the state information about other nodes.</p><p>For Example:- Which is reachable ? What key-range are they responsible for?</p><p>Gossip protocol is a peer-to-peer communication mechanism. Nodes periodically exchange state information about itself and other random nodes. Eventually any event (example, node down), will propagate through the system. All nodes become aware about all other nodes.</p><p><strong>Tail End:-</strong></p><p>Isn’t it wonderful to know the principles that is applied behind one of the most scalable and efficient databases in the cloud? It is just another epitome of the thoughts and efforts Amazon puts in delivering the best customer experience.</p><p>Reference and further reading:</p><p><a href="https://www.allthingsdistributed.com/2007/10/amazons_dynamo.html">https://www.allthingsdistributed.com/2007/10/amazons_dynamo.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3956212553cf" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/principles-driving-dynamo-amazons-highly-available-key-value-store-3956212553cf">Principles driving Dynamo: Amazon’s highly available key-value store</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Containerizing a Java Spring Boot application and deploying to ECS]]></title>
            <link>https://awstip.com/containerizing-a-java-spring-boot-application-and-deploying-to-ecs-3c7cc73f7c6?source=rss-bc29b083f17a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c7cc73f7c6</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[ecs-fargate]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Asna Siji]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 16:05:24 GMT</pubDate>
            <atom:updated>2023-05-04T14:45:53.789Z</atom:updated>
            <content:encoded><![CDATA[<p>Microservices architecture enables the deployment of independent and loosely coupled modules. Containerization of these microservices provides the added advantage and ensures that they works uniformly regardless of the infrastructure.</p><p>Spring Boot framework makes the development of web application and microservices faster. Amazon ECS (Elastic Container Service) is a container management service that makes the deployment and scaling of containers in the cloud hassle free.</p><p>Let’s take a deep dive into the implementation of containerizing a java spring boot application and deploying it to ECS. The sample architecture is as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*i193vlgxNsINJ0ixlmcIpA.png" /></figure><p>The details of the Spring Boot application is expressed in a docker file. This is converted into a docker image, tagged and later pushed to docker hub. When the user requests for a service, it is served by an application load balancer which in turn redirects it to an ECS target group. The ECS service has tasks which pulls the container image from docker hub and runs it as a container.</p><p><strong>Difference Between Monoliths / Microservices</strong></p><p>In microservices architecture, a single application is composed of many smaller services that can be independently deployed. This enables loose coupling and each application can be scaled independently. This eliminates vendor lock ins and each application can have its own tech stack.</p><p>With monolithic architectures, all processes run as a single big service. Because of this tightly coupled nature, scaling the application becomes difficult. This increases the impact of a single point of failure and making changes hard.</p><p><strong>Containers and Images</strong></p><p>A container is a standard unit of software that packages code and all its dependencies so the application runs quickly and reliably in all environments. Containers isolate software from its environment and ensure that it works uniformly regardless of the infrastructure.</p><p>A container image is a lightweight, standalone, executable package of software that includes everything needed to run an application from code to runtime, tools, system libraries etc. A container images when it is running is called a container. Examples of major container platforms are Docker, Rkt etc.</p><p>A container registry is a repository used to store and access container images. Example :- Docker Hub, Amazon ECR (Elastic Container Registry)</p><p><strong>Spring Framework</strong></p><p>Spring is a Java based Framework that enables developers to create modular applications with loosely coupled components. It offers a dependency injection feature that lets objects define their dependencies that the Spring will later injects into them. Define the dependencies and all the wiring will be done by the Spring framework.</p><p>Java Spring Boot (Spring Boot) is a tool that makes developing web application and microservices with Spring Framework faster and easier. It embeds a web server such as Tomcat and enables stand alone application development.</p><p><strong>Useful Docker Commands</strong></p><p>1. Use a Dockerfile to create an image with docker build<br>This command creates an image based on a Dockerfile. The -t switch assigns a tag to the build.<br><em>docker build -t mydockertest dockerfile.</em></p><p>2. Control container versions with docker tag<br>Tags provide version control in a container build. By default, every successful build becomes the most recent image.<br>To tag an image, use the following command:</p><p><em>docker tag IMAGE ID image/TAG.</em></p><p>3. Retrieve images with docker pull<br>Docker pull, pulls the container images to use from a repository or other designated source.</p><p>4. Stop container instances with docker stop<br>This Docker command enables users to stop specified container instances, without deleting them.<br><em>docker stop (container ID).</em></p><p>5. Check container status with <em>docker ps</em><br>Provides a list of currently available containers and their operational status.</p><p>Prerequisites: Implementation requires below setup to be available in your machine and all the system and environment variable configuration done.</p><p>Java 11 or above</p><p>An IDE of your choice (STS or Eclipse or IntelliJ)</p><p>Maven (build tool)</p><p>Docker</p><p>So, let’s get our hands dirty.</p><ol><li><strong>Create a sample spring boot application.</strong></li></ol><p>This application has a Rest Controller which responds to HTTP Get method via path <strong>‘/greeting’</strong> with a message that can be customized by passing a parameter. The sample code is available in GitHub.</p><p><a href="https://github.com/asnakhader/escdemo">GitHub - asnakhader/escdemo: Spring boot application with docker file</a></p><p><a href="https://github.com/asnakhader/escdemo">https://github.com/asnakhader/escdemo</a></p><pre>@RestController<br>public class ECSRestController {<br><br> private static final String template = &quot;Welcome to Containers, %s!&quot;;<br> private final AtomicLong counter = new AtomicLong();<br><br> @GetMapping(&quot;/greeting&quot;)<br> public ECSUserInput greeting(@RequestParam(value = &quot;name&quot;, defaultValue = &quot;Awesome&quot;) String name) {<br>  return new ECSUserInput(counter.incrementAndGet(), String.format(template, name));<br> }<br>}</pre><p><strong>2. Create the .jar (Java Archive) file</strong></p><p>Use any build tools to build the java application and create the jar file. I have used maven. This will create a jar file in the target folder specified.</p><p><strong>3. Create the docker file</strong></p><p>Create a docker file ‘Dockerfile’ at the root of the project. This will contain the instruction to create the image. Sample as follows.</p><pre>FROM openjdk:17 ---&gt; Specifies the base image<br>ADD target/ecs-0.0.1-SNAPSHOT.jar ecs.jar ---&gt; copy jar from target folder as ecs.jar<br>EXPOSE 8080 --&gt; expose port 8080<br>ENTRYPOINT [&quot;java&quot;,&quot;-jar&quot;,&quot;ecs.jar&quot;]--&gt; run ecs.jar when container starts</pre><p><strong>4. Build, Tag and Push the Image</strong></p><p>Build the container image using the docker build command.</p><p><em>docker build ecs-springboot-starter .</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SIIV-FNjdx7F66pMP21flg.png" /></figure><p>‘ecs-springboot-starter’ is the name of the image and ‘.’ indicates current folder. Dockerfile is present in the same folder.</p><p>Tag the image.</p><p><em>docker tag ecs-springboot-starter ecs-springboot-starter/latest</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ontkUSCC4-xmROIOFeAJg.png" /></figure><p>Push the image to DockerHub into a public repo.</p><p><em>docker push asnakhader/ecs-springboot-starter:latest</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gvNgvRFnBoglq8K8fnw3pQ.png" /></figure><p>Navigate to the DockerHub and see if the image is available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*EtQCcvV2sCvpL-2AgMqujg.png" /></figure><h4>Setting Up ECS</h4><p>Login to AWS management console and navigate to the ECS .</p><ol><li>Create a task definition</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uuOpF7pzhHs4icQ7YuVblQ.png" /></figure><p>A <strong>task</strong> is the unit of work within Amazon ECS and is made of a group of one or more containers that run together. These containers share a lifecycle by getting started and stopped together. A task is made from a <strong>task definition</strong> template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*sElrHvNzkIaowgEuyBz6Sg.png" /></figure><p>Create the task definition by providing a name. Specify the image URI and port mappings. We are going to use the port mapping 8080 which was exposed.</p><p>Under the environment details, specify the CPU, Memory and Task Execution Role required for running this task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*2DRqaKKI6R-ZxLC2CRcQew.png" /></figure><p>2. Create a cluster</p><p>A <strong>cluster</strong> is a logical grouping of services or standalone tasks. Create a cluster by specifying the name. Choose default VPC under Networking and Fargate option under Infrastructure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sZbLdS7itcnRvuIbpa2dvw.png" /></figure><p><strong>3. Security Group</strong></p><p>Create a security group, for the load balancer that is going to be created. The ALB security group should permit all inbound HTTP traffic from port 8080.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I-z-V2R5bLt6cxnEHV_eOQ.png" /></figure><p><strong>4. Create Service</strong></p><p>A <strong>service</strong> runs an application by maintaining a specified number of tasks from a specific task definition.</p><p>Under the newly created cluster, create a new Service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dw4BUQJ2ryjI3T2BxHlgfw.png" /></figure><p>Create the service by specifying the launch type as Fargate. Under deployment configuration, select application type as service , which is for tasks handling a long-running computing work that can be stopped and restarted. For example, a web application. Choose the task to run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*MVZtK8rjFJEZw1vwqSUsIw.png" /></figure><p>Under Networking, select default VPC and the default security group.</p><p>Under Load Balancing, create a new load balancer. Select the container port to balance as 8080(default port of spring boot) and add a new listener on port 8080.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*BfirzcWlCxK03vUo3bCmUQ.png" /></figure><p>Add the listener port for the ALB and specify the health check path as <strong>‘/greeting’, </strong>which is the path exposed by the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*9RI8NKqYzW57GXnL2sl85w.png" /></figure><p>Create the service. After sometime, the status will be updated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Wfk8mchJ5B1_UoIkDt4kQ.png" /></figure><p>Under the Logs tab, we can navigate to CloudWatch and see that the spring boot application has started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*byxsIDSAQB2t15zjckYGlg.png" /></figure><p>Navigate to the Networking tab and copy the DNS details of the load balancer created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K3oe1Lw8YgFGOmrkAoqLQw.png" /></figure><p>Hit the browser with the URL <em>dnsname :8080/greeting .</em></p><p>Walla!, you have the result displayed from the spring boot application which is running as a container in ECS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*OPoLCYMGzT1QRto0sbaKPQ.png" /></figure><p>Once done, set the desired task count zero and delete the services if not needed.</p><p>Hurray! We have successfully completed the containerization of a spring boot application and deployment in Amazon ECS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c7cc73f7c6" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/containerizing-a-java-spring-boot-application-and-deploying-to-ecs-3c7cc73f7c6">Containerizing a Java Spring Boot application and deploying to ECS</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL / NoSQL. What’s your take?]]></title>
            <link>https://awstip.com/sql-nosql-whats-your-take-1be662f067ab?source=rss-bc29b083f17a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1be662f067ab</guid>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Asna Siji]]></dc:creator>
            <pubDate>Mon, 30 Jan 2023 15:39:23 GMT</pubDate>
            <atom:updated>2023-02-02T15:03:53.416Z</atom:updated>
            <content:encoded><![CDATA[<p>Applications have evolved considerably in the past few years and so do the way in which data is stored. Apart from the SQL databases where many organizations used to persist data, fast performing NoSQL databases are also evaluated now as a storage option based on the merit of the requirement.</p><p>Consider this hypothetical scenario where you are approached by a start-up firm to suggest a storage solution for their new venture. What will be your take on this?</p><h3>Background</h3><p>SQL databases have a predefined schema. They are relational (stores and provides access to data that are related to one another) and uses structured query language (SQL) for data manipulation. Examples:- <strong>MySQL, Oracle, PostgreSQL</strong> etc.</p><p>NoSQL (Not only SQL / Non-SQL) databases are non-relational. NoSQL databases have dynamic schemas for data that is not very structured. Examples:- MongoDB, Couchbase</p><h3><strong>Selecting your database</strong></h3><p>The choice of the database solution will be driven by the requirements. Hence it is essential to have a clear understanding of the business scenario / use case. Conducting workshops or familiarization sessions with the client will help to derive the best solution to meet their needs.</p><p>Listed below are some key pointers that can be assessed to draw a solution.</p><p><strong>Type of Data</strong><br>1. Structured Data: Structured data has predefined structure and can be easily mapped to columns and rows in a database. Databases that hold tables in this form are called relational / SQL databases.</p><p>2. Semi-Structured like JSON: Semi structured data is not bound by strict data model; but still has some structure to it. A NoSQL database will be ideal for such data.</p><p>3. Unstructured Data like images, videos: Information is not organized in a pre defined manner. They do not have any pre defined structure. An object store like Amazon S3 (Simple Storage Service) will be the apt solution here.</p><p><strong>Type of Operation / Transactional Support</strong><br>If the business operation requires the highest levels of transactional support like OLTP (Online Transaction Processing) systems, SQL databases can be considered.</p><p><strong>OLTP systems</strong> are meant for capturing transaction data in a database. <br>Each transaction may involve multiple rows in a database made up of multiple fields or columns. If a transaction fails, data integrity need to be ensured.</p><p>Example:- A payment processing system handling accounts, debit, and credit information. Go for an SQL database here as all of the major relational DBMSs adhere to the ACID [Atomicity, Consistency, Isolation and Durability] principles.</p><p><strong>OLAP Systems</strong> applies complex queries to large amounts of historical data obtained from multiple sources like data analytics, OLTP systems etc. These type of systems are also ideal candidates for a relational database.</p><p>On the other hand, if the system is not having strongly consistent transactional requirements, NoSQL databases can be considered.<br>Example:- Systems displaying features of a product, in which presentation of information is more important.</p><p><strong>Frequency of Change</strong><br>Consider a product catalogue. A product like phone will have colour, screen size, warranty, camera etc. as features. This is totally different from another product like a shoe. When a new product is launched, it may have a totally different set of features. Fitting all this frequently changing information in a strict schema structure like a SQL database is difficult.<br>Here, No SQL can be considered.</p><p><strong>Performance/Speed</strong><br>NoSQL enables faster, more agile storage and processing. Speed makes NoSQL databases generally a better fit for use cases where the system is demanding better read performance.</p><p><strong>Complex Operations</strong><br>If the application demands complex operations like joins including multiple tables, procedures etc. SQL database is a sure-fire solution.</p><p>Example:- Reports generated by fetching data joining multiple data sets spanning multiple tables.</p><p><strong>Costing Considerations</strong></p><p>Maintaining high end commercial SQL databases can be expensive. They require the purchase of licenses and powerful hardware to scale. NoSQL databases offers better resource allocation to minimize costs.</p><p><strong>Flexibility</strong></p><p>NoSQL databases offers horizontal scaling. This refers to bringing on additional nodes to share the load. In contrast, SQL databases can be scaled vertically which means increasing the processing power of a single server, which has limitations. Horizontal scaling is difficult with relational databases due to the difficulty in spreading out related data.</p><p>Because of this, NoSQL databases are best fit for large volumes of rapidly changing data, the ones that demand flexible data model and agile development.</p><h3><strong>Major types of NoSQL Data Storage</strong></h3><p><strong>Key-value store</strong><br>The data is organized into a dictionary of key-value pairs, where each item has a key and a value. Example:- Couchbase, Redis. Use cases : Caching, storing user session information.</p><p><strong>Document store</strong></p><p>Used for managing semi-structured data and storing it as documents. Example :- MongoDB Use Case: Storing XML, JSON documents</p><p><strong>Wide-column store</strong><br>Information is stored in columns, enabling users to access only the specific columns they need. Example:- Apache Cassandra. Use Cases : Real-time data analytics, Big Data</p><p><strong>Graph store</strong><br>Data is retained in the form of a knowledge graph. Data elements are stored as nodes, edges and properties. Example:- Amazon Neptune. Use Cases: Storing network of connections</p><h3><strong>Mapping these to AWS Space</strong></h3><p>AWS offers a variety of purpose built databases to match individual business needs. Below illustration shows some of the main offerings from AWS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*ToPapnpRXbmd2kw-m6ekJw.jpeg" /></figure><p>For relational data sets which requires analytical processing , Amazon Redshift is a good option. For transactional use cases of relational data, AWS offers 2 flavours. Amazon Aurora is best fit as a fully managed, high performance data store for MySQL and PostgreySQL work loads. In addition to this, Amazon RDS can support most of the high end commercial RDBMS like Oracle, Maria DB and SQL Server.</p><p>For non relational use cases, based on the data storage requirement, AWS offers Neptune(Graph Store), Document DB(Document store which is MongoDB compatible), Keyspaces(Wide column store, Cassandra compatible), DynamoDB (Key value Store) etc. There are in memory storage solutions like ElastiCache and time series storage like Amazon Timestream as well.</p><h3>Tail End</h3><p>There are many flavours of relational and non relational databases available today. However clear understanding of the requirement is needed to select the best storage that meets the business needs. In all ways, requirement drives the solution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1be662f067ab" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/sql-nosql-whats-your-take-1be662f067ab">SQL / NoSQL. What’s your take?</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hosting a Cost Effective Serverless Secured Static Website in AWS.]]></title>
            <link>https://awstip.com/hosting-a-cost-effective-serverless-secured-static-website-in-aws-4226b721366b?source=rss-bc29b083f17a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4226b721366b</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloudfront]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Asna Siji]]></dc:creator>
            <pubDate>Sun, 18 Dec 2022 06:20:11 GMT</pubDate>
            <atom:updated>2022-12-22T16:27:23.346Z</atom:updated>
            <content:encoded><![CDATA[<p>The essence of cost optimization in cloud relies on opting for the right services and right plans. Cloud can be expensive if not used wisely.</p><p>When enquired by a small scale start up builder firm to host their website with lot of emphasis on cost savings, an obvious choice was static website hosting in S3. Hosting your personal secured static website can be accomplished at a cost of less than 1$ per month.</p><p>Let’s have a dive into the details of the implementation and AWS features to leverage for an optimal solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*F2oNOTrIqIl6K1yx9Pr4hA.png" /></figure><p><strong>Featured AWS Services</strong></p><ol><li>AWS Pricing Calculator / AWS Budgets / AWS Free Tier — [Estimation and Cost Monitoring]</li></ol><p>2. S3 — Simple Storage Service [Object Store]</p><p>3. Route 53 — DNS [Domain Name System] service</p><p>4. AWS Certificate Manager — Certificate Authority</p><p>5. Cloud Front — CDN [Content Delivery Network]</p><p>First, we need a domain name for our website. Domains can be purchased from Route 53 (AWS DNS) and that makes the set up a lot more easier. It is also possible to buy your domain from other domain registrars, say namecheap.com. This discussion is focused on the later approach, ie. buying domain from external registrar.</p><p><strong>Step 1: Create a new AWS account</strong></p><p>Signing up for a new AWS account unboxes lot of free tier services for you. AWS has a wide range of services offered under free tier, some are short term trials, some free for 12 months and there are always free services as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9lHmCAVQwKe5koVJ2KKorA.png" /></figure><p>The main services which interests us in the current context are S3 and Cloud Front.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*rGnUPnWRpgYV_3N7-Mu-Yw.png" /></figure><p><strong>Step 2: Let’s estimate</strong></p><p>AWS Pricing Calculator is an efficient tool to estimate the cost of our AWS solution. We can pick the services we like to add to our solution, its configuration and the preferred region. Pricing Calculator will provide an estimate in terms of the monthly and yearly spend.</p><p>So for our static website, the main components are going to be the S3 bucket and Route 53 (DNS) hosted zones.</p><p>Route 53 services are not covered under AWS Free Tier. There is a minimal charge to use them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rtKhHNmwSI84uhwaoK5zdQ.png" /></figure><p>So the total estimate for both services are coming around 0.5$ / month.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w2www46n9CHAHoANv9iG_g.png" /></figure><p><strong>Step 3: Turn the monitoring On!</strong></p><p>The first thing to do after an AWS account creation for me is to keep the budgets on. AWS Budgets allows to set custom budgets to track costs and usage. When threshold is exceeded, you will be alerted via email or SNS notification.</p><p>Create a monthly cost budget with a minimal amount and provide the email ids to send the notification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*vEXXbrT7MP14mepq0Nqx3A.png" /></figure><p><strong>Step 4: Create an S3 Website</strong></p><p>The most cost effective way to host a static website in AWS is to leverage the S3 (Simple Storage Service) bucket’s hosting feature. More details about this can be found <a href="https://medium.com/aws-tip/hosting-a-static-website-in-amazon-s3-cors-and-more-b4ac2118c1be">here</a>.</p><p><a href="https://awstip.com/hosting-a-static-website-in-amazon-s3-cors-and-more-b4ac2118c1be">Hosting a Static Website in Amazon S3, CORS and more.</a></p><p>Note : Always create the bucket with the same name as your website address. For example if you want to host your website from <a href="http://www.example.com,/">www.example.com,</a> create a bucket with name &#39; <a href="http://www.example.com,/">www.example.com</a>&#39; to hold all of the static content ; and create another bucket ‘<em>example.com’</em> and redirect traffic to ‘<a href="http://www.example.com,/">www.example.com</a>’.</p><p><strong>Additional Note:</strong> If you want your traffic to be served from example.com, just reverse the above steps while bucket creation]</p><p><strong>Step 5: Purchase a domain</strong></p><p>There are many domain registrars available for you to pick from. Route 53 aka DNS service offering from AWS also provides domain naming services for you. Selecting Route 53 as DNS makes the configuration and wiring steps easier. But for the purpose of this case study, let’s buy domain from an external DNS provider, namecheap.com.</p><p>Sign up / in to your name cheap account and purchase the domain. After the registration is successful, your domain will be listed in your dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*OkSAifd-c5mG413lHS4JLw.png" /></figure><p><strong>Step 6: Creating Route 53 Hosted Zones</strong></p><p>First, lets follow the steps to access this website from http protocol without CloudFront (not secured). A hosted zone is a collection of records, belonging to a single parent domain name that can be managed together.</p><p>Navigate to the Route 53 dashboard and create a hosted zone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*52VRFnPJp4ZfYrxHEQCttQ.png" /></figure><p>Enter you domain name (example.com) and create a public hosted zone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*I95AckvIy_HzuJM4wVvjPg.png" /></figure><p>This will create 2 records of type NS (Name Server) and SOA (<strong>start of authority).</strong>For each public hosted zone that you create, Amazon Route 53 automatically creates this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*2cj8d8-W-ZRJpP4k_i7Qww.png" /></figure><p>You will get a set of 4 values in the NS record type. Keep this handy.</p><p>Now we need to create two Type A alias records to point to the s3 end point that was created before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SY99A-Ua4s9PwrhBxxhpJQ.png" /></figure><p>For the first record, keep the subdomain field as blank, for the second one keep it as ‘www’. In the route traffic field, select the s3 website end point that was created before.</p><p><strong>Step 7: Link domain to your website</strong></p><p>Navigate to your namecheap account. Your purchased domain will be listed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkSAifd-c5mG413lHS4JLw.png" /></figure><p>Click on Manage. From the NameServers sections, select Custom DNS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zwOUdbfLIZXAQ1UWroNiTA.png" /></figure><p>Enter the name server values obtained in previous step here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Luxs0TogMbcfImtUlKheWg.png" /></figure><p>The sample values will look like this. Please note to remove any periods (.) at the end.</p><p><em>ns-1111.awsdns-00.org<br>ns-1234.awsdns-11.co.uk<br>ns-222.awsdns-22.com<br>ns-333.awsdns-33.net</em></p><p>The DNS propagation can take few hours. Wait for some time and try accessing your website with the purchased domain name (for example:- http://example.com). Yay! your website is up and running.</p><p><strong>Word of Caution</strong> : While accessing the website, if you end up in below error, it means that your bucket name is not correct.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*QPuIWpHDveHogdOYQL2pxQ.png" /></figure><p>If you are trying to access your website like <a href="http://www.example.com,/"><strong>www.example.com,</strong></a><strong> </strong>the name of the bucket should also be the same. Some things we learn the hard way. :)</p><p><strong>Step 8: Request for a certificate in AWS Certificate Manager(ACM)</strong></p><p>Now we want to make this website secured and enable access via https as well.</p><p>AWS Certificate Manager (ACM) can provide public and private SSL/TLS certificates for use with AWS services . It removes the overhead of purchasing, uploading, and renewing SSL/TLS certificates and the public certificates that we are going to use here is totally free. That’s amazing.</p><p>Navigate to the ACM service and request for a certificate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p7DH4U3yoGzpdSuurW-Fqg.png" /></figure><p>Select the certificate type as public.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YUXIVpgkvE7gqmFr9FaG5Q.png" /></figure><p>You can select the validation type as DNS / Email. Choose the DNS validation type which is the recommended one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dzRDzwreWWGQLumoKw9ggw.png" /></figure><p>This will generate a CNAME record that needs to be added in the DNS configuration of the external registrar. Please refer the sample <a href="https://postimg.cc/Y4GzZnRr">here</a>.</p><p>The CNAME comes as a name value pair. For example :-</p><blockquote>Name : _cff0cda88701846cbe7a34cd737378e2.example.com</blockquote><blockquote>Value : _490287b8f448e2cca3862ebb4a51591.acm-validations.aws.</blockquote><p><strong>Step 9: Validate the certificate with your registrar</strong></p><p>Namecheap does not permit DNS validation if we are using Custom DNS. So change the DNS setting back to Basic DNS (if not so) before proceeding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*roCjoIaCjltc3dCbDwABJQ.png" /></figure><p>Now navigate to the Advanced DNS tab and select the ‘Host Records’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cAe5Gi8vFQCrtICUVgmFPg.png" /></figure><p>Create CNAME records with host as (the name obtained from AWS without the domain name, ie. <strong>_cff0cda88701846cbe7a34cd737378e2 in below example) </strong>and value (without period at the end). Please refer sample <a href="https://postimg.cc/Y4hdkqrw">here</a>.</p><blockquote>Name : <strong>_cff0cda88701846cbe7a34cd737378e2</strong>.example.com</blockquote><blockquote>Value : <strong>_490287b8f448e2cca3862ebb4a51591.acm-validations.aws</strong></blockquote><p>The DNS verification can take some time. Once completed, the certificate will be listed under ‘Issued’ status in ACM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3eM7IHPa0jVOwrtOxMjPsQ.png" /></figure><p>Once the verification is done, you can revert back to Custom DNS option in namecheap account and provide the name servers again as described in Step 7.</p><p><strong>Step 10: Create a Cloud Front Distribution</strong></p><p>Cloud Front is the Content Delivery Network service provided by AWS which securely deliver content with low latency and high transfer speeds. It is the best option to deliver secure fast websites and with AWS Free Tier, we get 1 TB of data out free. Cool!</p><p>Navigate to Cloud Front and create a distribution. Select the origin domain as the s3 website end point that was created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XZ6ZXIT-RC1yEBF24lnLDQ.png" /></figure><p>You can choose the origin access as public(bucket should be public), origin access control settings or by creating an Origin Access Identity particularly for Cloud Front to access the S3 bucket. By choosing the latter 2 options, we can have a private bucket which allows only Cloud Front to access content from it and that is more secure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*wyd_qojrdu1bpTzitGY3ng.png" /></figure><p>Let’s create an OAI and allow AWS to update the bucket policy for us to enable Cloud Front OAI to access the bucket. If the bucket was public before, you can turn that off now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*BAG9pgY9IEaZV_5qFTK1Zg.png" /></figure><p>Choose the custom SSL certificate option and select the certificate that was issue before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*gPgU6-FOKUMq_ybnkTJ48g.png" /></figure><p>Choose security policies and supported http versions to complete the set up.</p><p><strong>Step 11: Link Cloud Front to Route 53</strong></p><p>Navigate to the hosted zone that was created in Route53. If the type A Alias records which points to the S3 endpoint is present, those can be removed and new ones which points to the Cloud Front distribution can be created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OGwvPrAWs9TgB5brwXliNw.png" /></figure><p>Alternatively, the existing ones can be edited to point to Cloud Front as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xFz3yAPljorAt3N7yUXtew.png" /></figure><p><strong>Step 12 : Your Secured Website is Up and Running!</strong></p><p>Yay! You can access your website under the registered domain name in a secured way. Wonderful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*91GLR8kcsgyy5ZBxLLYCzw.png" /></figure><p>Now coming to the interesting part. The Pricing Calculator estimated the monthly cost as 0.53$ and how much was the actual?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*YyIl0LC7u_wdj9_lrwecdA.png" /></figure><p>It was 0.59$. Cool. Go ahead. Host your secured static website for less than a dollar per month.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4226b721366b" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/hosting-a-cost-effective-serverless-secured-static-website-in-aws-4226b721366b">Hosting a Cost Effective Serverless Secured Static Website in AWS.</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving it the AWS way.]]></title>
            <link>https://awstip.com/solving-it-the-aws-way-b7bb7a9e82d4?source=rss-bc29b083f17a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7bb7a9e82d4</guid>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws-textract]]></category>
            <dc:creator><![CDATA[Asna Siji]]></dc:creator>
            <pubDate>Mon, 26 Sep 2022 09:18:34 GMT</pubDate>
            <atom:updated>2022-10-01T11:24:01.591Z</atom:updated>
            <content:encoded><![CDATA[<p>My kids love to write and draw. To reduce the screen time and to improve their writing skills, I encourage them to scribble their thoughts on paper. So far so good. But keeping the hard copies is a bit difficult. I would like to convert these handwritten notes to soft copies in textual format [Foreseeing some Kindle plans, when it becomes a small little bundle :-) ].</p><p>Let’s solve this the AWS way.</p><p><strong>Solution Description</strong></p><p>Let’s build a solution leveraging S3 replication / event notification, a serverless compute layer with lambda function and Textract. The sample architecture looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*5VowWZmJ3JrQEHJXwsvDxQ.jpeg" /></figure><ol><li>Two buckets are created, source bucket and destination bucket. Source bucket will hold the images user is giving as input.</li><li>The drawings are uploaded to the source bucket with tags say ‘picture’. S3 same region replication is enabled on the source bucket on the configured tag.</li><li>A folder is created say ‘story’ in source bucket to upload the handwritten text. S3 event notification is enabled on the source bucket on prefix ‘/story’, in such a way that any upload to this folder will create an event notification.</li><li>A lambda function is set up to receive these event notifications. The lambda function will invoke Textract passing the uploaded image as input. Textract will scan the image and return the identified words in the document to the lambda function.</li><li>Lambda function logic will consolidate it into sentences and save it to destination bucket as text.</li><li>Event notification is enabled on the destination bucket to invoke SNS to send external emails once the process is completed.</li></ol><h3><strong>Serverless Features on Spot Light</strong></h3><ol><li><strong>S3 Replication</strong></li></ol><p>Amazon Simple Storage Service (S3) can automatically replicate S3 objects to help you reduce costs and protect data.<br>Two main replication options are:<br>Cross-Region Replication (CRR) — copies S3 objects across multiple AWS Regions.<br>Same-Region Replication (SRR) — copies S3 objects between buckets in different availability zones (AZs), in the same region.<br>S3 also offers a Replication Time Control (RTC) that guarantees object replication in less than fifteen minutes.</p><p><strong>2. S3 Event Notification</strong></p><p>Amazon S3 Event Notifications feature helps you to receive notifications when certain events happen in your S3 bucket. <br>To enable this, a notification configuration to be added with events details that you want S3 to publish and a destination where you want S3 to send the notifications.</p><p><strong>3. Computation Layer with Lambda</strong></p><p>AWS Lambda is the serverless event-driven computation layer that runs your code without provisioning or managing servers</p><p><strong>4. Textract</strong></p><p>Amazon Textract is a service that can be used to automatically extracts text, handwriting, and data from documents /images.<br>It uses advanced machine learning (ML) algorithms to achieve this.</p><p><strong>5. SNS</strong></p><p>Amazon Simple Notification Service (Amazon SNS) is a fully managed messaging service. It enables communication between applications with a pub/sub functionality. It also supports application to person communications by sending messages to users at scale via SMS, mobile push, and email.</p><h3>Let’s Build.</h3><p><strong>Step 1 : Create Buckets</strong></p><p>Navigate to the S3 console and create 2 buckets in the same region, say ‘<a href="https://s3.console.aws.amazon.com/s3/buckets/textractsourcebucket?region=ap-south-1">textractsourcebucket</a>’ and ‘<a href="https://s3.console.aws.amazon.com/s3/buckets/textractdestinationbucket?region=ap-south-1">textractdestinationbucket</a>’ with versioning enabled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_lA2_LAislVNY70mlB7cAA.png" /></figure><p><strong>Step 2 : Creating Roles</strong></p><p>We need 2 roles, one for S3 replication and another for lambda function.</p><p>Role 1 : Let the S3 replication feature itself create a new role for this. Skip this for now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FQoNcDoPePEQX5W1jd89eg.png" /></figure><p>Role 2 : Create a role with Cloud Watch, Textract and S3 access for lambda.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*oFDcDUPlZhwj8Sv0ZbMsVA.png" /></figure><p><strong>Step 3 : Enabling replication</strong></p><p>Navigate to the Management tab of the source bucket and create replication rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*grziuXUClUL6JXWfBTQHUw.png" /></figure><p>Create replication rule by providing a name. Enable versioning if you have not enabled it before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-cG0jy4OK0F5FtJKY8fK0w.png" /></figure><p>We are filtering the replication items based on tag. The drawings will be uploaded with a tag ‘picture’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*GTezDrte_XwHnus-KfK-uA.png" /></figure><p>Select the destination bucket created before in Step 1 as destination.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*5TNtmWNNE0YstOI6c4F0DA.png" /></figure><p>Allow S3 replication feature to create a role for you with required permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*4Sn6qHzXo6Vbc65v0JZUng.png" /></figure><p>Save the replication configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*O6pPmrF8TW666xoUgxvblA.png" /></figure><p>You can choose not to replicate existing objects.</p><p><strong>Step 4 : Creating lambda function</strong></p><p>The lambda function will receive the event notification from S3 when handwritten note is uploaded. It will call Textract to extract the textual details and consolidate it and save to destination bucket as text file.</p><p>Navigate to lambda console and create a new function with run time as Node.js.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qt2dd2ENAfPp1Vas5FiPaA.png" /></figure><p>Change default execution role as the existing role and select the role created in Step 2 Role 2 for lambda. Copy the contents of index.js from below GitHub repo (after making modification, like region, bucket name etc. if any) to the code section of lambda.</p><p><a href="https://github.com/asnakhader/textract">GitHub - asnakhader/textract: Convert handwritten image to text</a></p><p>Create a test event to test the function. Sample given below (obtained from Cloud Watch logs when the S3 event notification happens).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c555b004cd85598cb01dd24ab0ba0d32/href">https://medium.com/media/c555b004cd85598cb01dd24ab0ba0d32/href</a></iframe><p>Test the function to see if return a success response.</p><p><strong>Step 5: Setting up S3 Event Notification</strong></p><p>Navigate to the S3 console and select the source bucket.</p><p>Create a folder, say ‘images; to upload handwritten notes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7I5KpewilJt8vULoYdvycw.png" /></figure><p>Navigate to the ‘Properties’ tab and create event notifications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BIot9xcrFAqA6FZPuuF6mg.png" /></figure><p>Create event notification with prefix as /images and suffix as .jpg as we the handwritten notes will be uploaded to this folder as .jpg image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fr99RlkdMpx0DYie3-nDkA.png" /></figure><p>Enable this for all object creation events and set the destination as lamda function created before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*PPXxJtfASdbwnJ0kUq-HVA.png" /></figure><p><strong>Step 6 : Create SNS Topic</strong></p><p>Navigate to the SNS Console and create a topic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BKtue3ogt_WIDmJbZQffrQ.png" /></figure><p>Navigate to the Access Policy tab and attach a policy which allows the S3 bucket to publish messages to SNS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*iL2uXoXG8S8kjZ2q815fpQ.png" /></figure><p>Sample policy is given below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9ff312f19fbce767d9a86034a6fd304/href">https://medium.com/media/b9ff312f19fbce767d9a86034a6fd304/href</a></iframe><p>Create a subscription for this topic with an email end point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6TjATlrFJOFsOdUIz4UXQ.png" /></figure><p>Confirm the subscription by accepting the invitation received in email.</p><p><strong>Step 7 : Setting up email notification for process completion</strong></p><p>Navigate to the destination bucket and create event notification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mT0J8cMQMFjXaehwdjycIg.png" /></figure><p>Select destination as the previously created SNS topic and save changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*WIKYEvEICS6yHeODnzJXmA.png" /></figure><p><strong>Step 8 : Testing</strong></p><p>Navigate to S3 Source Bucket and upload a drawing with tag as ‘picture’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IzIaX0Y3tC4yDwPdBXWPAg.png" /><figcaption>Source Bucket</figcaption></figure><p>Upload the handwritten text images in folder ‘/images’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2O5UHI0cJ_RG6V_cmtYWAQ.png" /></figure><p>Navigate to destination bucket and check the details. S3 replication has replicated the uploaded image with tag ‘picture’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qXij0bUVYeesuMwOn0CCCg.png" /></figure><p>Check the details inside the image folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bA54vOqe2DuvGDrBgbL1lA.png" /></figure><p>The lambda function with Textract has converted the handwritten notes uploaded as .jpg images into textual format. An email notification is received indicating process completion. Woohoo!</p><p><strong>Final Product</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lgpqo-JKnjgciCJRyQfzUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8y4ME_ai73EO7NMF4QkH6w.png" /><figcaption>Excuse the spelling / grammar mistakes pls. Big shoutout to Textract for reading this :-)</figcaption></figure><p>At the end of the day, the whole purpose of technology is to ease human lives and save it from monotonous and repetitive work. Do you agree?</p><p><strong>Tail End:</strong> Now that the kids have taken the pictures of all their stories and given to me, the ball is in my court to convert it and keep it safe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WQ9ex20sZBIrbT5HMUauqg.png" /></figure><p>I get task assignments from them with reminders set :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7bb7a9e82d4" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/solving-it-the-aws-way-b7bb7a9e82d4">Solving it the AWS way.</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Auto scaling with custom metrics.]]></title>
            <link>https://awstip.com/auto-scaling-with-custom-metrics-477fb67e6814?source=rss-bc29b083f17a------2</link>
            <guid isPermaLink="false">https://medium.com/p/477fb67e6814</guid>
            <category><![CDATA[autoscaling]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Asna Siji]]></dc:creator>
            <pubDate>Sun, 28 Aug 2022 06:56:48 GMT</pubDate>
            <atom:updated>2022-08-29T18:23:20.006Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the primary shortcomings of the traditional on premise infrastructure is its inability to scale on demand. Many data centers have unused capacity in store anticipating spikes in load / usage.</p><p>Auto Scaling or the ability to automatically adjust capacity to maintain predictable performance thus becomes a primary advantage of using a cloud infrastructure.</p><p>AWS Auto Scaling enables to setup application scaling for multiple resources across multiple services including virtual servers (EC2),container tasks(ECS) or NoSQL database like Amazon Dynamo DB. Amazon EC2 Auto Scaling helps to automatically launch or terminate EC2 instances as per the conditions defined.</p><p>The most common use case in EC2 Auto Scaling is to configure CloudWatch alarms to launch new EC2 instances when a specific metric exceeds a threshold. This can be done with pre-defined metrics like CPU Utilization, Network In/Out or Customs metrics like memory usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*GoPd2-qijOb3TLAiL76pIA.png" /></figure><p>Let’s setup EC2 Auto Scaling with a custom metric.</p><h4>Step 1 : Launch an instance</h4><p>First, launch an Amazon EC2 Linux instance with default configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*LFnpNtSXVOmkXYFSA3VKEQ.png" /></figure><h4>Step 2 : Create a role with CloudWatch access</h4><p>Navigate to IAM and create a role which can be assumed by the EC2 instance which enables Cloud Watch access for EC2. Select the Trusted entity type as AWS service and Use case as EC2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MJuPvo5ZTiwRxjW6d6CtGg.png" /></figure><p>For the purpose of this demo, I am assigning full access. But always remember ‘PLP’ , Principle of Least Privilege.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KsasnkgC0qifcmMyOIxhuA.png" /></figure><p>Navigate to EC2 instance dashboard and assign this role to the instance by selecting the instance and modifying IAM role under Security option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TkJu4mfErMEAZO_vveiORA.png" /></figure><p>Modify the role by selecting the role created in previous step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AHXSfwgOqj69YI0dWMhhdA.png" /></figure><h4>Step 3: Install agents</h4><p>Connect to the instance with EC2 Instance connect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*TIfhlPu5QWrLDBV25V_OtQ.png" /></figure><p>Its time to leverage some of your Linux admin skills :)</p><ol><li>Install Cloud Watch agent to send the EC2 instance metrics to CW for monitoring. The CloudWatch agent is available as a package in Amazon Linux .</li></ol><blockquote>sudo yum install amazon-cloudwatch-agent</blockquote><p>2.It’s important that EPEL repo is enabled in Linux 2 AMI by running</p><blockquote>sudo amazon-linux-extras install epel -y</blockquote><p>3.Let’s create some stress.Install the stress package by</p><blockquote><em>sudo yum install stress -y</em></blockquote><p>4. Create the agent configuration file</p><p>The agent configuration file is a JSON file that specifies the metrics and logs that the agent is to collect, including custom metrics. We can create it by using the wizard or manually from scratch. We are creating a sample file as it gives more control over the metrics collected and can specify metrics not available through the wizard.</p><p>Commands to create an agent config file named <em>amazon-cloudwatch-agent.json</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aca736d96b13a77a464c7fe23d087451/href">https://medium.com/media/aca736d96b13a77a464c7fe23d087451/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*O0_cyxwFwo7EDdWHKuVOsg.png" /><figcaption>Sample agent config file content</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/011f2c2f828201fc8c161469883f36af/href">https://medium.com/media/011f2c2f828201fc8c161469883f36af/href</a></iframe><p>Any time you change the agent configuration file, you must then restart the agent to have the changes take effect. After you have created a configuration file, you can save it manually as a JSON file and then use this file with the agent on your servers.</p><p>5. Start the CloudWatch agent on the server.</p><p>Enter following command. Replace configuration-file-path with the path to the agent configuration file.</p><blockquote>sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:<strong>configuration-file-path</strong></blockquote><p>In this command, -a fetch-config causes the agent to load the latest version of the CloudWatch agent configuration file, and -s starts the agent. Example :</p><p>sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:amazon-cloudwatch-agent.json</p><p>This file is the amazon-cloudwatch-agent.json if you created it manually as per above step 4.</p><h4>Step 4: Stop the server and create an AMI</h4><p>Note: AMI means Amazon Machine Image which is a customization of an EC2 instance. We can add own software, configuration, operating system etc. AMI is built for a specific region. This helps for faster boot / configuration time because all your software is pre-packaged.<br>EC2 instances can be launched from <br>• A Public AMI: AWS provided<br>• Your own AMI: you make and maintain them yourself (like what we are doing now)<br>• An AWS Marketplace AMI: an AMI someone else made</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Le8z-qLvIZXeJBQeRODXQ.png" /></figure><p>During AMI creation time, a snapshot of the volume will be taken. There is provision to tag the image and snapshot together or separately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WQXoowXc9c74PBiYHAMOFQ.png" /></figure><p>Navigate to the AMI section and wait for the newly created AMI to be ‘Available’.</p><h4>Step 5: Create a Launch Config</h4><p>Navigate to EC2 → Launch configurations and create a new launch configuration specifying the previously created AMI and instance type as t2.micro. Assign the role which has Cloud Watch access for Instance profile. .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*C5BmiTYZh8KX0V22v3l8Ig.png" /></figure><p>Assign any existing key pairs and security groups with SSH access and create launch configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TtwOCV_VCgvx3iC44jf_RQ.png" /></figure><h4>Step 6: Auto Scaling Time</h4><p>Note:An Auto Scaling Group (ASG) helps to maintain a steady performance for the deployed applications. Some of its features are</p><p>•Scale out (Launch EC2 instances) to match an increased load<br>• Scale in (Terminate EC2 instances) to match a decreased load<br>• Ensure we have a minimum and a maximum number of EC2 instances running<br>• Automatically register new instances to a load balancer.<br>• Re-create an EC2 instance in case a previous one is terminated (say unhealthy)</p><p>Create an auto scaling group with the Launch Config created in previous step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*h03AoLviFPxhPzoz0gDZow.png" /></figure><p>Keep the VPC setting as default and choose the subnets where these instance need to be launched. We are opting for a no load balancer option with health checks on EC2 at a grace period of 300 s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3pxdIB02R7L_7cJ2AgMHTg.png" /></figure><p>Choose the desired / minimum and maximum capacity needed.</p><ul><li><strong>Desired capacity</strong>: Represents the initial capacity of the Auto Scaling group at the time of creation. An Auto Scaling group attempts to maintain the desired capacity.</li><li><strong>Minimum capacity</strong>: Represents the minimum group size.An Auto Scaling group cannot decrease its desired capacity lower than the minimum size limit.</li><li><strong>Maximum capacity</strong>: Represents the maximum group size.An Auto Scaling group cannot increase its desired capacity more than the mazximum size limit.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*EBF5B5R-idPVb_dgSTg3fg.png" /></figure><h4>Step 7: ASG is launching an instance as per the config</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NE6kAv9sGumsGA3Y5Ab6zA.png" /></figure><h4>Step 8: Monitor it</h4><p>Navigate to the CW dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AhMDIuH5jMYaf69DGmYRsg.png" /></figure><p>Under the Metrics → All metrics, we can see that memory utilization is getting collected.</p><h4>Step 9: Create an Alarm</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*ITOumrcAvZ2xP8ebrTkaXA.png" /></figure><p>Create an alarm based on the memory used percent custom metric. For Notifications, choose the default SNS topic for Cloud Watch Alarms and enter your email id to get the notification in case of threshold breach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*nz3SfHLZW6o8uEWkAzi4ig.png" /></figure><h4>Step 10: Link ASG with Alarm</h4><p>Navigate to the EC2 console and select the ASG from the Auto scaling groups and create a dynamic scaling policy for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*dDh9_my_wvOr_f7e7C93nw.png" /></figure><p>Choose Step scaling and link the previously created Cloud Watch alarm.Define the action to take. Example :- Add 2 EC2 instances when memory percentage is greater than 50%. Sample given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*hgwn3Ru0Kdijzj1phPAPRw.png" /></figure><h4>Step 11: Stressing it out</h4><p>Connect to the live instance with EC2 Instance Connect and run below command to generate the stress</p><p><em>sudo stress — cpu 8 — vm-bytes $(awk ‘/MemAvailable/{printf “%d\n”, $2 * 0.9;}’ &lt; /proc/meminfo)k — vm-keep -m 1</em></p><h4>Step 12: Wait for the Alarm</h4><p>The load is slowly increasing and the graphed metrics for memory usage is indicating a spike.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iT3JNHmafiIVH0qefbmSTg.png" /></figure><p>The alarm state is changing from OK to Alarm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S0TwFE-bwA0zV8H8XbCAlQ.png" /></figure><p>An email message is received indicating an overflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pwTkMm5DCBjjerIi0dfRRA.png" /></figure><p>Navigate to the EC2 dashboard and check for new instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*38P-fGJ1OqfmZOmULI9czg.png" /></figure><p>Yes. the number of instances is increased to 3. ASG has launched 2 additional instances as per the auto scaling config because of the CW alarm.</p><p>Now stop the stress and observe the Cloud Watch Alarm. The status is changed from Alarm to OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ADZ7fDcZkWmc_mw2OPr9w.png" /></figure><h4>Step 13: Clean up!</h4><p>Now to clean up, if you stop the instances manually, ASG will again spin up new instances as per the desired capacity. Instead set the minimum and desired capacity in ASG as zero.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*zYZbeN4tkTyMUu1EDPjkKA.png" /></figure><p>This will cause the instances to be automatically terminated by ASG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJnFzSIwIk7Hl6XGI6jnDA.png" /></figure><p>Cool. That’s it. We have successfully completed EC2 Auto scaling with Cloud Watch using a custom metrics.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=477fb67e6814" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/auto-scaling-with-custom-metrics-477fb67e6814">Auto scaling with custom metrics.</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>