<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Asna Siji</title>
    <description>The latest articles on DEV Community by Asna Siji (@asnakhader).</description>
    <link>https://dev.to/asnakhader</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F923815%2Fc6353b72-4b5c-4c2b-93ef-36d6a3f28ac5.jpg</url>
      <title>DEV Community: Asna Siji</title>
      <link>https://dev.to/asnakhader</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/asnakhader"/>
    <language>en</language>
    <item>
      <title>Solving it the AWS way.</title>
      <dc:creator>Asna Siji</dc:creator>
      <pubDate>Mon, 03 Oct 2022 07:31:30 +0000</pubDate>
      <link>https://dev.to/asnakhader/solving-it-the-aws-way-4jgc</link>
      <guid>https://dev.to/asnakhader/solving-it-the-aws-way-4jgc</guid>
      <description>&lt;p&gt;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 :-) ].&lt;/p&gt;

&lt;p&gt;Let’s solve this the AWS way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution Description&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

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

&lt;p&gt;Two buckets are created, source bucket and destination bucket. Source bucket will hold the images user is giving as input.&lt;br&gt;
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.&lt;br&gt;
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.&lt;br&gt;
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.&lt;br&gt;
Lambda function logic will consolidate it into sentences and save it to destination bucket as text.&lt;br&gt;
Event notification is enabled on the destination bucket to invoke SNS to send external emails once the process is completed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Serverless Features in Spot Light&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;S3 Replication&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Amazon Simple Storage Service (S3) can automatically replicate S3 objects to help you reduce costs and protect data.&lt;br&gt;
Two main replication options are:&lt;br&gt;
Cross-Region Replication (CRR) — copies S3 objects across multiple AWS Regions.&lt;br&gt;
Same-Region Replication (SRR) — copies S3 objects between buckets in different availability zones (AZs), in the same region.&lt;br&gt;
S3 also offers a Replication Time Control (RTC) that guarantees object replication in less than fifteen minutes.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;S3 Event Notification&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Amazon S3 Event Notifications feature helps you to receive notifications when certain events happen in your S3 bucket.&lt;br&gt;
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.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Computation Layer with Lambda&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;AWS Lambda is the serverless event-driven computation layer that runs your code without provisioning or managing servers&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Textract&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Amazon Textract is a service that can be used to automatically extracts text, handwriting, and data from documents /images.&lt;br&gt;
It uses advanced machine learning (ML) algorithms to achieve this.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;SNS&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s Build.&lt;/strong&gt;&lt;br&gt;
Step 1 : Create Buckets&lt;/p&gt;

&lt;p&gt;Navigate to the S3 console and create 2 buckets in the same region, say ‘textractsourcebucket’ and ‘textractdestinationbucket’ with versioning enabled.&lt;/p&gt;

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

&lt;p&gt;Step 2 : Creating Roles&lt;/p&gt;

&lt;p&gt;We need 2 roles, one for S3 replication and another for lambda function.&lt;/p&gt;

&lt;p&gt;Role 1 : Let the S3 replication feature itself create a new role for this. Skip this for now.&lt;/p&gt;

&lt;p&gt;Role 2 : Create a role with Cloud Watch, Textract and S3 access for lambda.&lt;/p&gt;

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

&lt;p&gt;Step 3 : Enabling replication&lt;/p&gt;

&lt;p&gt;Navigate to the Management tab of the source bucket and create replication rules.&lt;/p&gt;

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

&lt;p&gt;Create replication rule by providing a name. Enable versioning if you have not enabled it before.&lt;/p&gt;

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

&lt;p&gt;We are filtering the replication items based on tag. The drawings will be uploaded with a tag ‘picture’.&lt;/p&gt;

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

&lt;p&gt;Select the destination bucket created before in Step 1 as destination.&lt;/p&gt;

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

&lt;p&gt;Allow S3 replication feature to create a role for you with required permissions.&lt;/p&gt;

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

&lt;p&gt;Save the replication configuration.&lt;/p&gt;

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

&lt;p&gt;You can choose not to replicate existing objects.&lt;/p&gt;

