<?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 Robledo Alencar on Medium]]></title>
        <description><![CDATA[Stories by Robledo Alencar on Medium]]></description>
        <link>https://medium.com/@robledo_92812?source=rss-4c7c3bb754c9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Robledo Alencar on Medium</title>
            <link>https://medium.com/@robledo_92812?source=rss-4c7c3bb754c9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 22:21:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@robledo_92812/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[How to set up AWS CloudWatch + Slack notifications for applications]]></title>
            <link>https://medium.com/prooftrading/how-to-set-up-aws-cloudwatch-slack-notifications-for-applications-ac59c0facc3d?source=rss-4c7c3bb754c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac59c0facc3d</guid>
            <dc:creator><![CDATA[Robledo Alencar]]></dc:creator>
            <pubDate>Wed, 20 Aug 2025 14:26:30 GMT</pubDate>
            <atom:updated>2025-08-20T14:26:30.345Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>At Proof, as an agency broker, we need to actively monitor our systems to make sure client orders are behaving as expected. Having the ability to respond to issues as quickly as possible is a requirement, as we want to minimize impact on the executions of our orders.</p><p>For the past several years, we have relied on 3rd party tools to provide notifications for errors in our apps. While it met our requirements for notifying issues on a timely manner, we were searching for something that could provide lower latency and reduce costs. That’s why we worked on integrating AWS CloudWatch + Slack for error notifications.</p><p>In this article, we will provide a full step-by-step guide to setup Slack notifications based on application logs. This is the full message flow at the end of the setup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zHHpqzupyjZL2OYY-nzBqw.png" /></figure><h3>Part 1: Feeding app logs into AWS</h3><p>For the 1st part, we need to start sending our application logs into AWS. This way we have a centralized place to monitor app logs and create our custom alerts.</p><p>To achieve this, we need to setup an IAM role with proper permissions to send logs and install the CloudWatch agent in our host.</p><p><strong>Launching a new EC2 instance</strong></p><p>For this demo, we will launch a t2.micro amazon Linux. Make sure to create a new keypair so you can use it to access the host when needed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*9L41SuOcMF995I7dbGeeRA.png" /></figure><p><strong>Setting up IAM role for CloudWatch logs</strong></p><p>We need a new IAM role with required permissions to start pushing logs to CloudWatch. This will later be assigned to the ec2 instance to give CloudWatch agent the permissions it needs to push the app logs.</p><p>Go to IAM in AWS Console, create a new role of the type AWS Service for EC2.</p><p>Under permissions, choose “AmazonAPIGatewayPushToCloudWatchLogs”:</p><p>The new role should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4E-8ZxPlVP7f-QiF8K5zCw.png" /></figure><p>Now update the ec2-instance to include this new role (EC2-&gt;Instances-&gt; Choose instance-&gt;Actions-&gt;Security-&gt;Modify IAM role):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*8kN0YmZsTvohIy_z4fx1vQ.png" /></figure><p><strong>Configuring AWS CloudWatch agent</strong></p><p>Run the following command in the ec2 host:</p><pre>sudo yum install amazon-cloudwatch-agent</pre><p>Edit the CloudWatch agent config (/opt/aws/amazon-cloudwatch-agent/bin/config.json) as per below:</p><pre>{<br>  &quot;agent&quot;: {<br>    &quot;metrics_collection_interval&quot;: 60,<br>    &quot;run_as_user&quot;: &quot;ec2-user&quot;<br>  },<br>  &quot;logs&quot;: {<br>    &quot;logs_collected&quot;: {<br>      &quot;files&quot;: {<br>        &quot;collect_list&quot;: [<br>          {<br>            &quot;file_path&quot;: &quot;/opt/demo/DemoApp.log&quot;,<br>            &quot;log_group_class&quot;: &quot;STANDARD&quot;,<br>            &quot;log_group_name&quot;: &quot;DemoApp&quot;,<br>            &quot;log_stream_name&quot;: &quot;{instance_id}_DemoApp&quot;,<br>            &quot;retention_in_days&quot;: 1<br>          }<br>        ]<br>      }<br>    }<br>  }<br>}</pre><p>Now start the CloudWatch agent:</p><pre>sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \<br> -a fetch-config -m ec2 -s -c \<br> file:/opt/aws/amazon-cloudwatch-agent/bin/config.json</pre><p>AWS CloudWatch agent reference: <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/download-cloudwatch-agent-commandline.html">https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/download-cloudwatch-agent-commandline.html</a></p><p><strong>Deploying the test App</strong></p><p>For this tutorial, we will use the following code snippet as our app. The idea is to generate simple error/info messages.</p><pre>package org.example;<br><br><br>import org.apache.logging.log4j.LogManager;<br>import org.apache.logging.log4j.Logger;<br><br>public class DemoApp {<br>    private static final Logger LOGGER = LogManager.getLogger(DemoApp.class);<br><br>    public static void main(String[] args) throws InterruptedException {<br>        for(int i = 1; i &lt; 100; i++) {<br>            if(i%5 == 0){<br>                LOGGER.error(&quot;Number is multiple of 5&quot;);<br>            }<br>            LOGGER.info(&quot;Number is: {}&quot;, i);<br>            Thread.sleep(500);<br>        }<br>    }<br>}</pre><p>Now build the jar for this project and run in ec2 host as follow:</p><pre>java -jar DemoApp.jar &gt; /opt/demo/DemoApp.log</pre><p>After running the app, logs should start flowing into CloudWatch in AWS (under Logs-&gt;Logs groups-&gt;Demo App):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zxOuM6gjfsPkATCu4-ZbJg.png" /></figure><p>With this, we have completed the App/AWS side of the setup. Now we proceed setting up the integration between AWS/Slack.</p><h3>Part 2: Generating Slack alerts based on app logs</h3><p>For part 2, we need to create a new AWS topic to send messages to slack, plus a couple of AWS Lambdas to properly handle the integration with CloudWatch/Slack.</p><p><strong>Creating a new topic</strong></p><p>First, we need a new topic to start publishing our error logs. Under SNS (Simple Notification Service) in AWS console, create a new topic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gRJ8Tf8p4zxQc9-80rDI0A.png" /></figure><p><strong>Publish errors to topic</strong></p><p>To start publishing messages to the topic, we are going to create a new lambda function that will filter errors from CloudWatch logs and send those error messages to the topic.</p><p>Go to AWS Lambda and create a new Node 18.js function. Make sure it has Amazon SNS publish policy attached:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rp7s17ph7c0k9TzLzns1OQ.png" /></figure><p>Use the following code for your function. Make sure to update the topic arn.</p><pre>import * as zlib from &#39;node:zlib&#39;;<br>import { SNSClient, PublishCommand } from &quot;@aws-sdk/client-sns&quot;;<br><br><br>export const handler = async (event) =&gt; {<br>    const payload = Buffer.from(event.awslogs.data, &#39;base64&#39;);<br>    const parsed = JSON.parse(zlib.gunzipSync(payload).toString(&#39;utf8&#39;));<br>    console.log(&#39;Decoded payload:&#39;, JSON.stringify(parsed));<br>    const snsClient = new SNSClient({});<br>    const input = { // PublishInput<br>        //Update this with your topic arn<br>        TopicArn: &quot;arn:aws:sns:us-east-1:XXXXXXXXXXXX:DemoTopic&quot;,<br>        Subject: &quot;App Error&quot;,<br>        Message: JSON.stringify(parsed), // required<br>    };<br>    const command = new PublishCommand(input);<br>    const response = await snsClient.send(command);<br>    return `sent ${parsed.logEvents.length} log events.`;<br>};</pre><p>reference code: reference: <a href="https://docs.aws.amazon.com/sns/latest/dg/example_sns_Publish_section.html">https://docs.aws.amazon.com/sns/latest/dg/example_sns_Publish_section.html</a></p><p>We are adding CloudWatch Logs as a trigger to this function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VC6DLJay1X2F_pNSABdQkA.png" /></figure><p>This function now will read logs from CloudWatch for our app, filter messages that have “ERROR” as part of it, and publish to the topic, which can be later sent to other destinations (Email, Slack, etc.)</p><p><strong>Create a Slack Incoming Webhook</strong></p><p>To send app errors to slack, we need an endpoint that allows sending Slack messages. This can be achieved using Slack’s Incoming Webhook.</p><p>Go to Slack apps portal (<a href="https://api.slack.com/apps/">https://api.slack.com/apps/</a>). Create a new app.</p><p>In the app page, enable incoming webhooks and add a new webhook:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fJYfHWNZBv6XndprNU8pMQ.png" /></figure><p>Now you should have a Webhook link to start publishing errors messages from apps directly to Slack.</p><p><strong>Publish topic messages to Slack</strong></p><p>In the last part of our demo, we need to read error topic messages and generate Slack messages based on them. We will create a new lambda that will parse topic messages and call our Incoming Webhook.</p><p>In AWS Lambda, we need a new Node 18.js function as per below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TbkdWCPP71UN1qh8cVy0Mg.png" /></figure><p>Let’s use the following code. Make sure to update your Webhook URL:</p><pre>import * as https from &#39;node:https&#39;;<br>import * as url from &#39;node:url&#39;;<br><br>/**<br> * Pass the data to send as `event.data`, and the request options as<br> * `event.options`. For more information see the HTTPS module documentation<br> * at https://nodejs.org/api/https.html.<br> *<br> * Will succeed with the response body.<br> */<br>export const handler = (event, context, callback) =&gt; {<br>    //Use the Webhook URL you created on the previous step<br>    const slack_url = &#39;https://hooks.slack.com/services/XXXXXXXX/YYYYYYYYYYYY/ZzzzzZZZZZZZZzzz&#39;;  //fill the slack webhook url here<br>    const slack_req_opts = url.parse(slack_url);<br>    slack_req_opts.method = &#39;POST&#39;;<br>    slack_req_opts.headers = {&#39;Content-Type&#39;: &#39;application/json&#39;};<br>    (event.Records || []).forEach(function (rec) {<br>        if (rec.Sns) {<br>            const req = https.request(slack_req_opts, (res) =&gt; {<br>                let body = &#39;&#39;;<br>                console.log(&#39;Status:&#39;, res.statusCode);<br>                console.log(&#39;Headers:&#39;, JSON.stringify(res.headers));<br>                res.setEncoding(&#39;utf8&#39;);<br>                res.on(&#39;end&#39;, () =&gt; {<br>                    console.log(&#39;Successfully processed HTTPS response&#39;);<br>                });<br>            });<br>            req.on(&#39;error&#39;, function(e) {<br>                console.log(&#39;problem with request: &#39; + e.message);<br>                context.fail(e.message);<br>            });<br>            let logEvent = JSON.parse(rec.Sns.Message);<br>            req.write(JSON.stringify(<br>                {blocks: [<br>                    { &quot;type&quot;: &quot;header&quot;, &quot;text&quot;: { &quot;type&quot;: &quot;plain_text&quot;, &quot;text&quot;:&quot;Error or Exception!&quot;}},<br>                    { &quot;type&quot;: &quot;section&quot;, &quot;text&quot;: { &quot;type&quot;: &quot;plain_text&quot;, &quot;text&quot;:JSON.stringify(logEvent.logEvents)}}<br>                ]<br>                }<br>              )<br>           );<br>            req.end();<br>        };<br>    });<br>};</pre><p>Add a SNS trigger to this function, as per below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v9qdhefBYyTza8hq19l-hQ.png" /></figure><p>Let’s run our Demo App again. Now we should see the following notifications popping up in Slack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*AbS246mv2hTMiZSf9Teo4A.png" /></figure><p>Now we can be notified in Slack whenever our application logs an error.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac59c0facc3d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prooftrading/how-to-set-up-aws-cloudwatch-slack-notifications-for-applications-ac59c0facc3d">How to set up AWS CloudWatch + Slack notifications for applications</a> was originally published in <a href="https://medium.com/prooftrading">Proof Reading</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>