<?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 Aakash Rana on Medium]]></title>
        <description><![CDATA[Stories by Aakash Rana on Medium]]></description>
        <link>https://medium.com/@aakashrana7?source=rss-32b468be1ec4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QhGCkWWhexJYtoSXwTZgTA.jpeg</url>
            <title>Stories by Aakash Rana on Medium</title>
            <link>https://medium.com/@aakashrana7?source=rss-32b468be1ec4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 14:58:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aakashrana7/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[Automating File Processing with AWS: Image Compression & Word Count ]]></title>
            <link>https://medium.com/@aakashrana7/automating-file-processing-with-aws-image-compression-word-count-5f70ccc0d08a?source=rss-32b468be1ec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f70ccc0d08a</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[file-compression-in-aws]]></category>
            <category><![CDATA[s3-bucket]]></category>
            <category><![CDATA[word-counting-in-aws]]></category>
            <dc:creator><![CDATA[Aakash Rana]]></dc:creator>
            <pubDate>Mon, 10 Aug 2026 13:01:12 GMT</pubDate>
            <atom:updated>2026-08-10T13:01:12.072Z</atom:updated>
            <content:encoded><![CDATA[<h3>Problem Statement</h3><p>Many industries handle large amounts of digital files, such as images and text documents. Managing storage efficiently and processing these files manually can be time-consuming.</p><p>For example:</p><ul><li><strong>E-commerce &amp; Media Platforms</strong> need to optimize images to reduce storage and improve website speed.</li><li><strong>Content Management Systems</strong> need to analyze text files, such as counting words for reports or summarization.</li></ul><p>A manual approach is inefficient. We need an <strong>automated</strong> system that can handle file uploads, process them accordingly, and display the results; all without human intervention.</p><h3>Solution Overview</h3><p>We will build a <strong>simple web-based system</strong> where users can:</p><ol><li><strong>Upload a file (image or text).</strong></li><li><strong>The system processes it automatically:</strong></li></ol><ul><li><strong>Images</strong> are compressed to reduce size.</li><li><strong>Text files</strong> are analyzed to count words.</li></ul><p><strong>3. The processed file or word count is displayed back on the website.</strong></p><p>The key idea is to use <strong>AWS cloud services</strong> to handle everything behind the scenes, making the process fast and scalable.</p><h3>AWS Services Used</h3><p>To achieve this, we will use the following <strong>AWS services</strong>:</p><ul><li><strong>Amazon S3: </strong>Stores uploaded and processed files.</li><li><strong>AWS Lambda: </strong>Runs the logic for image compression and word counting.</li><li><strong>Amazon API Gateway</strong>: Connects the frontend and backend.</li><li><strong>Amazon EC2: </strong>Hosts the website.</li></ul><h3>Architecture Overview</h3><h3>1. User Uploads a File</h3><ul><li>A user selects an image or text file and uploads it via the website (hosted on EC2).</li><li>The file is stored in an <strong>Amazon S3 bucket</strong>.</li></ul><h3>2. Event-Driven Processing Using AWS Lambda</h3><ul><li>When a file is uploaded, <strong>S3 Event Notifications</strong> trigger a <strong>Lambda function</strong>.</li><li><strong>Lambda Processing:<br></strong><em>If it’s an image, Lambda compresses it.<br>If it’s a text file, Lambda counts the words.</em></li><li>The processed file or result is saved back to S3 or DynamoDB.</li></ul><h3>3. Displaying Processed Data on the Website</h3><ul><li>The website retrieves the processed file or word count using <strong>API Gateway</strong>.</li><li>The user sees the output on the web interface.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*yB1cexLgDCCReMKriQhCcw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*q8RsCzqPCy0qAoHZxUT1Vw.png" /><figcaption>Fig: Architecture overview of Word Count Process and Image Compression Process</figcaption></figure><h3>Key AWS Concepts &amp; Features Used</h3><h3>1. Amazon S3 &amp; Event Notifications</h3><ul><li><strong>What is it?</strong> A storage service where we keep the uploaded and processed files.</li><li><strong>Event Notification:</strong> When a file is uploaded, S3 sends a signal (event) to trigger a Lambda function.</li></ul><h3>2. AWS Lambda &amp; Triggers</h3><ul><li><strong>What is it?</strong> A serverless compute service that runs code in response to events.</li><li><strong>Trigger Mechanism:</strong> Lambda is automatically executed whenever a new file is added to S3.</li><li><strong>Why use it?</strong> It allows instant processing without requiring a running server.</li></ul><h3>3. API Gateway &amp; EC2 for Web Hosting</h3><ul><li><strong>API Gateway</strong> helps the frontend communicate with AWS services.</li><li><strong>EC2</strong> hosts the website, providing a simple user interface for uploading and viewing results.</li></ul><h3>Step-by-step guide to automating Image Compression:</h3><h3>Step 1: Set Up Your AWS Services</h3><h3>1.1 Create an S3 Bucket</h3><ul><li>Go to the <strong>AWS Management Console</strong> → <strong>S3</strong>.</li><li>Click <strong>Create bucket</strong>.</li><li>Give it a unique name (e.g., image-compression-bucket).</li><li>Enable <strong>versioning</strong> (optional, for backup).</li><li>Configure permissions (set bucket policy to allow Lambda to access it).</li><li>Click <strong>Create bucket</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTSUbnp8WzF7VTAQ1naEoA.png" /></figure><h3>1.2 Launch an EC2 Instance</h3><ul><li>Go to <strong>AWS Management Console</strong> → <strong>EC2</strong>.</li><li>Click <strong>Launch Instance</strong>.</li><li>Choose an <strong>Amazon Linux 2</strong> or <strong>Ubuntu</strong> AMI.</li><li>Select an instance type (e.g., <strong>t2.micro</strong> for free-tier usage).</li><li>Configure Security Group: <br>Allow <strong>SSH (port 22)</strong> to connect from your IP.<br>If your website is hosted here, allow <strong>HTTP (80)</strong> and <strong>HTTPS (443)</strong>.</li><li>Attach an IAM role with <strong>S3 access</strong>.</li><li>Click <strong>Launch</strong> and connect via SSH.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LxJU8HC3Okw8MjhwpfQGZw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wBQNXkbZNsPkdsaicEHwtw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q5P7f9PQmsLz3asNszgM0w.png" /></figure><h3>Step 2: Configure the S3 Trigger and Lambda Function</h3><h3>2.1 Create an IAM Role for Lambda</h3><ul><li>Go to <strong>AWS IAM</strong> → <strong>Roles</strong> → <strong>Create role</strong>.</li><li>Select <strong>AWS Service</strong> → <strong>Lambda</strong>.</li><li>Attach the policies:<br>AmazonS3FullAccess (to access S3).<br>AWSLambdaBasicExecutionRole (for logging).</li><li>Name the role <strong>LambdaS3CompressionRole</strong> and create it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPFlXJwJZ55wf1KpA8KgWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KpDDs7k9ND0AnreHo3fHng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9FujLH6iBY9U8j726D_9-A.png" /></figure><h3>2.2 Create a Lambda Function</h3><ul><li>Go to <strong>AWS Lambda</strong> → <strong>Create function</strong>.</li><li>Choose <strong>Author from scratch</strong>.</li><li><em>Set:<br></em>Function name: ImageCompressionLambda<br>Runtime: <strong>Python 3.9</strong> (or latest)<br>Execution Role: Select <strong>LambdaS3CompressionRole</strong>. <br><em>(PS: i have different role name)</em></li><li>Click <strong>Create function</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PcQidnok51UT6MESUOBl3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V_w3lOBJqDfajuUIca1G5g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DiotlK9U947EHBjvisQ4pQ.png" /></figure><h3>2.3 Add S3 Trigger to Lambda</h3><ul><li>Scroll to <strong>Triggers</strong> → Click <strong>Add trigger</strong>.</li><li>Select <strong>S3</strong>.</li><li>Choose the bucket (image-compression-bucket).</li><li>Event type: <strong>PUT</strong> (trigger when a file is uploaded).</li><li>Click <strong>Add</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUiEptQhO1A7o8JNChkAgw.png" /></figure><h3>Step 3: Write and Deploy Lambda Code</h3><ol><li>In the <strong>Lambda function code editor</strong>, replace the default code with:</li></ol><pre>import boto3<br>import os<br>import io<br>import urllib.parse<br>from PIL import Image<br><br>s3 = boto3.client(&#39;s3&#39;, region_name=&#39;us-east-1&#39;)  # Change region if needed<br><br>def lambda_handler(event, context):<br>    print(&quot;Lambda function triggered!&quot;)  # Debugging step<br><br>    for record in event[&#39;Records&#39;]:<br>        bucket_name = record[&#39;s3&#39;][&#39;bucket&#39;][&#39;name&#39;]<br>        object_key = urllib.parse.unquote_plus(record[&#39;s3&#39;][&#39;object&#39;][&#39;key&#39;])<br><br>        print(f&quot;Processing file: {object_key} from bucket: {bucket_name}&quot;)  # Debugging step<br><br>        try:<br>            # Download the image<br>            response = s3.get_object(Bucket=bucket_name, Key=object_key)<br>            image = Image.open(io.BytesIO(response[&#39;Body&#39;].read()))<br><br>            # Compress the image<br>            compressed_image = io.BytesIO()<br>            image.save(compressed_image, format=image.format, quality=50)  # Adjust quality as needed<br>            compressed_image.seek(0)<br><br>            # Save the compressed image back to S3<br>            compressed_key = f&quot;compressed/{object_key}&quot;<br>            s3.put_object(Bucket=bucket_name, Key=compressed_key, Body=compressed_image, ContentType=f&quot;image/{image.format.lower()}&quot;)<br><br>            print(f&quot;Compressed image saved as {compressed_key}&quot;)  # Debugging step<br><br>        except Exception as e:<br>            print(f&quot;Error processing {object_key}: {e}&quot;)  # Print error in logs<br><br>    return {&quot;status&quot;: &quot;Success&quot;}</pre><p>2. Click <strong>Deploy</strong>.</p><h3>Step 3: Setup EC2 and hosting for website</h3><h3>Step 1: Set Up Your EC2 Instance</h3><h4>3.1.1 SSH into EC2</h4><pre>chmod 400 &quot;your-key.pem&quot;<br>ssh -i &quot;your-key.pem&quot; ec2-user@your-ec2-public-ip</pre><h4>3.1.2 Install Dependencies</h4><pre>sudo yum update -y<br>sudo dnf install -y python3.9 python3-pip<br>pip3 install pillow boto3 flask libjpeg-dev -y</pre><h4>3.1.3 Set up a virtual environment</h4><ol><li>Create a new directory for your project:</li></ol><pre>mkdir ~/image-compression <br>cd ~/image-compression</pre><p>2. Create a virtual environment and install all the dependencies.</p><h3>Step 2 Create your Flask application</h3><ol><li>Inside your project directory (~/image-compression), create a file named app.py:</li></ol><pre>nano app.py</pre><ul><li>Add the following content to app.py:</li></ul><pre>from flask import Flask, render_template, request, send_from_directory<br>import os<br>from PIL import Image<br>import io<br>import boto3<br>from werkzeug.utils import secure_filename<br><br>app = Flask(__name__)<br><br># AWS credentials and resources<br>s3 = boto3.client(&#39;s3&#39;)<br><br># Source and destination bucket details<br>SOURCE_BUCKET = &#39;your-source-bucket&#39;  # Replace with your own bucket<br>DESTINATION_BUCKET = &#39;your-destination-bucket&#39;  # Replace with your destination bucket<br><br># Local directory for saving compressed files temporarily<br>UPLOAD_FOLDER = &#39;uploads&#39;<br>COMPRESSED_FOLDER = &#39;compressed_images&#39;<br><br># Allowed image extensions<br>ALLOWED_EXTENSIONS = {&#39;jpg&#39;, &#39;jpeg&#39;, &#39;png&#39;}<br><br>app.config[&#39;UPLOAD_FOLDER&#39;] = UPLOAD_FOLDER<br><br># Check if file extension is allowed<br>def allowed_file(filename):<br>    return &#39;.&#39; in filename and filename.rsplit(&#39;.&#39;, 1)[1].lower() in ALLOWED_EXTENSIONS<br><br>def compress_image(image):<br>    compressed_image = io.BytesIO()<br>    image.save(compressed_image, format=&#39;JPEG&#39;, quality=30)  # Adjust quality as needed<br>    compressed_image.seek(0)<br>    return compressed_image<br><br>@app.route(&#39;/&#39;)<br>def index():<br>    return render_template(&#39;index.html&#39;)<br><br>@app.route(&#39;/upload&#39;, methods=[&#39;POST&#39;])<br>def upload_file():<br>    if &#39;file&#39; not in request.files:<br>        return &#39;No file part&#39;, 400<br><br>    file = request.files[&#39;file&#39;]<br><br>    if file.filename == &#39;&#39;:<br>        return &#39;No selected file&#39;, 400<br><br>    if file and allowed_file(file.filename):<br>        filename = secure_filename(file.filename)<br>        filepath = os.path.join(app.config[&#39;UPLOAD_FOLDER&#39;], filename)<br>        file.save(filepath)<br><br>        # Compress the image<br>        image = Image.open(filepath)<br>        compressed_image = compress_image(image)<br><br>        # Save compressed image temporarily<br>        compressed_filepath = os.path.join(COMPRESSED_FOLDER, f&quot;compressed_{filename}&quot;)<br>        with open(compressed_filepath, &#39;wb&#39;) as f:<br>            f.write(compressed_image.getvalue())<br><br>        # Send the compressed image as a downloadable file<br>        return send_from_directory(COMPRESSED_FOLDER, f&quot;compressed_{filename}&quot;, as_attachment=True)<br><br>    return &#39;File type not allowed&#39;, 400<br><br>if __name__ == &#39;__main__&#39;:<br>    # Ensure the upload and compressed directories exist<br>    os.makedirs(UPLOAD_FOLDER, exist_ok=True)<br>    os.makedirs(COMPRESSED_FOLDER, exist_ok=True)<br><br>    app.run(debug=True, host=&#39;0.0.0.0&#39;, port=80)</pre><ul><li>Create a templates directory and add an index.html file for the file upload form.</li></ul><pre>mkdir templates <br>nano templates/index.html</pre><ul><li>Add the following content to index.html:</li></ul><pre>&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; <br>&lt;head&gt;     <br>&lt;meta charset=&quot;UTF-8&quot;&gt;     <br>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;     <br>&lt;title&gt;Image Compression&lt;/title&gt; &lt;/head&gt; <br>&lt;body&gt;     <br>&lt;h1&gt;Upload an Image to Compress&lt;/h1&gt;     <br>&lt;form action=&quot;/upload&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;         <br>&lt;input type=&quot;file&quot; name=&quot;file&quot; accept=&quot;image/jpeg, image/png&quot; required&gt;         <br>&lt;button type=&quot;submit&quot;&gt;Upload and Compress&lt;/button&gt;     <br>&lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre><h3>Step 3 Run the Flask application</h3><ol><li>In your EC2 instance, run the Flask app:</li></ol><pre>python3 app.py</pre><p>2. Your app should now be running on your EC2 instance’s public IP. You can access it by visiting:</p><pre>http://your-ec2-public-ip/</pre><p>3. You should see the file upload form. Upload an image, and once it’s compressed, a download link will appear for the compressed image.</p><h4>Troubleshooting: Make sure to open port 80 in EC2:</h4><p>In your EC2 instance’s security group, open port 80 to allow HTTP traffic.</p><ul><li>Go to your EC2 console.</li><li>In the left sidebar, choose <strong>Security Groups</strong>.</li><li>Select the security group associated with your instance.</li><li>In the <strong>Inbound rules</strong>, click <strong>Edit</strong> and add a new rule:</li><li>Type: HTTP</li><li>Port Range: 80</li><li>Source: 0.0.0.0/0 (or restrict to your IP address if needed).</li></ul><blockquote>Moment of truth:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eXo-vWsmrDJBtOqCOCwD7g.png" /><figcaption>Fig: Website Interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3n2iUpjnCkDXboNfbSJhXw.png" /><figcaption>After you upload a image, it gets compressed and you can download it via the page itself</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OExE1DLMVTfLm784kXZrFw.png" /><figcaption>The compressed image gets stored in S3 inside /compressed folder</figcaption></figure><h3>Part 2: Automating Word Counting</h3><p>Let’s modify our <strong>Flask application</strong> to handle both <strong>image compression</strong> and <strong>word counting for .txt files</strong>.</p><h4>Step 1. Modify app.py to Handle Image and Text Uploads</h4><p>Update your <strong>Flask backend</strong> to:</p><ul><li>Accept file uploads (.jpg/.png and .txt).</li><li>Compress images.</li><li>Count words in text files.</li></ul><blockquote><strong><em>Updated </em></strong><strong><em>app.py:</em></strong></blockquote><pre>from flask import Flask, request, render_template<br>import boto3<br>import os<br>from PIL import Image<br>import io<br><br>app = Flask(__name__)<br><br># AWS Configuration<br>S3_BUCKET = &quot;your-s3-bucket-name&quot;<br>s3 = boto3.client(&#39;s3&#39;)  # No credentials needed for me since EC2 IAM role is used<br><br># Home Page<br>@app.route(&#39;/&#39;)<br>def index():<br>    return render_template(&#39;index.html&#39;)<br><br><br># File Upload Route<br>@app.route(&#39;/upload&#39;, methods=[&#39;POST&#39;])<br>def upload_file():<br>    if &#39;file&#39; not in request.files:<br>        return &quot;No file part&quot;<br>    <br>    file = request.files[&#39;file&#39;]<br>    if file.filename == &#39;&#39;:<br>        return &quot;No selected file&quot;<br><br>    file_extension = file.filename.lower().split(&#39;.&#39;)[-1]<br><br>    # Upload original file to S3<br>    s3.upload_fileobj(file, S3_BUCKET, file.filename)<br>    <br>    # Handle Image Compression<br>    if file_extension in [&#39;jpg&#39;, &#39;jpeg&#39;, &#39;png&#39;]:<br>        compressed_filename = f&quot;compressed_{file.filename}&quot;<br>        compressed_file_key = f&quot;compressed/{compressed_filename}&quot;<br>        <br>        # Download file from S3<br>        file_obj = s3.get_object(Bucket=S3_BUCKET, Key=file.filename)<br>        image = Image.open(file_obj[&#39;Body&#39;])<br>        <br>        # Compress Image<br>        compressed_image = io.BytesIO()<br>        image.save(compressed_image, format=&#39;JPEG&#39;, quality=30)<br>        compressed_image.seek(0)<br><br>        # Upload compressed image to S3<br>        s3.upload_fileobj(compressed_image, S3_BUCKET, compressed_file_key)<br><br>        return f&quot;Image compressed! &lt;a href=&#39;https://{S3_BUCKET}.s3.amazonaws.com/{compressed_file_key}&#39;&gt;Download Here&lt;/a&gt;&quot;<br><br>    # Handle Text Word Count<br>    elif file_extension == &#39;txt&#39;:<br>        file_obj = s3.get_object(Bucket=S3_BUCKET, Key=file.filename)<br>        text_content = file_obj[&#39;Body&#39;].read().decode(&#39;utf-8&#39;)<br>        word_count = len(text_content.split())<br><br>        return f&quot;Word Count: {word_count}&quot;<br><br>    else:<br>        return &quot;Unsupported file type!&quot;<br><br><br>if __name__ == &#39;__main__&#39;:<br>    app.run(debug=True, host=&#39;0.0.0.0&#39;, port=5000)</pre><h4>Step 2. Update index.html</h4><p>Modify the frontend to allow updated file uploads.</p><blockquote><strong><em>Updated </em></strong><strong><em>index.html</em></strong></blockquote><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;File Upload&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;Upload an Image or Text File&lt;/h1&gt;<br>    &lt;form action=&quot;/upload&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;<br>        &lt;input type=&quot;file&quot; name=&quot;file&quot; required&gt;<br>        &lt;button type=&quot;submit&quot;&gt;Upload&lt;/button&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong><em>Boom, we are all set 🚀<br>Let’s test it by running our flask app and opening EC2 pubic IP in browser-</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QtgQzopiyZE3wRL2SwdiJg.png" /><figcaption>Our updated Webpage interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BUjfkPJk72S96SDgkiGhNg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBYRK0mBS1FBadUtfvWN-w.png" /><figcaption>Result</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DHIOCf9cXedbwCYXpZjiuQ.png" /><figcaption>Checking S3 for out txt file,boom!</figcaption></figure><h3>TROUBLESHOOTING-</h3><h4>If you encountered a problem during the task, to troubleshoot-</h4><h3>1. Check if Lambda Was Triggered</h3><h3>1.1 Check CloudWatch Logs</h3><p>Lambda logs its execution in <strong>CloudWatch</strong>. Follow these steps to check logs:</p><ol><li>Go to <strong>AWS Console</strong> → <strong>CloudWatch</strong>.</li><li>Click <strong>Logs</strong> → <strong>Log groups</strong>.</li><li>Find your Lambda function’s log group (e.g.,/aws/lambda/ImageCompressionLambda).</li><li>Click on it and check for recent log streams.</li><li>Open the latest log entry and look for error messages.</li></ol><h3>2. Verify S3 Trigger for Lambda</h3><p>Your Lambda function should be automatically triggered when you upload an image. If it’s not, check your S3 event notifications:</p><h3>2.1 Check Event Notifications in S3</h3><ol><li>Go to <strong>AWS Console</strong> → <strong>S3</strong>.</li><li>Click your bucket (e.g., image-compression-bucket).</li><li>Go to <strong>Properties</strong> → Scroll down to <strong>Event notifications</strong>.</li><li>Look for an event notification that triggers <strong>on PUT (file upload)</strong> events.</li></ol><p>✅ <strong>If it’s missing, create a new event notification:</strong></p><ul><li><strong>Event name</strong>: image-upload-trigger</li><li><strong>Prefix</strong>: <em>(leave empty)</em></li><li><strong>Suffix</strong>: .* <em>(to handle all file types)</em></li><li><strong>Event type</strong>: PUT <em>(fires when a new file is uploaded)</em></li><li><strong>Destination</strong>: <strong>Select your Lambda function (</strong><strong>ImageCompressionLambda)</strong></li><li>Click <strong>Save changes</strong>.</li></ul><h3>3. Ensure Lambda Has S3 Write Permissions</h3><p>Lambda needs <strong>write access</strong> to store the compressed image in S3.</p><h3>3.1 Check Lambda Execution Role</h3><ol><li>Go to <strong>AWS Console</strong> → <strong>IAM</strong>.</li><li>Click <strong>Roles</strong> → Find the role assigned to your Lambda function (LambdaS3CompressionRole).</li><li>Check if it has the <strong>AmazonS3FullAccess</strong> policy.</li></ol><h3>Conclusion</h3><p>This project demonstrates an automated, serverless system for <strong>image compression and word counting using AWS Lambda and Amazon S3</strong>. A web-based interface was developed to allow users to upload images and text files easily. Once uploaded, the files are processed automatically using AWS Lambda — images are compressed to reduce their size, while text files are analyzed to count the number of words. The processed files are then stored securely in an <strong>Amazon S3 bucket</strong>, eliminating the need for manual processing and making the workflow faster and more efficient. By integrating a webpage with AWS services, this project provides a <strong>scalable, cost-effective, and automated solution</strong> that can be further extended to applications such as document processing, file conversion, video processing, and AI-based analysis. 🚀☁️</p><blockquote>Consider giving me a <strong>follow </strong>if you enjoyed the task and I’m <strong>open for any positive feedback</strong> as I’m still learning. 😊😊</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f70ccc0d08a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Key Management Service(KMS) for data encryption and decryption | Notion]]></title>
            <link>https://medium.com/@aakashrana7/aws-key-management-service-kms-for-data-encryption-and-decryption-notion-3247d6098ed9?source=rss-32b468be1ec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3247d6098ed9</guid>
            <dc:creator><![CDATA[Aakash Rana]]></dc:creator>
            <pubDate>Thu, 22 Jan 2026 02:25:45 GMT</pubDate>
            <atom:updated>2026-01-22T02:25:45.531Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NUiRX3GVQ-crVpSW" /></figure><p><strong>Amazon KMS (Key Management Service)</strong> is a <strong>fully managed encryption service</strong> that helps you create, manage, and control cryptographic keys across AWS services and applications. It allows you to encrypt and decrypt data securely without handling the complexities of key storage or rotation.</p><h3>🛠️ How Amazon KMS Works</h3><ol><li><strong>Create a KMS Key</strong> — Define a Customer Master Key (CMK) in the AWS KMS console.</li><li><strong>Assign Permissions</strong> — Use IAM policies to grant specific users or applications access to the key.</li><li><strong>Encrypt Data</strong> — AWS services (e.g., S3, RDS, EBS) use KMS keys to encrypt data automatically.</li><li><strong>Decrypt Data</strong> — Only authorized users and services can request decryption using the KMS key.</li></ol><h3>🔐 Types of KMS Keys</h3><ol><li><strong>AWS Managed Keys</strong> — Created and managed by AWS for specific services.</li><li><strong>Customer Managed Keys (CMK)</strong> — Created and managed by customers, allowing more control.</li><li><strong>AWS Owned Keys</strong> — Used internally by AWS services and not visible to customers.</li><li><strong>Custom Key Stores</strong> — Uses AWS CloudHSM for added security and compliance.</li></ol><h3>💡 Common Use Cases</h3><ul><li><strong>Encrypting Amazon S3 Buckets</strong> — Secure S3 objects with KMS keys.</li><li><strong>Securing Databases</strong> — Encrypt Amazon RDS or DynamoDB tables.</li><li><strong>Protecting Secrets</strong> — Encrypt sensitive data in AWS Secrets Manager or Systems Manager Parameter Store.</li><li><strong>Code Signing</strong> — Ensure the integrity of application code and packages.</li><li><strong>Secure Key Management</strong> — Control key access across multiple AWS accounts.</li></ul><h3>Step by Step Procedures</h3><p>This guide walks you through setting up <strong>AWS KMS</strong>, creating an <strong>EC2 instance</strong>, encrypting a <strong>file</strong>, and managing access through IAM roles and policies.</p><h3>Step 1: Set Up an AWS KMS Key</h3><p><em>Originally published at </em><a href="https://www.notion.so/AWS-Key-Management-Service-KMS-for-data-encryption-and-decryption-2b96e49772b38067a327cb96cfdbcf52?source=copy_link"><em>https://organic-meadow-cb2.notion.site</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3247d6098ed9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[️ Build a Private Tunnel to AWS EC2 with OpenVPN — No Public IPs Needed ]]></title>
            <link>https://medium.com/@aakashrana7/%EF%B8%8F-build-a-private-tunnel-to-aws-ec2-with-openvpn-no-public-ips-needed-1e37a9ba7b43?source=rss-32b468be1ec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e37a9ba7b43</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-tutorial]]></category>
            <category><![CDATA[private-ec2-tunnel]]></category>
            <category><![CDATA[aws-ec2-instance]]></category>
            <category><![CDATA[aws-openvpn]]></category>
            <dc:creator><![CDATA[Aakash Rana]]></dc:creator>
            <pubDate>Thu, 10 Jul 2025 11:51:29 GMT</pubDate>
            <atom:updated>2025-07-10T11:51:29.017Z</atom:updated>
            <content:encoded><![CDATA[<h3>🛠️ Build a Private Tunnel to AWS EC2 with OpenVPN — No Public IPs Needed 🔐</h3><h3>1. Introduction</h3><p>In cloud computing, keeping your infrastructure secure is more important than ever. When accessing EC2 (Elastic Compute Cloud) instances on AWS, exposing them directly to the internet can lead to potential threats like unauthorized access and brute-force attacks.</p><p>In this article, I’ll guide you through creating a <strong>private and secure tunnel using OpenVPN</strong> to access your EC2 instances — without ever needing to open them to the public internet. It’s a simple yet powerful solution for anyone who values cloud security.</p><h3>2. Problem Statement</h3><p>By default, many teams access their EC2 instances through public IP addresses, using SSH over the open internet. While this works, it’s not the most secure method and can expose your infrastructure to threats like brute-force attacks or unauthorized access.</p><p><strong>What is it?</strong><br> In many secure cloud architectures, EC2 instances are launched inside <strong>private subnets</strong> with <strong>no public IP addresses</strong>. This setup enhances security by making sure these instances can’t be accessed directly from the internet.</p><p>But how do you connect to these instances when they’re private?</p><p>This is where <strong>OpenVPN</strong> plays a key role. It creates a <strong>secure, encrypted tunnel</strong> from your local device to your AWS network. By setting up an OpenVPN server in a <strong>public subnet</strong>, you can connect to it from your device, and once you’re inside, it feels like you’re <strong>inside the same private network</strong>. From there, you can SSH into private EC2 instances using their <strong>private IP addresses</strong> — without ever exposing them to the outside world.</p><h3>3. Solution Overview</h3><p>The goal is to set up a <strong>VPN tunnel</strong> that allows you to securely connect to your AWS Virtual Private Cloud (VPC), and from there, access your private EC2 instances without exposing them to the outside world.</p><p>Here’s what we’ll do:</p><ol><li>Launch an EC2 instance and install OpenVPN on it.</li><li>Configure the VPN server and client settings.</li><li>Connect to the VPN from your local machine.</li><li>Access your private EC2 instances via their private IPs using the VPN tunnel.</li></ol><h3>4. AWS Services We’ll Use</h3><p>Let’s take a look at the AWS services we’ll use in this task:</p><ul><li><strong>EC2 (Elastic Compute Cloud):</strong><br> This is where we’ll host our VPN server and the target private instance. EC2 is simply a virtual server in the cloud.</li><li><strong>VPC (Virtual Private Cloud):</strong><br> A logically isolated network in AWS where our EC2 instances live. It ensures your resources are securely separated from other users on AWS.</li><li><strong>Security Groups:</strong><br> These act like virtual firewalls. We’ll use them to control which traffic is allowed to and from our EC2 instances.</li><li><strong>Elastic IP (optional):</strong><br> A static public IP address we can attach to our OpenVPN server so that it remains accessible from the internet.</li></ul><h3><strong>5. Step-by-Step Implementation</strong></h3><h3>Step 1: Launch a Dedicated VPN EC2 Instance</h3><p>First, we’ll create the EC2 instance that will serve as our VPN gateway:</p><ol><li>Navigate to the <strong>EC2 Dashboard</strong> → <strong>Instances</strong> → <strong>Launch Instance</strong></li><li>Select <strong>Ubuntu</strong> as your AMI</li><li>Choose an instance type (t2.micro works well for testing and is free-tier eligible)</li><li>Create or select an existing key pair for SSH access</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WT0jPkoa6f6caP1kxLVO_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MTy-VYZUC4quikSzu_qIvQ.png" /></figure><h3>Step 2: Configure Security Groups</h3><p>Security group configuration is crucial for the VPN server to function properly:</p><ol><li>Under <strong>Network Settings</strong>, click <strong>Edit</strong></li><li>Configure the security group with the following rules:</li></ol><ul><li>Type: SSH — Port 22 (for administrative access)</li><li>Type: UDP — Port 1194 (standard OpenVPN port)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g7yfm_xdzrdDuB16TzcUJw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uyunJ-uu-puXm5kxpAFi1g.png" /></figure><p>Complete the configuration and launch your instance.</p><h3>Step 3: Connect to Your EC2 Instance</h3><p>Once your instance is running, connect via SSH:</p><pre>ssh -i /path/to/key.pem ubuntu@your-ec2-public-ip</pre><h3>Step 4: Install and Configure OpenVPN</h3><p>Now for the exciting part — setting up your VPN server:</p><pre># Update system packages<br>sudo apt update<br>sudo apt upgrade -y<br><br># Download OpenVPN installer script<br>wget https://git.io/vpn -O openvpn-install.sh<br><br># Make it executable<br>chmod +x openvpn-install.sh<br><br># Run the installer<br>sudo ./openvpn-install.sh</pre><p>Follow the prompts to create your VPN profile:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lAOcD1evY-XeRjNFOjlDjg.png" /></figure><p>The installer will generate a client configuration file (*.ovpn) that contains everything needed to connect to your VPN.</p><h3>Step 5: Download the Configuration File</h3><p>Transfer the .ovpn file to your local machine using SCP:</p><pre>scp -i &lt;path-of-pemfile&gt; ubuntu@&lt;public-ip-address&gt;:/home/ubuntu/&lt;.ovpnfilename&gt; &lt;path-where you want to download in local&gt;</pre><p>The configuration file will download to your specified location:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*S1P1K5Me5-1j_8zh.png" /></figure><h3>Step 6: Connect Using OpenVPN Client</h3><ol><li>Download and install the <a href="https://openvpn.net/community-downloads/">OpenVPN client</a> for your operating system</li><li>Open the OpenVPN client</li><li>Import your .ovpn configuration file</li></ol><h3>Step 7: Verify Your Connection</h3><p>Once connected, your OpenVPN client will display connection details:</p><p>You’ll also notice a VPN icon in your system tray, indicating an active secure connection:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/0*_VgYPaplFaZf3jEn.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/0*n3MWTNaSe-FHmLuD.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/0*byFe6nxQCjwAfhV6.png" /></figure><h3>Testing Your Connection</h3><p>With the VPN active, you can now:</p><ul><li>Connect to private EC2 instances using their private IP addresses</li><li>Access internal AWS services securely</li><li>Browse the internet through your EC2 instance’s IP (useful for testing geolocation-restricted services)</li></ul><p>Try pinging a private instance to confirm connectivity:</p><pre>ping 10.0.0.123</pre><h3>Conclusion</h3><p>By setting up <strong>OpenVPN on an EC2 instance</strong>, we’ve successfully built a <strong>secure and private tunnel</strong> into our AWS environment. This allowed us to access private EC2 instances <strong>without assigning public IPs</strong> — a major step toward strengthening our cloud security.</p><p>All our traffic to the private instances is now routed through an <strong>encrypted VPN tunnel</strong>, which ensures it remains <strong>confidential, authenticated, and shielded</strong> from external threats. We’ve essentially removed multiple common attack vectors such as <strong>brute-force attempts, port scanning</strong>, and <strong>unauthorized access</strong>.</p><p>What’s even better is that this solution is both <strong>simple and cost-effective</strong>. With just a small amount of setup time, we achieved <strong>secure remote access</strong> without complex networking configurations or expensive third-party tools.</p><p>In the end, we proved that <strong>cloud security doesn’t have to be complicated</strong>. By using OpenVPN in combination with AWS, we created a reliable, private, and secure access path — all while keeping our infrastructure off the public internet.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e37a9ba7b43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ensuring Consistent Data Access in a Scalable Web Application on AWS Using ALB and EFS ]]></title>
            <link>https://medium.com/@aakashrana7/ensuring-consistent-data-access-in-a-scalable-web-application-on-aws-using-alb-and-efs-f7de26605449?source=rss-32b468be1ec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7de26605449</guid>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[aws-efs]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Aakash Rana]]></dc:creator>
            <pubDate>Tue, 22 Apr 2025 20:37:44 GMT</pubDate>
            <atom:updated>2025-04-22T20:37:44.230Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Problem Statement</h3><p>A company initially deployed a web application on AWS using a single <strong>Amazon EC2 instance</strong> with an attached <strong>Amazon EBS volume</strong> to store user-uploaded documents. To enhance <strong>scalability and availability</strong>, they replicated the setup by launching a second <strong>EC2 instance</strong> in another <strong>Availability Zone</strong>, each with its own <strong>EBS volume</strong>. Both instances were placed behind an <strong>Application Load Balancer (ALB)</strong> to distribute traffic dynamically.</p><p>However, after implementing this architecture, users encountered an issue: refreshing the website resulted in inconsistent document visibility. Depending on which EC2 instance processed the request, users could only see a <strong>subset of their uploaded documents</strong>, rather than a unified collection. This inconsistency arose because the <strong>uploaded files were stored locally on each EC2 instance’s EBS volume</strong>, rather than in a shared storage system.</p><h3>2. Solution Overview</h3><p>To resolve this inconsistency and ensure all uploaded documents are <strong>accessible from any EC2 instance</strong>, the architecture needs a <strong>centralized storage solution</strong> that both instances can access simultaneously. <strong>Amazon Elastic File System (EFS)</strong> provides a <strong>highly available, scalable, and shared file system</strong> that can be mounted across multiple EC2 instances, regardless of the Availability Zone. By integrating <strong>EFS</strong>, all uploaded files are stored in a single location, ensuring seamless file access regardless of which instance serves the request.</p><h3>3. AWS Services Utilized</h3><ol><li><strong>Amazon EC2 (Elastic Compute Cloud)</strong> — A scalable cloud computing service that provides virtual machines to host applications.</li></ol><ul><li><strong>Purpose in this solution:</strong> Hosts the web application on multiple instances to ensure availability and scalability.</li></ul><p><strong>2. Application Load Balancer (ALB)</strong> — A managed service that automatically distributes incoming network traffic across multiple targets for improved reliability and performance.</p><ul><li><strong>Purpose in this solution:</strong> Balances user requests between the two EC2 instances, ensuring optimal resource utilization and fault tolerance.</li></ul><p><strong>3. Amazon EFS (Elastic File System)</strong> — A fully managed, scalable, and shared file storage system designed for use with multiple EC2 instances.</p><ul><li><strong>Purpose in this solution:</strong> Provides a centralized storage location for uploaded files, ensuring that all instances have simultaneous access to the same data.</li></ul><p><strong>4. AWS IAM (Identity and Access Management)</strong> — A security service that controls access to AWS resources through role-based policies and permissions.</p><ul><li><strong>Purpose in this solution:</strong> Grants EC2 instances the necessary permissions to read and write files to the shared EFS storage securely.</li></ul><p><strong>5. Amazon Route 53 (Optional)</strong> — A scalable domain name system (DNS) web service that facilitates domain registration and traffic routing.</p><ul><li><strong>Purpose in this solution:</strong> Enables the assignment of a custom domain name to the web application, enhancing accessibility and user experience.</li></ul><h3>4. Understand the Concept</h3><p>The inconsistency in file visibility arises because <strong>EBS volumes are tied to individual EC2 instances</strong> and cannot be shared across multiple instances. When a user uploads a document, it is stored locally on the <strong>specific EC2 instance that processed the request</strong>. Since the <strong>ALB alternates requests between the two instances</strong>, users only see the files stored on the instance handling their request at that moment.</p><p>By <strong>mounting an Amazon EFS file system to both EC2 instances</strong>, all uploaded documents are stored in a <strong>shared storage location</strong> instead of being confined to separate EBS volumes. This ensures:</p><ul><li><strong>All uploaded files are accessible from any EC2 instance</strong>, regardless of which one serves the request.</li><li><strong>High availability</strong> since EFS is designed to operate across multiple Availability Zones.</li><li><strong>Automatic scaling</strong> to accommodate growing storage needs without requiring manual intervention.</li></ul><h3>5. Architecture Details</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ix1yL9dxrMBjP0QWhj-fWA.png" /><figcaption>Figure: Architectural Diagram (source: genesesolution.com)</figcaption></figure><ol><li><strong>Amazon EC2 Instances</strong><br>Two <strong>EC2 instances</strong> are launched in different <strong>Availability Zones</strong> for high availability. These instances host the web application and serve the users’ requests.</li><li><strong>Application Load Balancer (ALB)</strong><br>The <strong>ALB</strong> sits in front of the EC2 instances and routes incoming user traffic between them. It balances the load to ensure no single instance is overwhelmed.</li><li><strong>Amazon EFS (Elastic File System)</strong><br>Both EC2 instances are connected to the <strong>EFS</strong> file system, which serves as the <strong>shared storage</strong>. This allows both instances to access the same documents uploaded by users, ensuring consistency in file visibility.</li><li><strong>IAM Roles</strong><br><strong>IAM roles</strong> are used to grant the necessary permissions for the EC2 instances to access the <strong>EFS file system</strong> securely. This ensures only authorized instances can read/write to the shared storage.</li></ol><blockquote>Let’s proceed with a detailed, step-by-step tutorial to demonstrate and implement the solution. This guide will walk you through the entire process, from setting up the infrastructure to configuring the necessary services to ensure consistent file access across your EC2 instances.</blockquote><h3>6. Step-by-step Demonstration</h3><h3>Step 1: Set Up Two EC2 Instances</h3><h4><strong>1.1: Launch an EC2 Instance in two devices(you and your friend’s AWS Account)</strong></h4><ol><li><strong>Log in to AWS Console</strong> and go to the <strong>EC2 Dashboard</strong>.</li><li>Click on <strong>Launch Instance</strong> and configure the following:</li></ol><ul><li><strong>AMI</strong>: Choose <strong>Amazon Linux 2</strong> or <strong>Ubuntu 22.04</strong>.</li></ul><blockquote>(For follow-along with me, use Ubuntu)</blockquote><ul><li><strong>Instance Type</strong>: Select <strong>t2.micro</strong> (free-tier eligible).</li><li><strong>Key Pair</strong>: Create or use an existing key pair for SSH access.</li></ul><p><strong>3. Security Group</strong>:</p><ul><li>Create a new security group.</li><li>Allow <strong>SSH (port 22)</strong> only from your IP.</li><li>Allow <strong>HTTP (port 80)</strong> only from a specific IP range (e.g., 203.0.113.0/32).</li></ul><p><strong>4. Storage</strong>: Use at least <strong>8GB</strong> of General Purpose SSD (gp2).</p><ol><li>Click <strong>Launch</strong> and wait for the instance to be in the “running” state.</li></ol><h4>1.2: Connect to the EC2 Instance</h4><ol><li>Open a terminal and connect via SSH:</li></ol><pre>ssh -i your-key.pem ec2-user@your-instance-public-ip</pre><p>(For Ubuntu, use ubuntu instead of ec2-user.)</p><h3>Step 2: Install Dependencies and Host a Website on Both EC2s</h3><ol><li><strong>Update and Install Dependencies</strong><br> Run these commands on both EC2 instances:</li></ol><pre>sudo yum update -y  # For Amazon Linux<br>sudo apt update -y  # For Ubuntu<br>sudo yum install -y httpd php php-cli unzip wget  # Amazon Linux<br>sudo apt install -y apache2 php libapache2-mod-php unzip wget  # Ubuntu</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*pza-Gm2aaQrVMQGqsBWSdg.png" /></figure><p><strong>2. Start and Enable Web Server</strong></p><pre>sudo systemctl start httpd  # Amazon Linux<br>sudo systemctl enable httpd<br>sudo systemctl start apache2  # Ubuntu<br>sudo systemctl enable apache2</pre><p><strong>3. Navigate to the web root:</strong></p><pre>cd /var/www/html</pre><blockquote><strong>Apache2</strong> creates an index.html file by default which is in this directory.</blockquote><blockquote><strong>Delete it </strong>or <strong>edit it </strong>with the your code for the site. Share the code with your friend as well.</blockquote><p><strong>3.1 To delete default file and add a new php file:</strong></p><pre>sudo rm index.html  //delete index.html<br>sudo nano index.php  //create and open index.php</pre><blockquote>Write your code for the site or copy below written code<br>Click `<strong>ctrl+X</strong>` then `<strong>Y</strong>` and `<strong>Enter</strong>`</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*D799w9lWgCUaWgieW_3wRw.png" /></figure><h4><strong>My Code looks like-</strong></h4><pre>&lt;!DOCTYPE html&gt;<br> &lt;html lang=&quot;en&quot;&gt;<br> &lt;head&gt;<br> &lt;meta charset=&quot;UTF-8&quot;&gt;<br> &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br> &lt;title&gt;My Simple Website&lt;/title&gt;<br> &lt;link href=&quot;https://cdn.jsdelivr.&quot; rel=&quot;stylesheet&quot;&gt;<br> &lt;style&gt;<br> body {<br> background-color: #f8f9fa;<br> }<br> .container {<br> max-width: 600px;<br> margin-top: 50px;<br> background: white;<br> padding: 20px;<br> border-radius: 10px;<br> box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);<br> }<br> .uploaded-files {<br> margin-top: 20px;<br> }<br> &lt;/style&gt;<br> &lt;/head&gt;<br> &lt;body&gt;<br> <br> &lt;div class=&quot;container text-center&quot;&gt;<br> &lt;h1 class=&quot;mb-3&quot;&gt;Welcome to My Website!&lt;/h1&gt;<br> &lt;p&gt;This is a simple website hosted on an EC2 instance.&lt;/p&gt;<br> &lt;a href=&quot;#&quot; class=&quot;btn btn-primary&quot;&gt;Learn More&lt;/a&gt;<br> <br> &lt;! - File Upload Form →<br> &lt;h2 class=&quot;mt-5&quot;&gt;Upload a File&lt;/h2&gt;<br> &lt;form action=&quot;index.php&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;&gt;<br> &lt;input type=&quot;file&quot; name=&quot;file&quot; class=&quot;form-control mb-3&quot;&gt;<br> &lt;button type=&quot;submit&quot; name=&quot;upload&quot; class=&quot;btn btn-success&quot;&gt;Upload&lt;/button&gt;<br> &lt;/form&gt;<br> <br> &lt;?php<br> // Handle file upload<br> if (isset($_POST[&#39;upload&#39;])) {<br> $target_dir = &quot;/var/www/html/uploads/&quot;;<br> $target_file = $target_dir . basename($_FILES[&quot;file&quot;][&quot;<br> <br> // Create the directory if it doesn&#39;t exist<br> if (!file_exists($target_dir)) {<br> mkdir($target_dir, 0777, true);<br> }<br> <br> // Move uploaded file to the target directory<br> if (move_uploaded_file($_FILES[&quot;<br> echo &quot;&lt;div class=&#39;alert alert-success mt-3&#39;&gt;File uploaded successfully!&lt;/div&gt;&quot;;<br> } else {<br> echo &quot;&lt;div class=&#39;alert alert-danger mt-3&#39;&gt;Error uploading file.&lt;/div&gt;&quot;;<br> }<br> }<br> <br> // Display uploaded files<br> $dir = &quot;uploads&quot;;<br> if (is_dir($dir)) {<br> $files = scandir($dir);<br> echo &quot;&lt;div class=&#39;uploaded-files&#39;&gt;&quot;;<br> echo &quot;&lt;h3&gt;Uploaded Files:&lt;/h3&gt;&quot;;<br> echo &quot;&lt;ul class=&#39;list-group&#39;&gt;&quot;;<br> foreach ($files as $file) {<br> if ($file !== &quot;.&quot; &amp;&amp; $file !== &quot;..&quot;) {<br> echo &quot;&lt;li class=&#39;list-group-item&#39;&gt;&lt;a href=&#39;$dir/$file&#39; target=&#39;_blank&#39;&gt;$file&lt;/a&gt;&lt;/li&gt;<br> }<br> }<br> echo &quot;&lt;/ul&gt;&quot;;<br> echo &quot;&lt;/div&gt;&quot;;<br> }<br> ?&gt;<br> <br> &lt;/div&gt;<br> <br> &lt;/body&gt;<br> &lt;/html&gt;</pre><p><strong>4. Create a directory uploads where the uploaded files get stored:</strong></p><pre>sudo mkdir /var/www/html/uploads</pre><p><strong>4.1 Change access permission of the directory:</strong></p><pre>sudo chmod -R 777 /var/www/html/uploads</pre><p><strong>5. Restart the web server:</strong></p><pre>sudo systemctl restart httpd  # Amazon Linux<br>sudo systemctl restart apache2  # Ubuntu</pre><p><strong>5. Test the Website:</strong></p><p>→ Visit http://&lt;EC2_PUBLIC_IP&gt; in a browser.</p><p><strong>6. Upload a file from the website and verify it:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8HZucn0yekwWaSyozh6AmQ.png" /></figure><blockquote>To list the uploaded files in the server:</blockquote><pre>cd /var/www/html/uploads  //navigate to the directory<br>ls -l  //list them</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*Wfr7bAeVeDmqjpP_ElRVGg.png" /></figure><p><strong>MAKE SURE BOTH USERS HAVE COMPLETED ABOVE TASK UPTO HERE</strong></p><h3><strong><em>Step 3- Connect both instances using ALB</em></strong></h3><p><strong><em>(only one of the user needs to do this)</em></strong></p><ol><li><strong><em>Open AWS Console</em></strong></li></ol><blockquote><em>Go to instances → load balancers → ALB</em></blockquote><blockquote><em>Create a new ALB</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sf0slwHLJFgtWNvdkCuMjw.png" /></figure><p><strong><em>2. Create Target Group that connects both EC2s</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HBgrgBA5g5rGFnb6B64F_A.png" /></figure><p><strong><em>3. Select a default VPC and make sure you have selected 80 port</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bkghJpvm3FNkuiIaTAx8wA.png" /></figure><p><strong><em>4. Select both EC2s that you want to connect together with(you and your friend’s)</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0F6uBSq87bnQ8bZXd5w74g.png" /></figure><p><strong><em>5. Select both security groups of both EC2s</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_QPlAoHUFRSpm-HQwzP4bw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QIVdfvVPbiMXd3sJWKotDA.png" /></figure><blockquote><em>ALB is created.</em></blockquote><blockquote><em>Now Open the site through the DNS name of the ALB</em>(e.g., my-web-app-alb-1234567890.us-west-1.elb.amazonaws.com)</blockquote><p><em>Refresh and you may see the file from other ec2- (you can try this on both devices)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErBW33_oLDv637yl8XyM0w.png" /><figcaption>The shown file was uploaded by my friend from his EC2</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8HZucn0yekwWaSyozh6AmQ.png" /><figcaption>Refresh again and you may see the file you uploaded</figcaption></figure><blockquote><em>THIS IS THE MAIN ISSUE. TO RESOLVE THIS WE NEED EFS-</em></blockquote><blockquote><em>Right now, your EC2 instances store uploaded files </em><strong><em>locally</em></strong><em>, which means each instance has its own separate storage. Since your </em><strong><em>Application Load Balancer (ALB)</em></strong><em> distributes requests randomly between the two EC2 instances, sometimes you see the files from one instance and sometimes from the other.</em></blockquote><blockquote>To fix this, you need to store uploaded files in a <strong>shared storage</strong> so that both EC2 instances can access the same uploaded files. <strong>Amazon Elastic File System (EFS)</strong> is perfect for this because it allows multiple EC2 instances to read and write to the same file system.</blockquote><h3><strong><em>Step 4: Setup EFS for shared file storage:</em></strong></h3><ol><li><strong>Go to AWS Console → EFS</strong></li><li><strong>Create a new file system</strong></li></ol><ul><li>Click <strong>Create file system</strong>.</li><li><strong>Name:</strong> Give it a name (e.g., my-efs).</li><li><strong>VPC:</strong> Select the same <strong>VPC</strong> where your EC2 instances are running.</li><li><strong>Availability Zones (AZs):</strong> Keep default settings (Multi-AZ setup).</li></ul><p><strong>3. Configure Network Access</strong></p><p><strong>3.1 Attach security groups</strong>:</p><ul><li>Use the <strong>same security group</strong> as your EC2 instances (or create a new one allowing NFS access).</li><li><strong>Inbound Rules:</strong> Add a rule to allow <strong>NFS (port 2049)</strong> from the security group of your EC2 instances.</li></ul><p><strong>3.2 Create and Save the EFS File System ID</strong></p><ul><li>Click <strong>Create</strong>.</li><li>After creation, <strong>copy the File System ID</strong> (e.g., fs-12345678).</li></ul><p><strong>4. Mount EFS on Both EC2 Instances</strong></p><p><strong>4.1 Install NFS Client on Both EC2 Instances</strong></p><ul><li>SSH into each EC2 instance and run:</li></ul><pre>sudo apt update<br>sudo apt install -y nfs-common</pre><p><strong><em>4.2 Navigate to a directory where the EFS will be mounted-</em></strong></p><pre>cd ../uploads</pre><p><strong><em>4.3 Unmount any existing local storage directory</em></strong><em> (to avoid conflicts):</em></p><pre>→ sudo umount /var/www/html/uploads</pre><blockquote>If it says &quot;not mounted,&quot; ignore it and proceed.</blockquote><p><strong>4.4. Now mount the EFS in the current directory:</strong></p><pre>sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 \<br>&lt;your-efs-id&gt;.efs.&lt;aws-region&gt;.amazonaws.com:/ /var/www/html/uploads</pre><blockquote>Replace &lt;your-efs-id&gt; with your <strong>EFS File System ID</strong> and &lt;aws-region&gt; with your <strong>AWS region</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*KNfXT5I3uxmridF_lELIKw.png" /></figure><p><strong><em>Verify that EFS is mounted correctly</em></strong><em>:</em></p><pre>→ df -h</pre><ul><li>You should see an entry like this:</li></ul><pre>fs-12345678.efs.us-east-1.amazonaws.com:/  8.0E  0  8.0E   0% /var/www/html/uploads</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*q2qEUQSU8D2dykd3IWkucQ.png" /></figure><blockquote>OR in my case:</blockquote><p><strong><em>Make the mount permanent</em></strong><em> by adding it to </em><em>/etc/fstab:</em></p><pre>sudo nano /etc/fstab</pre><p><strong>Add the following line at the end of the file</strong> (replace &lt;your-efs-id&gt; and &lt;aws-region&gt;):</p><pre>&lt;your-efs-id&gt;.efs.&lt;aws-region&gt;.amazonaws.com:/ /var/www/html/uploads nfs4 defaults,_netdev 0 0</pre><ul><li>Save and exit (CTRL + X, then Y, then ENTER).</li></ul><p><strong>6. Test file upload</strong>:</p><ul><li>Go to your <strong>ALB DNS URL</strong> in a browser.</li><li>Upload a file from one EC2 instance.</li><li>Refresh and check if the uploaded file appears on both instances.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rJYjOgHhiVVeF9u_LZmlcA.png" /></figure><p>Now, both EC2 instances are <strong>sharing the same EFS directory</strong>, so files will be <strong>visible on both instances</strong>, no matter which one the ALB routes traffic to.</p><p><em>Upload a new file from any device and refresh website on both devices:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bpnRdI8cEctVBoVGEi2v4g.png" /></figure><h3><strong>Conclusion:</strong></h3><p>This architecture effectively resolves the issue of inconsistent document access by ensuring both EC2 instances access a shared, centralized storage (EFS), allowing the application to provide a consistent user experience regardless of which instance processes the request.</p><p>By replacing instance-specific EBS storage with <strong>Amazon EFS</strong>, the company ensures <strong>consistent file access across all EC2 instances</strong> while maintaining scalability and high availability. This approach eliminates file inconsistency issues and enhances user experience by providing a seamless and reliable document storage solution.</p><p>For further optimization, additional <strong>backup mechanisms</strong>, <strong>performance tuning</strong>, and <strong>content delivery solutions like Amazon CloudFront</strong> could be considered to improve performance and reliability. 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7de26605449" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating S3 Event Notifications Using AWS Lambda and SNS for Real-Time Alerts ]]></title>
            <link>https://medium.com/@aakashrana7/automating-s3-event-notifications-using-aws-lambda-and-sns-for-real-time-alerts-6379f69b9d11?source=rss-32b468be1ec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/6379f69b9d11</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[aws-sns]]></category>
            <dc:creator><![CDATA[Aakash Rana]]></dc:creator>
            <pubDate>Fri, 07 Mar 2025 18:42:28 GMT</pubDate>
            <atom:updated>2025-03-07T18:42:28.084Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Problem Statement</h3><p>In many applications, files are frequently uploaded, modified, or deleted in an Amazon S3 bucket. However, manually monitoring these changes is inefficient and impractical. Organizations need an automated solution that triggers actions based on S3 events and notifies relevant stakeholders in real time.</p><p>For example, a company may want to:</p><ul><li>Notify users when a file is uploaded.</li><li>Trigger data processing workflows.</li><li>Alert administrators when an unauthorized file is deleted.</li></ul><p>Manually handling these tasks increases operational overhead and the risk of missing critical events. A better approach is to automate event-driven notifications using AWS services.</p><h3>2. Solution Overview</h3><p>To automate S3 event notifications, we will:</p><ul><li>Configure <strong>Amazon S3 Event Notifications</strong> to detect file changes.</li><li>Use <strong>AWS Lambda</strong> as an event-driven compute service to process events dynamically.</li><li>Integrate <strong>Amazon SNS (Simple Notification Service)</strong> to send notifications via email, SMS, or other endpoints when an event occurs.</li></ul><p>This architecture enables a <strong>fully automated, serverless</strong> notification system, ensuring real-time alerts with minimal maintenance.</p><h3>3. AWS Services We’ll Use</h3><ol><li><strong>Amazon S3 (Simple Storage Service)</strong> — A scalable object storage service that securely stores files and generates event notifications when objects are created, updated, or deleted.<br><strong>Usage:</strong> S3 will trigger events when files are modified.</li><li><strong>AWS Lambda</strong> — A serverless compute service that runs code in response to triggers, eliminating infrastructure management.<br><strong>Usage:</strong> Lambda will process S3 events and trigger notifications.</li><li><strong>Amazon SNS (Simple Notification Service)</strong> — A messaging service that delivers notifications via email, SMS, or other endpoints.<br><strong>Usage:</strong> SNS will send real-time alerts when an S3 event occurs.</li><li><strong>AWS IAM (Identity and Access Management)</strong> — A security service that manages access permissions between AWS resources.<br><strong>Usage:</strong> IAM will control access between S3, Lambda, and SNS.</li></ol><h3>4. Architecture Explanation in Brief</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*NV78mFe5wYFDMPCeic3AgQ.jpeg" /><figcaption>Figure: AWS S3 Event Notification Architecture with Lambda and SNS</figcaption></figure><ol><li>A user uploads, modifies, or deletes a file in an <strong>Amazon S3 bucket</strong>.</li><li>S3 generates an <strong>event notification</strong> (e.g., ObjectCreated, ObjectRemoved).</li><li>This event triggers an <strong>AWS Lambda function</strong>, which processes the event data.</li><li>The Lambda function publishes a message to an <strong>Amazon SNS topic</strong>.</li><li>SNS delivers the notification to <strong>subscribers</strong> (email, SMS, or application endpoints).</li></ol><p>This serverless architecture is <strong>scalable, cost-effective, and maintenance-free</strong>, ensuring real-time processing of S3 events.</p><blockquote><strong>Let’s dive into the step-by-step tutorial:</strong></blockquote><h3>4. Step-by-step Tutorial:</h3><h3>Step 1: Create an S3 Bucket</h3><ol><li>Go to the <strong>AWS S3 Console</strong>.</li><li>Click <strong>“Create bucket”</strong>.</li><li>Enter a <strong>unique name</strong> for your bucket.</li><li>Choose the AWS region closest to you.</li><li><strong>Disable Block Public Access</strong> (only if needed).</li><li>Click <strong>“Create bucket”</strong>.</li></ol><h3>Step 2: Create an SNS Topic and Subscription</h3><ol><li>Go to the <strong>SNS Console</strong>.</li><li>Click <strong>“Create topic”</strong>.</li><li>Choose <strong>Standard</strong> and enter a <strong>topic name</strong> (e.g., s3-file-uploads).</li><li>Click <strong>“Create topic”</strong>.</li><li>Copy the <strong>Topic ARN</strong> (you will need it later).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kBcQXOsirOU7vZ5T_zmX5g.png" /><figcaption>SNS Topic Dashboard</figcaption></figure><h3>Create an SNS Subscription</h3><ol><li>In the <strong>SNS Console</strong>, click on your newly created topic.</li><li>Click <strong>“Create subscription”</strong>.</li><li>Select <strong>Protocol</strong> (choose <strong>Email</strong> or <strong>SMS</strong>).</li><li>Enter the <strong>Email/SMS</strong> where notifications should be sent.</li><li>Click <strong>“Create subscription”</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0iE1eMy355jx7EOYftUH_A.png" /><figcaption>SNS Subscription Dashboard</figcaption></figure><p><strong>6. Check your email</strong> and confirm the subscription.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EavIA0tW_T0Wd6eKcV0zFA.png" /></figure><p>After confirmation, you should receive something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*S4CnKr7qWyTUWO7Po4qCag.png" /></figure><h3>Step 3: Create an IAM Role for Lambda</h3><ol><li>Go to the <strong>IAM Console</strong> → <strong>Roles</strong> → <strong>Create Role</strong>.</li><li>Choose <strong>AWS Service</strong> → Select <strong>Lambda</strong>.</li><li>Click <strong>Next</strong>.</li><li>Attach the following <strong>policies</strong>:</li></ol><ul><li>AmazonS3ReadOnlyAccess (To read from S3)</li><li>AmazonSNSFullAccess (To publish to SNS)</li></ul><p>5. Click <strong>Next</strong>, enter a <strong>Role name</strong> (e.g., Lambda-S3-SNS-Role), and <strong>Create Role</strong>.</p><p>6. Copy the <strong>Role ARN</strong> (you will need it later).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BP6NiQ2t3FC9ODrOA4BCEA.png" /><figcaption>IAM Policies attached</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wl-5n7hfjBrrGoU_SEYHgg.png" /><figcaption>IAM Role Dashboard</figcaption></figure><h3>Step 4: Create a Lambda Function</h3><ol><li>Go to the <strong>AWS Lambda Console</strong>.</li><li>Click <strong>“Create function”</strong> → <strong>Author from scratch</strong>.</li><li>Enter a <strong>function name</strong> (e.g., S3ToSNSLambda).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uY888pvkHpiFvS7MY3PDrg.png" /></figure><p>4. Choose <strong>Runtime</strong> → <strong>Python 3.x (or Node.js, depending on your preference)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*niydv5k8pPivV6-lwXKXZQ.png" /></figure><p>5. Choose <strong>“Use an existing role”</strong>, and select the <strong>IAM role</strong> created earlier.</p><p>6. Click <strong>“Create function”</strong>.</p><h3>Step 5: Add Environment Variable for SNS</h3><ol><li>Inside your <strong>Lambda function</strong>, go to <strong>Configuration</strong> → <strong>Environment variables</strong>.</li><li>Click <strong>Edit</strong> → <strong>Add environment variable</strong>.</li><li>Key: SNS_TOPIC_ARN</li><li>Value: Paste the <strong>SNS Topic ARN</strong> from Step 2.</li><li>Click <strong>Save</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fVC83PMOXpkzL_r-cOcedQ.jpeg" /></figure><h3>Step 6: Write the Lambda Code</h3><p>Replace the default Lambda code with the following in the Code editor:</p><pre>import json<br>import boto3<br>import os<br><br># Initialize SNS client<br>sns_client = boto3.client(&#39;sns&#39;)<br><br># Load SNS topic ARN from environment variables<br>SNS_TOPIC_ARN = os.environ.get(&#39;SNS_TOPIC_ARN&#39;)<br><br>def lambda_handler(event, context):<br>    print(&quot;Received event: &quot; + json.dumps(event, indent=2))<br><br>    for record in event[&#39;Records&#39;]:<br>        event_name = record[&#39;eventName&#39;]<br>        bucket_name = record[&#39;s3&#39;][&#39;bucket&#39;][&#39;name&#39;]<br>        object_key = record[&#39;s3&#39;][&#39;object&#39;][&#39;key&#39;]<br><br>        message = f&quot;📢 S3 Event Notification 📢\n\n🔹 Event: {event_name}\n🔹 Bucket: {bucket_name}\n🔹 Object: {object_key}&quot;<br><br>        # Send SNS notification<br>        response = sns_client.publish(<br>            TopicArn=SNS_TOPIC_ARN,<br>            Message=message,<br>            Subject=&quot;S3 Event Notification&quot;<br>        )<br><br>        print(f&quot;✅ Notification sent! Message ID: {response[&#39;MessageId&#39;]}&quot;)<br><br>    return {&quot;statusCode&quot;: 200, &quot;body&quot;: json.dumps(&quot;Notification sent successfully!&quot;)}</pre><p>Click <strong>Deploy</strong> to save the changes.</p><h3>Step 7: Configure S3 Event Notifications to Trigger Lambda</h3><ol><li>Go to the <strong>S3 Console</strong>.</li><li>Click on your <strong>bucket name</strong>.</li><li>Go to the <strong>Properties</strong> tab.</li><li>Scroll down to <strong>Event notifications</strong> → Click <strong>“Create event notification”</strong>.</li><li>Enter a <strong>name</strong> (e.g., S3LambdaTrigger).</li><li>Under <strong>Event types</strong>, select <strong>“PUT”</strong> (for file uploads).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uK6XT7Sfe5skDPCdNACqaw.png" /></figure><ol><li>Choose <strong>Destination</strong> → Select <strong>Lambda function</strong>.</li><li>Select the Lambda function you created (S3ToSNSLambda).</li><li>Click <strong>Save changes</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2uixriIFM1VCsesMTg4scQ.png" /></figure><h3>Step 8: Test the Setup</h3><ol><li>Upload a file to your S3 bucket.</li><li>Check the <strong>AWS Lambda Logs</strong> in <strong>CloudWatch</strong> to see if the function ran.</li><li>Check your <strong>SNS Subscription</strong> (Email/SMS) for a notification.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ajTOKRPGELj9Dbdb2uFqdA.jpeg" /><figcaption>File Uploaded in S3</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*plVeVEkJNQ99ganMEu2lJQ.jpeg" /><figcaption>Email trigerred to notify the changes in S3</figcaption></figure><h3>Congratulations! 🎉</h3><p>You have successfully automated <strong>S3 event notifications</strong> using <strong>AWS Lambda and SNS</strong>. Now, whenever a file is uploaded, a notification will be sent automatically.</p><h3>5. Conclusion</h3><p>By integrating S3 Event Notifications with Lambda and SNS, we achieve an automated, event-driven notification system that eliminates manual monitoring. This approach improves efficiency, reduces operational costs, and enhances real-time alerting. Organizations can extend this setup further by integrating other AWS services like <strong>Amazon SQS for queue-based processing</strong> or <strong>AWS Step Functions for workflow automation</strong>.</p><p>This solution is ideal for businesses that require <strong>instant alerts on file changes</strong> for security, compliance, or workflow automation. 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6379f69b9d11" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>