&lt;p&gt;Step 4 : Creating lambda function&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Navigate to lambda console and create a new function with run time as Node.js.&lt;/p&gt;

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

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/asnakhader/textract" rel="noopener noreferrer"&gt;https://github.com/asnakhader/textract&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/asnakhader/textract" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a test event to test the function. Sample given below (obtained from Cloud Watch logs when the S3 event notification happens).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Records": [
        {
            "eventVersion": "2.1",
            "eventSource": "aws:s3",
            "awsRegion": "ap-south-1",
            "eventTime": "2022-09-23T04:59:35.441Z",
            "eventName": "ObjectCreated:Put",
            "userIdentity": {
                "principalId": "AWS:BBBBBBB"
            },
            "requestParameters": {
                "sourceIPAddress": "00.00.00.174"
            },
            "responseElements": {
                "x-amz-request-id": "XDG0P50ZJ02XX7JR",
                "x-amz-id-2": "c+xP2nQ780GjtppxeXERgXK9OJt7ZTLUqR941EE9/y74GhIBoQX5ZRb2leJWD40XpkFFK82HZR/lfT/lTR0n/Atnr26OmFK5wzx3F7npKJc="
            },
            "s3": {
                "s3SchemaVersion": "1.0",
                "configurationId": "storyUpload",
                "bucket": {
                    "name": "&amp;lt;your source bucket name&amp;gt;",
                    "ownerIdentity": {
                        "principalId": "BBBBBBB"
                    },
                    "arn": "arn:aws:s3:::&amp;lt;your source bucket name&amp;gt;"
                },
                "object": {
                    "key": "&amp;lt;your object name&amp;gt;",
                    "size": 1522574,
                    "eTag": "c5fa617910f9118efa01ddcbd82e1433",
                    "versionId": "Q9yd0M4L2otyIdURpFOgnZdi46C54y91",
                    "sequencer": "00632D3D375CC84842"
                }
            }
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Test the function to see if return a success response.&lt;/p&gt;

&lt;p&gt;Step 5: Setting up S3 Event Notification&lt;/p&gt;

&lt;p&gt;Navigate to the S3 console and select the source bucket.&lt;/p&gt;

&lt;p&gt;Create a folder, say ‘images; to upload handwritten notes.&lt;/p&gt;

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

&lt;p&gt;Navigate to the ‘Properties’ tab and create event notifications.&lt;/p&gt;

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

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fodwqp5o3s3s92iorriqc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fodwqp5o3s3s92iorriqc.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Enable this for all object creation events and set the destination as lamda function created before.&lt;/p&gt;

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

&lt;p&gt;Step 6 : Create SNS Topic&lt;/p&gt;

&lt;p&gt;Navigate to the SNS Console and create a topic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbnb98e2yqn09r05tragg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbnb98e2yqn09r05tragg.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Navigate to the Access Policy tab and attach a policy which allows the S3 bucket to publish messages to SNS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz26qqadd73wznhndomol.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz26qqadd73wznhndomol.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Sample policy is given below.&lt;br&gt;
&lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://gist.githubusercontent.com/asnakhader/4f170b78f30d11b7cb1e7b72cbdc9c27/raw/322511d87d0c2c16c6aa1dbacf616dc2851c904e/textract_sns_topic_policy" rel="noopener noreferrer"&gt;
      gist.githubusercontent.com
    &lt;/a&gt;
&lt;/div&gt;



&lt;p&gt;Create a subscription for this topic with an email end point.&lt;/p&gt;

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

&lt;p&gt;Confirm the subscription by accepting the invitation received in email.&lt;/p&gt;

&lt;p&gt;Step 7 : Setting up email notification for process completion&lt;/p&gt;

&lt;p&gt;Navigate to the destination bucket and create event notification.&lt;/p&gt;

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

&lt;p&gt;Select destination as the previously created SNS topic and save changes.&lt;/p&gt;

&lt;p&gt;Step 8 : Testing&lt;/p&gt;

&lt;p&gt;Navigate to S3 Source Bucket and upload a drawing with tag as ‘picture’.&lt;/p&gt;

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

&lt;p&gt;Source Bucket&lt;br&gt;
Upload the handwritten text images in folder ‘/images’.&lt;/p&gt;

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

&lt;p&gt;Navigate to destination bucket and check the details. S3 replication has replicated the uploaded image with tag ‘picture’.&lt;/p&gt;

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

&lt;p&gt;Check the details inside the image folder.&lt;/p&gt;

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

&lt;p&gt;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!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Product&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2roq7ge1o7zdgbmv3fsz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2roq7ge1o7zdgbmv3fsz.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Excuse the spelling / grammar mistakes pls. Big shoutout to Textract for reading this :-)&lt;/p&gt;

&lt;p&gt;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?&lt;/p&gt;

&lt;p&gt;Tail End: 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.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>javascript</category>
      <category>serverless</category>
      <category>lambda</category>
    </item>
    <item>
      <title>Auto scaling with custom metrics.</title>
      <dc:creator>Asna Siji</dc:creator>
      <pubDate>Sat, 10 Sep 2022 05:17:56 +0000</pubDate>
      <link>https://dev.to/aws-builders/auto-scaling-with-custom-metrics-2393</link>
      <guid>https://dev.to/aws-builders/auto-scaling-with-custom-metrics-2393</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Auto Scaling or the ability to automatically adjust capacity to maintain predictable performance thus becomes a primary advantage of using a cloud infrastructure.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Let’s setup EC2 Auto Scaling with a custom metric.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1 : Launch an instance&lt;/strong&gt;&lt;br&gt;
First, launch an Amazon EC2 Linux instance with default configuration.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 2 : Create a role with CloudWatch access&lt;/strong&gt;&lt;br&gt;
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.&lt;/p&gt;

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

&lt;p&gt;For the purpose of this demo, I am assigning full access. But always remember ‘PLP’ , Principle of Least Privilege.&lt;/p&gt;

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

&lt;p&gt;Navigate to EC2 instance dashboard and assign this role to the instance by selecting the instance and modifying IAM role under Security option.&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;Step 3: Install agents&lt;/strong&gt;&lt;br&gt;
Connect to the instance with EC2 Instance connect.&lt;/p&gt;

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

&lt;p&gt;Its time to leverage some of your Linux admin skills :)&lt;/p&gt;

&lt;p&gt;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 .&lt;br&gt;
sudo yum install amazon-cloudwatch-agent&lt;/p&gt;

&lt;p&gt;2.It’s important that EPEL repo is enabled in Linux 2 AMI by running&lt;br&gt;
&lt;code&gt;&lt;br&gt;
sudo amazon-linux-extras install epel -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3.Let’s create some stress.Install the stress package by&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo yum install stress -y&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create the agent configuration file&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Commands to create an agent config file named amazon-cloudwatch-agent.json&lt;/p&gt;

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

--run as root user
sudo su

--create the agent config file
touch amazon-cloudwatch-agent.json

--change the file permissions to make it editable
chmod +rwx amazon-cloudwatch-agent.json

--edit the file in visual editor
vi amazon-cloudwatch-agent.json

--Copy the sample contents for amazon-cloudwatch-agent.json and enter :wq command to save the file and exit

--display the file content
cat amazon-cloudwatch-agent.json


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

&lt;/div&gt;

&lt;p&gt;Sample for amazon-cloudwatch-agent.json&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{&lt;br&gt;
  "metrics": {&lt;br&gt;
    "append_dimensions": {&lt;br&gt;
      "InstanceId": "${aws:InstanceId}"&lt;br&gt;
    },&lt;br&gt;
    "metrics_collected": {&lt;br&gt;
      "mem": {&lt;br&gt;
        "measurement": [&lt;br&gt;
          "mem_used_percent"&lt;br&gt;
        ]&lt;br&gt;
      },&lt;br&gt;
      "disk": {&lt;br&gt;
        "resources": [&lt;br&gt;
          "*"&lt;br&gt;
        ],&lt;br&gt;
        "measurement": [&lt;br&gt;
          "used_percent"&lt;br&gt;
        ]&lt;br&gt;
      }&lt;br&gt;
    }&lt;br&gt;
  }&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Start the CloudWatch agent on the server.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Enter following command. Replace configuration-file-path with the path to the agent configuration file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:configuration-file-path&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;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 :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:amazon-cloudwatch-agent.json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This file is the amazon-cloudwatch-agent.json if you created it manually as per above step 4.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Stop the server and create an AMI&lt;/strong&gt;&lt;br&gt;
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.&lt;br&gt;
EC2 instances can be launched from&lt;br&gt;
• A Public AMI: AWS provided&lt;br&gt;
• Your own AMI: you make and maintain them yourself (like what we are doing now)&lt;br&gt;
• An AWS Marketplace AMI: an AMI someone else made&lt;/p&gt;

&lt;p&gt;During AMI creation time, a snapshot of the volume will be taken. There is provision to tag the image and snapshot together or separately.&lt;/p&gt;

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

&lt;p&gt;Navigate to the AMI section and wait for the newly created AMI to be ‘Available’.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 5: Create a Launch Config&lt;/strong&gt;&lt;br&gt;
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. .&lt;/p&gt;

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

&lt;p&gt;Assign any existing key pairs and security groups with SSH access and create launch configuration.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 6: Auto Scaling Time&lt;/strong&gt;&lt;br&gt;
Note:An Auto Scaling Group (ASG) helps to maintain a steady performance for the deployed applications. Some of its features are&lt;/p&gt;

&lt;p&gt;•Scale out (Launch EC2 instances) to match an increased load&lt;br&gt;
• Scale in (Terminate EC2 instances) to match a decreased load&lt;br&gt;
• Ensure we have a minimum and a maximum number of EC2 instances running&lt;br&gt;
• Automatically register new instances to a load balancer.&lt;br&gt;
• Re-create an EC2 instance in case a previous one is terminated (say unhealthy)&lt;/p&gt;

&lt;p&gt;Create an auto scaling group with the Launch Config created in previous step.&lt;/p&gt;

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

&lt;p&gt;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.&lt;/p&gt;

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

&lt;p&gt;Choose the desired / minimum and maximum capacity needed.&lt;/p&gt;

&lt;p&gt;Desired capacity: Represents the initial capacity of the Auto Scaling group at the time of creation. An Auto Scaling group attempts to maintain the desired capacity.&lt;br&gt;
Minimum capacity: Represents the minimum group size.An Auto Scaling group cannot decrease its desired capacity lower than the minimum size limit.&lt;br&gt;
Maximum capacity: Represents the maximum group size.An Auto Scaling group cannot increase its desired capacity more than the mazximum size limit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7: ASG is launching an instance as per the config&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 8: Monitor it&lt;/strong&gt;&lt;br&gt;
Navigate to the CW dashboard.&lt;/p&gt;

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

&lt;p&gt;Under the Metrics → All metrics, we can see that memory utilization is getting collected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9: Create an Alarm&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9r2upk05z5cvt3r04eus.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9r2upk05z5cvt3r04eus.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
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.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 10: Link ASG with Alarm&lt;/strong&gt;&lt;br&gt;
Navigate to the EC2 console and select the ASG from the Auto scaling groups and create a dynamic scaling policy for it.&lt;/p&gt;

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

&lt;p&gt;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.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 11: Stressing it out&lt;/strong&gt;&lt;br&gt;
Connect to the live instance with EC2 Instance Connect and run below command to generate the stress&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo stress — cpu 8 — vm-bytes $(awk ‘/MemAvailable/{printf “%d\n”, $2 * 0.9;}’ &amp;lt; /proc/meminfo)k — vm-keep -m 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 12: Wait for the Alarm&lt;/strong&gt;&lt;br&gt;
The load is slowly increasing and the graphed metrics for memory usage is indicating a spike.&lt;/p&gt;

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

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

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

&lt;p&gt;Navigate to the EC2 dashboard and check for new instances.&lt;br&gt;
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.&lt;/p&gt;

&lt;p&gt;Now stop the stress and observe the Cloud Watch Alarm. The status is changed from Alarm to OK.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 13: Clean up!&lt;/strong&gt;&lt;br&gt;
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.&lt;/p&gt;

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

&lt;p&gt;This will cause the instances to be automatically terminated by ASG.&lt;/p&gt;

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

&lt;p&gt;Cool. That’s it. We have successfully completed EC2 Auto scaling with Cloud Watch using a custom metrics.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>ec2</category>
      <category>autoscaling</category>
    </item>
  </channel>
</rss>
