<?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 Saugat Rijal on Medium]]></title>
        <description><![CDATA[Stories by Saugat Rijal on Medium]]></description>
        <link>https://medium.com/@saugatrijal99?source=rss-f75595ab59b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IoxxcI-A0Gx1_WfX5kIEuw.jpeg</url>
            <title>Stories by Saugat Rijal on Medium</title>
            <link>https://medium.com/@saugatrijal99?source=rss-f75595ab59b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 15:28:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saugatrijal99/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[Hosting a Static Website on AWS EC2 with Load Balancer and CloudFront]]></title>
            <link>https://medium.com/@saugatrijal99/hosting-a-static-website-on-aws-ec2-with-load-balancer-and-cloudfront-78fa19743fde?source=rss-f75595ab59b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/78fa19743fde</guid>
            <category><![CDATA[cloudfront]]></category>
            <category><![CDATA[static-website-hosting]]></category>
            <category><![CDATA[aws-cloud]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[load-balancer]]></category>
            <dc:creator><![CDATA[Saugat Rijal]]></dc:creator>
            <pubDate>Wed, 09 Jul 2025 06:47:12 GMT</pubDate>
            <atom:updated>2025-07-09T06:47:12.766Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In today’s digital world, delivering websites with high availability, speed, and reliability is essential for a great user experience. Hosting a static website on <strong>AWS EC2</strong> provides full control over your web server environment, while integrating it with an <strong>Application Load Balancer (ALB)</strong> ensures traffic is distributed efficiently across instances. To further enhance performance and global reach, <strong>Amazon CloudFront</strong>, AWS’s content delivery network (CDN), is used to cache and serve content from edge locations closer to users.</p><p>In this blog, we’ll walk you through how to:</p><ul><li>Host a static website on an EC2 instance</li><li>Set up a Load Balancer for high availability</li><li>Distribute content globally using CloudFront</li></ul><p>By the end of this guide, you’ll have a scalable and globally optimized static website running entirely on AWS infrastructure.</p><p>🖥️ Step 1: Host Static Web Page on EC2 Instance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*bSUTbP8Z37_JasF4D4TFKQ.png" /></figure><p>Host static web page and access it through public IP of EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*kqSvJKGXc5Vcl-KrrPSeEA.png" /></figure><p>🎯 Step 2: Create a Target Group</p><ul><li>Navigate to the <strong>EC2 Dashboard</strong> → <strong>Target Groups</strong>.</li><li>Click <strong>Create target group</strong>.</li><li>Select <strong>Target type</strong>: Instances.</li><li>Set <strong>Protocol</strong> to HTTP and <strong>Port</strong> to 80.</li><li>Register your running <strong>EC2 instance</strong> to this target group.</li><li>Click <strong>Create</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*7QgXf_ftCSFkg9PYtMVyeg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*m0bkYiAkXsOyzJYrP02YSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*dPnrdj3xW4FmjMY9k4yTpQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*uZR1x_7RcYwQHB5EWxKY1A.png" /></figure><p>⚖️ Step 3: Create an Application Load Balancer (ALB)</p><ol><li>Go to <strong>EC2 Dashboard</strong> → <strong>Load Balancers</strong> → Click <strong>Create Load Balancer</strong>.</li><li>Select <strong>Application Load Balancer</strong>.</li><li>Provide a name (e.g., static-web-alb).</li><li>Select <strong>Scheme</strong>: Internet-facing.</li><li>Select <strong>Listeners</strong>: HTTP on port 80.</li><li>Choose at least <strong>2 Availability Zones</strong> for high availability.</li><li>Under <strong>Target Group</strong>, select the one you created earlier.</li><li>Click <strong>Create Load Balancer</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*itfiSAAoyTstzuJgAPFVqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*lWFUxozaOEIE-WBfQXo3Ew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*-wXdwXxoG98udVIzlwOx3g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*bPsZIArjpD0rQciAFP8lvg.png" /></figure><p>Access Website via Load Balancer DNS:</p><p>Go to Load Balancers → Copying the <strong>DNS Name</strong>. Opening a browser to <a href="http://load-balancer-dns-name./"><strong>http://load-balancer-dns-name</strong>.</a> Our static website should be accessible via Load Balancer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*V-QSvu1f02FlVxw4JBqW6Q.png" /></figure><p>🌎 Step 5: Configure Amazon CloudFront (CDN)</p><ul><li>Navigate to the <strong>CloudFront Console</strong>.</li><li>Click <strong>Create Distribution</strong>.</li><li>Under <strong>Origin domain</strong>, paste the <strong>Load Balancer DNS name</strong> (e.g., static-web-alb-123456.us-east-1.elb.amazonaws.com).</li><li>Leave default settings or customize as needed (e.g., enable HTTPS, caching).</li><li>Click <strong>Create Distribution</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*NlYRBBmkvOc1xXUoWtDCUQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*W33uV-EybWe2EBYY_kvalQ.png" /></figure><h3>🚀 Step 6: Access Website via CloudFront</h3><ol><li>Once CloudFront distribution is deployed, go to the <strong>Distributions page</strong>.</li><li>Copy the <strong>Domain name</strong> of the distribution (e.g., d1234abcd.cloudfront.net).</li><li>Open your browser and access:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*-8FZVBIJVGTqPE_LpR4mTg.png" /></figure><h4>Conclusion</h4><p>By combining <strong>EC2</strong>, <strong>Load Balancer</strong>, and <strong>CloudFront</strong>, you’ve built a reliable, scalable, and globally optimized static website. This setup ensures fast content delivery, high availability, and better user experience making your static site ready for real-world traffic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78fa19743fde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing APIs with AWS Cognito: A Step-by-Step Guide]]></title>
            <link>https://medium.com/@saugatrijal99/securing-apis-with-aws-cognito-a-step-by-step-guide-f454167262bc?source=rss-f75595ab59b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f454167262bc</guid>
            <category><![CDATA[api-security]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[amazon-cognito]]></category>
            <category><![CDATA[amazon-api-gateway]]></category>
            <dc:creator><![CDATA[Saugat Rijal]]></dc:creator>
            <pubDate>Fri, 06 Jun 2025 05:22:54 GMT</pubDate>
            <atom:updated>2025-06-06T05:22:54.757Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*Shy5e0OT2z8qlHSUVMe5SA.png" /></figure><h4>Introduction</h4><p>Imagine you’re building a serverless application — a React frontend with an AWS Lambda-powered backend, exposed through Amazon API Gateway. You want users to sign up, log in, and securely interact with your API, ensuring only authenticated users can access sensitive endpoints. How do you achieve this without building an entire authentication system from scratch?</p><p>Enter <strong>Amazon Cognito</strong>, a fully managed user identity and authentication service. With <strong>Cognito and API Gateway</strong>, you can easily implement secure access controls for your APIs without handling passwords or tokens manually.</p><p>In this blog, you’ll learn how to secure your APIs with Amazon Cognito through a real-world scenario. By the end, your API will only be accessible to authenticated users, and you’ll have a scalable, secure solution ready for production.</p><h3>Step 1: Create an AWS Lambda Function</h3><ol><li><strong>Open AWS Console</strong> → Navigate to <strong>AWS Lambda</strong>.</li><li>Click <strong>Create function</strong>.</li><li>Under <strong>Create function</strong>, choose <strong>Author from scratch</strong>.</li><li>Configure:</li></ol><ul><li><strong>Function Name</strong>: Function-sau</li><li><strong>Runtime</strong>: Select your preferred language (e.g., Python, Node.js).</li><li><strong>Execution Role</strong>: Choose <strong>Create a new role with basic Lambda permissions</strong>.</li></ul><p>5. Click <strong>Create function</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*rdwYCEO6hVqjaeJu0qBKcg.png" /></figure><p><strong>6. Add Code to the Lambda Function</strong>:</p><ul><li>Use the existing code or Replace the default code with the following example (Python):</li></ul><pre>import json<br><br>def lambda_handler(event, context):<br>    # Your business logic here<br>    response = {<br>        &quot;statusCode&quot;: 200,<br>        &quot;body&quot;: json.dumps({<br>            &quot;message&quot;: &quot;Hello from your secure API!&quot;,<br>            &quot;input&quot;: event<br>        })<br>    }<br>    return response</pre><p><strong>7. Deploy the Lambda Function</strong>:</p><ul><li>Click <strong>Deploy</strong> to save your changes.</li></ul><h3>Step 2: Set Up API Gateway</h3><ol><li>In the <strong>AWS Console</strong>, search for <strong>API Gateway</strong> and open it.</li><li>Click <strong>Build</strong> under <strong>REST API</strong>.</li><li>Select <strong>New API</strong>, provide an <strong>API name</strong>, and choose <strong>Regional</strong> for the endpoint type.</li><li>Click <strong>Create API</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*CW09SL5ploObHohMCHZitw.png" /></figure><p><strong>Define API Resources and Methods</strong></p><ol><li>Select your <strong>API</strong> and navigate to <strong>Resources</strong>.</li><li>Click <strong>Create Method</strong>, select <strong>GET</strong>, and click the checkmark.</li><li>Choose method type as GET.</li><li>For <strong>Integration type</strong>, choose <strong>Lambda Function</strong>.</li><li>Enter the <strong>Lambda function name</strong> created in Step 1.</li><li>Click Create Method.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*cWCX8lqTdBP8wlntmSSFeg.png" /></figure><p>7. Click <strong>Deploy API</strong> under the <strong>Actions</strong> menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*SVxdzkRnaDECKFZN7tsYpA.png" /></figure><p>8. Create a <strong>new stage</strong>, name it (e.g., prod), and deploy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*yolMgfgT2qHSci2y6TOrNw.png" /></figure><p>9. Copy the <strong>Invoke URL</strong> from the <strong>Stages</strong> section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*T-TASYkXerIo5kjLeha9eA.png" /></figure><p>Test the API by pasting the <strong>Invoke URL</strong> in a browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*Q9kt214kpmAAnIrOpMfaKg.png" /></figure><h3>Step 3: Secure the API with AWS Cognito</h3><ol><li>In the <strong>AWS Console</strong>, search for <strong>Amazon Cognito</strong> and open it.</li><li>Click <strong>User Pools</strong> → <strong>Create user pool</strong>.</li><li>Configure the user pool:</li></ol><ul><li>Choose an <strong>Application Type</strong> and provide a <strong>Name</strong>.</li><li>Select <strong>Sign-in identifiers</strong> (e.g., email, username).</li><li>Select <strong>Required attributes</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*btBou-DGpye-Vj0dQAUh7A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*shs0wRxrTIAIQe-n7B5m4A.png" /></figure><ul><li>After a user successfully logs in using Amazon Cognito, they can be redirected back to our application using Add a return URL field.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*CP3pif1ic6f4RU-QW-oVyA.png" /></figure><ul><li>Click <strong>Create user directory</strong>.</li></ul><p>4. Click User management &gt; Users and Click Create Users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*sN6dtvWaYgiKmRWhVD7FZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*rmcfjvD6jgs_B_35WOp0yQ.png" /></figure><p>5. Now, Click on App clients &gt; Select Client name and Select View login page.</p><p>6. Verify the <strong>email</strong> and get redirected with an <strong>authorization code</strong>.</p><p>7. Copy this code and we will use this code in Postman to generate access token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*U_Ef-RxupXEoC2xkXfV18A.png" /></figure><p><strong>Note:</strong> The token may expire after some times . So, you can again login to generate the code again.</p><h3>Step 4: Configure API Gateway Authorizer</h3><ol><li>Return to <strong>API Gateway</strong>.</li><li>Open the <strong>Authorizers</strong> section and click <strong>Create an authorizer</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*-U7_-cT-b_mOcwG5eUDf_Q.png" /></figure><p>3. Provide:</p><ul><li><strong>Name</strong>: CognitoAuth</li><li><strong>Type</strong>: Cognito</li><li><strong>User Pool</strong>: Select the Cognito User Pool created earlier.</li><li><strong>Token Source</strong>: Enter Authorization.</li></ul><p>4. Click <strong>Create authorizer</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*vud_EwG9y8YcobHHnOkb8A.png" /></figure><h3>Attach the Authorizer to the API Method</h3><ol><li>Go to <strong>Resources</strong> and select the <strong>GET</strong> method.</li><li>Click <strong>Method Request</strong> → <strong>Edit</strong>.</li><li>Under <strong>Authorization</strong>, select CognitoAuth.</li><li>Save changes and <strong>Redeploy API</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*pOWOq0akLvw-hq6_4IiVIw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*5EA8GzVsPIMSMXEYcnkQRA.png" /></figure><p>Testing the new API URL:</p><ul><li>Copy the Invoke URl of the new stage and paste it into the browser.</li><li>You’ll receive a forbidden message. This is because we haven’t provided a token in the Authorization header.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*9_dbr8bPMPiTe7_rjBkd3A.png" /></figure><h3>Step 5: Obtain an Access Token</h3><ol><li>In <strong>Cognito</strong>, go to <strong>Branding</strong> → <strong>Domain</strong>.</li><li>Copy the <strong>Cognito domain URL</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*jEyvOstwrV49KEZ471e3dg.png" /></figure><p>3. Use <strong>Postman</strong> to exchange the <strong>authorization code</strong> for an <strong>access token</strong>:</p><ul><li><strong>Method</strong>: POST</li><li><strong>URL</strong>: <a href="https://your-cognito-domain/oauth2/token">https://your-cognito-domain/oauth2/token</a></li><li><strong>Headers</strong>:</li></ul><pre>Content-Type: application/x-www-form-urlencoded</pre><ul><li><strong>Body (URL-encoded)</strong>:</li></ul><pre>grant_type: authorization_code<br>client_id: &lt;client_id_in_App_clients&gt;<br>code: &lt;authorization_code&gt;<br>redirect_uri: http://localhost<br>client_secret: &lt;client_secret_in_App_clients&gt;</pre><p>Note: Client ID and Client secret can be found in App clients sub menu under Applications section.</p><p>Below is the required postman request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*lwdzndzruN-6gm9tF8Nvog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*QTZADFLbBHNZdGQudRMWbg.png" /></figure><p>If successful, Cognito returns an <strong>access token.</strong></p><h3>Step 6: Invoke the API with the Access Token</h3><ol><li>In <strong>Postman</strong>, create a <strong>new request</strong>:</li></ol><ul><li><strong>Method</strong>: GET</li><li><strong>URL</strong>: Paste the <strong>API Gateway Invoke URL</strong>.</li><li><strong>Authorization Tab</strong>:</li><li>Select **<strong>Bearer Token</strong> and add your <strong>Access Token.</strong></li><li>Click <strong>Send</strong></li></ul><p>2. The API should return a response from the Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*aaRPRKEwt1G8Y9XKuA-Q8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*qhsx3iv-1j_GnFkie52yLA.png" /></figure><h4>Conclusion</h4><p>By integrating <strong>Amazon Cognito with API Gateway</strong>, you’ve added secure, scalable authentication to your serverless API. This setup protects your backend from unauthorized access and provides a seamless login experience for users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f454167262bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a DynamoDB Table with LSI & GSI, Insert Data, Query Efficiently, and Calculate WCU/RCU]]></title>
            <link>https://medium.com/@saugatrijal99/create-a-dynamodb-table-with-lsi-gsi-insert-data-query-efficiently-and-calculate-wcu-rcu-94f12071d0fe?source=rss-f75595ab59b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/94f12071d0fe</guid>
            <category><![CDATA[dynamodb]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Saugat Rijal]]></dc:creator>
            <pubDate>Fri, 30 May 2025 08:24:04 GMT</pubDate>
            <atom:updated>2025-05-30T08:26:57.483Z</atom:updated>
            <content:encoded><![CDATA[<h3>1: Create a DynamoDB Table with LSI &amp; GSI</h3><ol><li><strong>Sign in to AWS Console</strong></li></ol><ul><li>Go to<a href="https://console.aws.amazon.com/dynamodb"> <strong>AWS DynamoDB Console</strong></a>.</li><li>Click on <strong>Create Table</strong>.</li></ul><h4><strong>2. Configure the Table:</strong></h4><ul><li><strong>Table name:</strong> Users</li><li><strong>Primary Key:</strong></li><li><strong>Partition Key:</strong> UserID (Type: String)</li><li><strong>Sort Key:</strong> SignupDate (Type: String)</li><li><strong>Capacity Mode:</strong> On-demand</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*3-JF3vOSEKUCxsrLOVGUvg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*HVreeBXkjDW-nsuy3Gwhug.png" /></figure><p><strong>Step-2: Add a Local Secondary Index (LSI):</strong></p><ul><li>Click on <strong>Add Index</strong>.</li><li><strong>Index name:</strong> AgeIndex</li><li><strong>Sort Key:</strong> Age (Type: Number)</li><li><strong>Projection Type:</strong> All attributes</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*wKOZ3ng3odvqpbUm1WCmIA.png" /></figure><p><strong>Step-3: Add a Global Secondary Index (GSI):</strong></p><ul><li>Click on <strong>Add Index</strong>.</li><li><strong>Index name:</strong> EmailIndex</li><li><strong>Partition Key:</strong> Email (Type: String)</li><li><strong>Projection Type:</strong> All attributes</li><li>Click <strong>Create index</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*r0-6310ZwpYW2dVCnX1S1g.png" /></figure><p>5. Click <strong>Create Table</strong> and wait for the table to be active.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*oW_kiWe2MtEUOzsiKZ4QUA.png" /></figure><p><strong>Step-4: Insert Dummy Data into the Table</strong></p><ol><li>Go to the <strong>Tables</strong> section in the AWS Console.</li><li>Click on the <strong>saugat </strong>table.</li><li>Go to the<strong> Explore table items</strong> tab.</li><li>Click <strong>Create Item</strong> and add data manually:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*vBf1vHL7dc85rgG2yGnwtA.png" /></figure><p>Click <strong>Explore table items </strong>and Click on<strong> Create item.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*de1whtoI8uKZP4q-E1GDrQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*0sqBju7EnYF7m6dvqLLD9g.png" /></figure><p>Click on <strong>JSON view </strong>and insert the code:</p><pre>{<br>  &quot;sau1&quot;: {&quot;S&quot;: &quot;U001&quot;},<br>  &quot;Name&quot;: {&quot;S&quot;: &quot;2024-03-01&quot;},<br>  &quot;Age&quot;: {&quot;N&quot;: &quot;25&quot;},<br>  &quot;Email&quot;: {&quot;S&quot;: &quot;user1@example.com&quot;}<br>}<br>{<br>  &quot;sau1&quot;: { &quot;S&quot;: &quot;U002&quot; },<br>  &quot;Name&quot;: { &quot;S&quot;: &quot;Alice Johnson&quot; },<br>  &quot;Email&quot;: { &quot;S&quot;: &quot;alice@example.com&quot; },<br>  &quot;SignupDate&quot;: { &quot;S&quot;: &quot;2024-04-10&quot; },<br>  &quot;Age&quot;: { &quot;N&quot;: &quot;30&quot; }<br>}</pre><p><strong>Step-5: Query Using LSI (Local Secondary Index)</strong></p><ol><li>Open the <strong>saugat</strong> table in AWS Console.</li><li>Click on the <strong>Explorer Items</strong> tab.</li><li>Click on <strong>Query</strong>.</li><li>Select <strong>AgeIndex</strong> from the “Query on index” dropdown.</li><li>Enter filter conditions:</li></ol><ul><li><strong>Partition Key:</strong> UserID = “U001”</li></ul><p>Click <strong>Run</strong> to fetch results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*SRNumCQ0dZVyXWDGus6JJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*yv8P9U-8_-F-eypapClqkw.png" /></figure><p><strong>How to Check WCU &amp; RCU Usage in On-Demand Mode?</strong></p><p>Since you’re using <strong>On-Demand Mode</strong>, DynamoDB <strong>automatically scales</strong> WCU and RCU based on your workload. You <strong>don’t need to manually set</strong> WCU and RCU, but you can still <strong>observe</strong> your actual consumption in the AWS Console.</p><p>1️⃣ <strong>Go to AWS DynamoDB Console</strong> →<a href="https://console.aws.amazon.com/dynamodb"> DynamoDB Tables<br></a>2️⃣ Click on your <strong>Users</strong> table.<br>3️⃣ Click the <strong>Monitoring</strong> tab.<br>4️⃣ Look for these key CloudWatch metrics:</p><ul><li><strong>Consumed Read Capacity Units</strong> (RCU usage over time)</li><li><strong>Consumed Write Capacity Units</strong> (WCU usage over time)</li><li><strong>Throttled Requests</strong> (Indicates if AWS is limiting your requests)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*A1jVz-eapNA4p3ooiPysAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*3pO-Jm7mGYNmUNRh6D4gvQ.png" /></figure><p><strong>How to Interpret the Metrics?</strong></p><ul><li><strong>If Consumed RCU/WCU is low</strong>, your workload is light, and AWS is allocating only what you need.</li><li><strong>If Throttled Requests are appearing</strong>, you might be hitting a burst limit and need to optimize queries.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94f12071d0fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build and Deploy Your Projects Using Jenkins, Maven, SonarQube, and Nexus: The Ultimate Guide]]></title>
            <link>https://medium.com/@saugatrijal99/build-and-deploy-your-projects-using-jenkins-maven-sonarqube-and-nexus-the-ultimate-guide-c256f7582d57?source=rss-f75595ab59b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c256f7582d57</guid>
            <dc:creator><![CDATA[Saugat Rijal]]></dc:creator>
            <pubDate>Tue, 06 May 2025 17:39:31 GMT</pubDate>
            <atom:updated>2025-05-11T01:57:37.849Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>Today, software teams need to build and deliver apps quickly while keeping quality high. Developers often deal with challenges like making sure the code is good, managing tools and libraries, automating the build process, and safely storing the final product. This is where DevOps and CI/CD pipelines help a lot. In this blog, I’ll show you how to set up a basic DevOps setup using three Amazon EC2 instances. Each instance will run a different tool used in the CI/CD process:</p><ul><li><strong>Jenkins </strong>for automating the steps,</li><li><strong>SonarQube </strong>for checking code quality,</li><li><strong>Nexus </strong>for storing the built files (artifacts).</li></ul><p>By running each tool on its own EC2 instance, we make the system more reliable, scalable, and easier to manage.</p><h3>Step 1: Launch Three EC2 Instances</h3><p>Launch three EC2 instances, each using a <strong>t2.medium</strong> instance type (or any other type that suits your project). The <strong>t2.medium</strong> provides a good balance of computing power and memory, which makes it a suitable option for running tools such as Jenkins, SonarQube, and Nexus individually.</p><p><strong>1. Create Jenkins Instance</strong>:</p><ul><li>Launch an EC2 instance and assign a public IP for accessibility.</li><li>Select the <strong>Amazon Linux 2</strong> or <strong>Ubuntu</strong> AMI.</li><li>Use the t2.medium instance type.</li><li>Open port 8080 (Jenkins default port) in the security group to allow access to Jenkins.</li><li>Assign an SSH key pair for secure login.</li></ul><p><strong>2. Create SonarQube Instance</strong>:</p><ul><li>Follow the same steps to create another EC2 instance for SonarQube.</li><li>Open port 9000 (SonarQube default port) in the security group to allow access to SonarQube.</li></ul><p><strong>3. Create Nexus Instance</strong>:</p><ul><li>Create a third EC2 instance for Nexus.</li><li>Open port 8081 (Nexus default port) in the security group to allow access to Nexus.</li></ul><p>4. Create one security which includes all the necessary port for this project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*XPMFqKAIn4fY7GNYaQnrrg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*qhCy3_blWgy999bk7rkheQ.png" /></figure><h3>Step 2: Install Jenkins on the Jenkins Instance</h3><ol><li>SSH into the Jenkins instance using the private key.</li><li>Install Jenkins:</li></ol><pre>sudo apt update <br>sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \<br>https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key<br>echo &quot;deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]&quot; \<br>https://pkg.jenkins.io/debian-stable binary/ | sudo tee \<br> /etc/apt/sources.list.d/jenkins.list &gt; /dev/null<br>sudo apt-get update<br>sudo apt-get install Jenkins<br>sudo systemctl start jenkins<br>sudo systemctl enable Jenkins</pre><p>3.To Start Jenkins make sure the port 8080 is open</p><pre>http://&lt;Public-IP&gt;:8080</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*d6NkNWCwj_cQa3ob4EX5yQ.png" /></figure><p>4. Find the Jenkins Password <br>Jenkins generates an initial password when you first launch it. To retrieve it, run the following command:</p><pre>sudo cat /var/lib/jenkins/secrets/initialAdminPassword</pre><h3>Step 3: Install SonarQube on the SonarQube Instance</h3><ol><li>Install Docker</li></ol><pre>sudo apt update<br>sudo apt install -y docker.io<br>sudo systemctl start docker<br>sudo systemctl enable docker<br>sudo su<br># To Run SonarQube Container<br>docker run -d  -p 9000:9000 sonarqube:lts-community<br>   d means deteched mode / running in background<br>  -p means port first host port and second container port</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*F2tLDOT-K7X5rt9CywXr2Q.png" /></figure><p>To see status sonarqube running or not</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*jDa2hcnROhMUWxWZQxwMdQ.png" /></figure><p>2. Access SonarQube in Browser</p><pre>http://&lt;SonarQube-Instance-IP&gt;:9000</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*OMtXekx-XYNGkmZ6tbxw7A.png" /></figure><p>Get the default password</p><pre>docker exec -it sonarqube bash<br>cat /opt/sonarqube/data/es7/nodes/0/_state/global-*.st | grep -a &#39;admin&#39;</pre><h3>Step 4: Install Nexus on the Nexus Instance</h3><pre>sudo apt update<br>sudo su<br>apt install docker.io<br>sudo apt install openjdk-11-jdk<br>wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz<br>tar -zxvf latest-unix.tar.gz<br>sudo mv nexus-3.* /opt/nexus</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*qf56RCOF7HpXYMwN5QuwXQ.png" /></figure><p>To check docker running or not</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*02-eMNU2oSQ8QyGuQEssEw.png" /></figure><p>To go inside it</p><pre>docker exec -it ea0c57be737e /bin/bash<br></pre><p>Access the Nexus on port 8081</p><pre>http://&lt;Nexus-Instance-Public-IP&gt;:8081&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*cy0EIIBIN9hZYXl-DC5oxw.png" /></figure><p>For login password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*QnkhSMoHaDVIL_erfV8FgQ.png" /></figure><h3>Step 5: Configure Jenkins to Integrate with SonarQube and Nexus</h3><p>Install docker on jenkins</p><pre>sudo apt install docker.io<br>sudo chmod 666 /var/run/docker.sock</pre><p>Install plugins</p><ul><li>Go to Jenkins &gt; Manage Jenkins &gt; Manage Plugins.</li><li>Install the following plugins:</li><li>SonarQube Scanner Plugin</li><li>Maven Integration Plugin</li><li>Nexus Artifact Uploader</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*xNoyilObzNvTaJchppxeFg.png" /></figure><p><strong>Configure Global Tools</strong>:</p><ul><li>Go to Jenkins &gt; Manage Jenkins &gt; Global Tool Configuration.</li><li>Add SonarQube server details and Maven installation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*HqMTMxwWz45lFhmQERjPEQ.png" /></figure><p>Add another jdk11</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*hq7D0_g76DjYrsJyqYj1cw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*hc5XpLYV7wCzRpZK-tMoRg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*jQVubjPf5_eC-cKHbv_ojw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*0EypIjYvDcRD4J6bTNxE0g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*u-2djxf4tZxzdc6hHD5Kuw.png" /></figure><p>And apply this tools</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*wJDzef0lEKfOu4uHIKhEWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*N4OZsOs4Nqf0ymhmoWZSbA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*0xGlvQohxOfRb-Kx4yXaZg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*8EbGUwk6MaMyoeDJBzoe4A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*UTCuXv78yJZD7Y0ITFN-cw.png" /></figure><p>Install plugins config File Provider</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ZLYHdYKiFRMCzwMwGIS61Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*nMlwtUNaVAqxatVQf2bXKw.png" /></figure><p>2. <strong>Create a Jenkins Job</strong>:</p><ul><li>Create a Freestyle project or a Pipeline in Jenkins.</li><li>Configure the job to trigger SonarQube analysis and upload build artifacts to Nexus after successful builds.</li></ul><h4>GitHub</h4><p><a href="https://github.com/saugatrijal/Ekart.git">GitHub - saugatrijal/Ekart</a></p><p>For the Nexus Artifact we had configure it on our github pom.xml file .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*dVlcNhr2EwBxJyVJgo4Q7Q.png" /></figure><h3>Step 6: Create Jenkins Pipeline to Automate CI/CD Workflow</h3><p>Once Jenkins is installed and integrated with Maven, JDK, SonarQube, and GitHub, you can create a pipeline job to automate the build and analysis process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*SYb0jVmUxl07T_pPTFdtxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*J9_48R-TpQQQBlbrT5ihOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*tbBC0qNfN262TLfhDSdVnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*mWJlE0xB0s_o_Y12TKKAFg.png" /></figure><pre>pipeline {<br>    agent any<br>    <br>    tools {<br>        maven &#39;maven3&#39;<br>        jdk &#39;jdk17&#39;<br>    }<br>    <br>    environment{<br>        SCANNER_HOME= tool &#39;sonar-scanner&#39;<br>    }<br><br>    stages {<br>        stage(&#39;Git Checkout&#39;) {<br>            steps {<br>                git branch: &#39;main&#39;, url: &#39;https://github.com/saugatrijal/Ekart.git&#39;<br>            }<br>        }<br>        <br>        stage(&#39;Compile&#39;) {<br>            steps {<br>                sh &quot;mvn compile&quot;<br>            }<br>        }<br>        <br>        stage(&#39;Unit Tests&#39;) {<br>            steps {<br>                sh &quot;mvn test -DskipTests=true&quot;<br>            }<br>        }<br>        <br>        stage(&#39;SonarQube Analysis&#39;) {<br>            steps {<br>                withSonarQubeEnv(&#39;sonar&#39;) {<br>                    sh &#39;&#39;&#39; $SCANNER_HOME/bin/sonar-scaner -Dsonar.projectKey=EKART -Dsonar.projectName=EKART \<br>                    -Dsonar.java.binaries=. &#39;&#39;&#39;<br>                <br>            }<br>        }<br>        <br>        stage(&#39;Hello&#39;) {<br>            steps {<br>                echo &#39;Hello World&#39;<br>            }<br>        }<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*DB-Gcg9vP0iX_IXsk5_vlg.png" /></figure><h3>Explanation of the Pipeline Stages:</h3><ol><li><strong>Git Checkout</strong>: Clones the project from GitHub using the main branch.</li></ol><p><strong>2. Compile</strong>: Runs mvn compile to compile the Java source code.</p><p><strong>3. Unit Test</strong>: Executes unit tests using mvn test. <em>(If you want to skip tests during CI, use </em><em>-DskipTests=true, but that’s not recommended for actual testing.)</em></p><p><strong>4. SonarQube Analysis</strong>:</p><ul><li>Uses sonar-scanner to analyze the code quality.</li><li>Relies on the withSonarQubeEnv(&#39;sonar&#39;) block which injects environment variables like SONAR_HOST_URL and credentials.</li><li>Sends project metadata like projectKey, projectName, and compiled binary path.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*n9zB2jkKwtNXft-WLzOU8g.png" /><figcaption>Pipeline Build Successfully</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*cvJWegzLgJr_XkoXJNmPJw.png" /><figcaption>Nexus Artifact</figcaption></figure><p>As you can see our pipeline run successfully and our SonarQube is Showing the analysis of our project.</p><h3>Conclusion</h3><p>In this guide, we’ve walked through the end-to-end process of building and deploying applications using <strong>Jenkins</strong>, <strong>Maven</strong>, <strong>SonarQube</strong>, and <strong>Nexus</strong>. By integrating these powerful tools, we achieve a robust CI/CD pipeline that ensures code quality, security, and efficient artifact management. Jenkins orchestrates the entire process, Maven handles dependencies and builds, SonarQube maintains code integrity, and Nexus serves as a centralized repository for smooth deployments. You can further enhance this setup by integrating additional tools or expanding the pipeline.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c256f7582d57" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated Image Compression with AWS Lambda, EC2, and S3]]></title>
            <link>https://medium.com/@saugatrijal99/automated-image-compression-with-aws-lambda-ec2-and-s3-cf98b12f8cdb?source=rss-f75595ab59b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf98b12f8cdb</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[compress-image-size]]></category>
            <category><![CDATA[s3]]></category>
            <dc:creator><![CDATA[Saugat Rijal]]></dc:creator>
            <pubDate>Fri, 02 May 2025 05:33:13 GMT</pubDate>
            <atom:updated>2025-05-02T05:33:13.667Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine you’re running a web platform where users frequently upload high-resolution images (like a photography site, e-commerce app, or social network). Over time, this increases your S3 storage costs and slows down website load times. To address this, you decide to <strong>automatically compress images</strong> right after they’re uploaded to an S3 bucket. This compression should happen without any manual effort, using <strong>AWS Lambda</strong>, an <strong>EC2 instance</strong>, and <strong>Amazon S3</strong>.</p><h4><strong>Detailed Step-by-Step Guide</strong></h4><h4>1. Creating an S3 Bucket</h4><p>Go to the <strong>AWS Management Console</strong>. Navigate to <strong>S3</strong> → <strong>Create bucket</strong>. Provide a <strong>unique bucket name</strong>. Select a <strong>region</strong> (same as your EC2 instance for faster performance). Enable <strong>public access settings</strong> as needed (usually <strong>block public access</strong> for security). Click <strong>Create bucket</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*d7ALEDM58pW2wSSiWpAbzA.png" /></figure><h4>2. Creating an EC2 Instance</h4><p>Navigate to <strong>EC2</strong> → <strong>Instances</strong> → <strong>Launch Instance</strong>. Choose <strong>Amazon Linux 2 </strong>as your AMI. Select an <strong>instance type</strong>. Add <strong>storage</strong> as required. In <strong>Security Group</strong> settings: Allow <strong>SSH</strong> (port 22) for remote access. Optionally, add <strong>HTTP</strong> (port 80) if you want to test web-based functionality. Launch the instance and download the <strong>.pem key</strong> for SSH access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*bG_Rp2Osv4f8z-XluaohVQ.png" /></figure><h4>3. Creating and Attaching an IAM Role for EC2</h4><p>Go to <strong>IAM</strong> → <strong>Roles</strong> → Click <strong>Create Role</strong>. Under <strong>Trusted entity type</strong>, select <strong>AWS service</strong>. Choose <strong>EC2</strong>. Click <strong>Next</strong> → Attach the <strong>AmazonS3FullAccess</strong> policy. Click <strong>Next</strong> → Name the role. Click <strong>Create Role</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*JnuLmHoE_mkm7-qBFyFA7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*69UNucAof-xzM3eJ7M3oKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*KuFvLFh8IAm7E_-eRj9VTw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*pCg_J-Mn7-hxQABK43T1Zg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*p-_zrydjAvlEY53T0_l02w.png" /></figure><h4><strong>4. Attach this role to your EC2 instance:</strong></h4><p>Go to <strong>EC2</strong> → Select your instance → Click <strong>Actions</strong> → <strong>Security</strong> → <strong>Modify IAM Role</strong>. Select the role you just created and click <strong>Update IAM Role</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*PxK7cmi8CkpjfFosLdLk4g.png" /></figure><h4><strong>5. Creating an IAM Role for AWS Lambda</strong></h4><p>Go to <strong>IAM</strong> → <strong>Roles</strong> → Click <strong>Create Role</strong>. Select <strong>AWS service</strong> → Choose <strong>Lambda</strong>. Click <strong>Next</strong> → Attach these policies: <strong>AmazonS3FullAccess, AmazonEC2FullAccess. </strong>Click <strong>Next</strong>, name the role (e.g., Lambda-EC2-Trigger), and click <strong>Create Role</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*vUH7uV1p69nmOLNh3loH9g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*L4exvF1MGsTidcZnT0ZZnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*0s40LlWeo4ia3fX0ztfPPg.png" /></figure><h4>6. Creating a Lambda Function</h4><p>Go to <strong>AWS Lambda</strong> → Click <strong>Create Function</strong>. Select <strong>Author from scratch</strong>. Enter <strong>Function name</strong>. Set <strong>Runtime</strong> to <strong>Python 3.9</strong>. Under <strong>Execution Role</strong>, choose <strong>Use an existing role</strong> → Select Lambda-EC2-Trigger. Click <strong>Create Function</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*90jQRRTt_WZK6FVaEtZICg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*otaPNTe4B7Fgr46hZMcQKg.png" /></figure><p>After create lambda function. Inside the code editor, replace the default code with the code below and deploy it.</p><pre>import boto3<br>ec2 = boto3.client(&#39;ec2&#39;)<br>INSTANCE_ID = &#39;your-ec2-instance-id&#39;<br>def lambda_handler(event, context):<br>    ec2.start_instances(InstanceIds=[INSTANCE_ID])<br>    print(f&quot;EC2 instance {INSTANCE_ID} started successfully.&quot;)</pre><p>Deploy and test the code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*KEYXzeq8bxpM7kMAJgI2qQ.png" /></figure><h4>7. Adding a S3 event to Trigger Lambda</h4><p>Go to your <strong>S3 bucket</strong>. Open the <strong>Properties</strong> tab. Scroll down to <strong>Event Notifications</strong> and click <strong>Create event notification</strong>. Name the event. Under <strong>Event types</strong>, select <strong>PUT</strong> (for new image uploads). Under <strong>Destination</strong>, select <strong>Lambda function</strong>. Choose your Lambda function. Click <strong>Save changes</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*Wj3a7yoiRhG8LH8oAoLZSg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*xq7WiGwqcPxUXqQCVR1dDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*tuTIZn1SoPSCteAwcGNSuA.png" /></figure><h4>8. Connecting EC2 Instance via SSH</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*mLHPnt4Rsfw4L4S2vaO_oA.png" /></figure><p>Install all required dependencies</p><pre>sudo yum update -y<br>sudo dnf install -y python3.9 python3-pip<br>pip3 install pillow boto3<br>python3 --version<br>pip3 --version</pre><h4>9. Creating a Compression Script on EC2</h4><pre>import boto3 <br>from PIL import Image <br>import io <br> <br># AWS credentials and resources <br>s3 = boto3.client(&#39;s3&#39;) <br> <br># Source and destination bucket details <br>SOURCE_BUCKET = &#39;bucketname&#39; <br>DESTINATION_BUCKET = &#39;bucketname&#39; <br> <br>def compress_image(key): <br>    # Download the image from S3 <br>    response = s3.get_object(Bucket=SOURCE_BUCKET, Key=key) <br>    image_data = response[&#39;Body&#39;].read() <br> <br>    # Compress the image <br>    image = Image.open(io.BytesIO(image_data)) <br>    compressed_image = io.BytesIO() <br>    image.save(compressed_image, format=&#39;JPEG&#39;, quality=30)  # Adjust quality as needed <br> <br>    # Upload compressed image back to S3 <br>    s3.put_object(Bucket=DESTINATION_BUCKET, Key=f&#39;compressed/{key}&#39;, Body=compressed_image.getvalue()) <br> <br>    print(f&quot;Image &#39;{key}&#39; compressed and uploaded successfully.&quot;) <br> <br>if __name__ == &quot;__main__&quot;: <br>    # Manually specify the image key (adjust this if needed) <br>    image_key = &#39;your image path/key&#39;  # Example path <br>    compress_image(image_key)<br></pre><p>To save the file Press Ctrl+O and Enter.<br> To exit the file Press Ctrl+X.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*eN1VS9FE3QjMvke4hFOL-A.png" /></figure><p><strong>Now, make your Python script executable with:</strong></p><pre>chmod +x file.py<br>Now, run the python code with :<br>python3 file.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*NJKKP6UdezubwI-ShEBNbA.png" /></figure><h4>10. Testing the setup</h4><p>Here , the lambda will trigger your EC2 instance and it will download the image you uploaded earlier in S3 bucket to EC2 and EC2 instance will compress the image and save it as/compressed/. in your S3 bucket. I uploaded the file pokhari.jpg and file size 161 KB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ykVD7qBftwBED4aTl4kmuQ.png" /></figure><p>Original file size 161.2 KB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*YW9O0bnP7H50ROKigl_x1g.png" /></figure><h3>Conclusion</h3><p>Automating image compression with AWS Lambda, EC2, and S3 is a smart, scalable, and cost-efficient solution for modern cloud applications. It improves your application’s speed and performance while reducing storage and bandwidth costs. By leveraging AWS’s event-driven architecture, you ensure that every image uploaded gets optimized without any manual effort.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf98b12f8cdb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ How to Host a WordPress Website on Amazon EC2 (Step-by-Step for Beginners)]]></title>
            <link>https://medium.com/@saugatrijal99/how-to-host-a-wordpress-website-on-amazon-ec2-step-by-step-for-beginners-d01bc676b45a?source=rss-f75595ab59b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d01bc676b45a</guid>
            <category><![CDATA[dynamic-website-design]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Saugat Rijal]]></dc:creator>
            <pubDate>Thu, 24 Apr 2025 16:27:22 GMT</pubDate>
            <atom:updated>2025-04-24T16:27:22.426Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*EOTOROasjJZnML8jM4okmQ.png" /></figure><h3>Objective</h3><p>The objective of this blog is to provide a <strong>simple, step-by-step guide</strong> for beginners who want to host a WordPress website using <strong>Amazon EC2</strong>. Whether you’re learning cloud computing or launching your first blog, this tutorial will help you deploy a fully functional WordPress site with minimal hassle.</p><p><strong>Step 1: Launch an Amazon EC2 Instance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*U0rN8ULveOltEPeWjbqZhA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*AKEmzBb-TTR1f8MhfXxbAw.png" /></figure><ul><li>Click “Connect” to view connection instructions.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*eOMgtWW_yKOK5O_EqkXJeA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*wgynmAe81kNkbhoBdR09DA.png" /></figure><p><strong>Step 2: Update Your System</strong></p><pre>sudo dnf update -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*khZnoKrhHRdqr_mu-NFe7Q.png" /></figure><p><strong>Step 3: Install Apache, PHP, and MariaDB</strong></p><pre>sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Vy1sywRyU4dp-JVBRoCG-A.png" /></figure><pre>sudo dnf install -y mariadb105-server</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*zfvubGJT--kyQqjbZRqyYQ.png" /></figure><p>To check the MariaDB version:</p><pre>dnf info mariadb105</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Wn4iIWbIP8YMAMFtu0_gvw.png" /></figure><p><strong>Step 4: Start and Configure Apache</strong></p><p>Start the Apache server and enable it to launch on boot:</p><pre>sudo systemctl start httpd &amp;&amp; sudo systemctl enable httpd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*KbH-RllLpMzDS2FWM-LmFw.png" /></figure><p>Verify if Apache is enabled:</p><pre>sudo systemctl is-enabled httpd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ApBdLo6spiqKF0kVz89HLg.png" /></figure><p>Add your user (ec2-user) to the Apache group:</p><pre>sudo usermod -a -G apache ec2-user</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ilt7OZLC_eIJAYaRmvq2sA.png" /></figure><p>Then, log out and log back in again to refresh your groups:</p><pre>exit<br>groups</pre><p><strong>Step 5: Configure Permissions</strong></p><p>Adjust the permissions for your web directory:</p><pre>sudo chown -R ec2-user:apache /var/www<br>sudo chmod 2775 /var/www &amp;&amp; find /var/www -type d -exec sudo chmod 2775 {} \;<br>  find /var/www -type f -exec sudo chmod 0664 {} \;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*3Ap475pBJIJ_4XsypAJlPA.png" /></figure><p>Test PHP installation by creating a PHP file:</p><pre>echo &quot;&lt;?php phpinfo(); ?&gt;&quot; &gt; /var/www/html/phpinfo.php</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*jkGD5YvbTZVbkAFH20MIUA.png" /></figure><p>After verifying it works by accessing <a href="http://your-ec2-public-dns/phpinfo.php,">http://your-ec2-public-dns/phpinfo.php,</a> remove the file:</p><pre>rm /var/www/html/phpinfo.php</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*0Z1gqZ6f8IgXZiJg2nB3_Q.png" /></figure><p><strong>Step 6: Install and Start MariaDB</strong></p><p>Start MariaDB and secure your installation:</p><pre>sudo systemctl start mariadb<br>sudo mysql_secure_installation</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*cL7gflW4mAUaaqbjqpcELg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*wlc5R-PMbyH4syT6PbH2pw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*1R_zOeBB_37OIDqV1U_Wew.png" /></figure><p><strong>Step 7: Install WordPress</strong></p><p>Download the latest WordPress package and extract it:</p><pre>wget https://wordpress.org/latest.tar.gz</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Lx0_3uZj4Wlho0tUHBVJqA.png" /></figure><pre>tar -xzf latest.tar.gz</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*W1WD1CQTjofovfKWpYvTMQ.png" /></figure><p>Start both Apache and MariaDB if not already running:</p><pre>sudo systemctl start mariadb httpd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*XTPGok9xFAbNZYTm6IE4SA.png" /></figure><p><strong>Step 8: Create a Database for WordPress</strong></p><p>Access the MySQL shell as root:</p><pre>mysql -u root -p</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*WQXH8VHgNu-zc9E3bhUObg.png" /></figure><p>Then, create a new database and user for WordPress:</p><p>CREATE USER ‘wordpress-user’@’localhost’ IDENTIFIED BY ‘your_strong_password’;</p><p>Create your database. Give your database a descriptive, meaningful name, such as wordpress-db.</p><pre>CREATE DATABASE `wordpress-db`;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*7-iui73rSw9At69lEriy4A.png" /></figure><pre>Grant full privileges for your database to the WordPress user that you created earlier.<br># GRANT ALL PRIVILEGES ON `wordpress-db`.* TO &quot;wordpress-user&quot;@&quot;localhost&quot;;<br>Flush the database privileges to pick up all of your changes.<br># FLUSH PRIVILEGES;<br>Exit the mysql client.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*G91WCY1mKRgCovBqwi4irQ.png" /></figure><p><strong>Step 9: Configure WordPress</strong></p><p>Copy the WordPress sample configuration file and edit it with your database details:</p><pre>cp wordpress/wp-config-sample.php wordpress/wp-config.php<br>   nano wordpress/wp-config.php<br># Update the database name, user, and password in the wp-config.php file.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*Em_c5xofQDqCQ7SnJ1LDtA.png" /></figure><p><strong>Step 10: Deploy WordPress</strong></p><p>Copy the WordPress files to your web directory:</p><pre>cp -r wordpress/* /var/www/html/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*_PxjdR2Wt9fssAjKIxewRg.png" /></figure><p>If you wish to install WordPress in a subdirectory, such as /blog, create the directory and copy the files:</p><pre> mkdir /var/www/html/blog<br> cp -r wordpress/* /var/www/html/blog/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*wRpZM_IixjblCaschzll8A.png" /></figure><p><strong>Step 11: Configure Apache</strong></p><p>Before finalizing the installation, you may need to adjust the Apache configuration:</p><pre> sudo nano /etc/httpd/conf/httpd.conf</pre><p>Find the section that starts with &lt;Directory “/var/www/html”&gt;.</p><p>Change the AllowOverride None line in the above section to read AllowOverride All.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*3uGYqAsCYG_M0l0qjV38-w.png" /></figure><p><strong>Step 12: Finalize the Installation</strong></p><p>Restart Apache to apply the changes:</p><pre>sudo systemctl restart httpd</pre><p>Now, complete your WordPress installation by navigating to <a href="http://your-ec2-public-dns/">http://your-ec2-public-dns/</a> or <a href="http://your-ec2-public-dns/blog">http://your-ec2-public-dns/blog</a> if you installed it in a subdirectory. Follow the on-screen instructions to finish the setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*OwKdILz3uMULql7SWF7C1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*_vWaVnjWyquuH55bkKdyKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*UI4kwfa-qFhbcC0kXJZ6wA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*jCpjGeGhUboE552-RArMDA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*smNCGDe847DcpoyIUJLagA.png" /></figure><p>Congratulations! You have successfully installed WordPress on your Amazon EC2 instance using the 2023 Amazon Linux AMI.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d01bc676b45a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Automate AWS Resources Using CloudFormation — Step-by-Step Guide for Beginners]]></title>
            <link>https://medium.com/@saugatrijal99/automate-aws-resources-using-cloudformation-step-by-step-guide-for-beginners-383e8b702914?source=rss-f75595ab59b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/383e8b702914</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[cloudformation]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Saugat Rijal]]></dc:creator>
            <pubDate>Sun, 20 Apr 2025 03:49:02 GMT</pubDate>
            <atom:updated>2025-04-20T03:49:02.505Z</atom:updated>
            <content:encoded><![CDATA[<h3>🚀 Automate AWS Resources Using CloudFormation — Step-by-Step Guide for Beginners</h3><p><strong>Introduction</strong></p><p><strong>AWS CloudFormation</strong></p><p><strong>AWS CloudFormation</strong> is an <strong>Infrastructure as Code (IaC)</strong> service provided by AWS that lets you <strong>define, provision, and manage AWS infrastructure</strong> using <strong>code</strong> (in YAML or JSON). Instead of clicking around in the AWS Console, you write a <strong>template</strong> that declares the resources you need, and CloudFormation takes care of <strong>creating and configuring</strong> those resources for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*qUSro42j9x0mJIkY8-e8bQ.png" /></figure><p><strong>Key component of CloudFormation</strong></p><ol><li>Template</li></ol><p>The <strong>template</strong> is the core of CloudFormation. It’s a text file written in <strong>YAML</strong> or <strong>JSON</strong> that defines the AWS resources you want to create and how they should be configured.</p><p>2. Stack</p><p>A <strong>stack</strong> is a group of AWS resources managed together. You create a stack by submitting a template to CloudFormation. Everything in the template is created and managed as a single unit.</p><p>3. Change Sets</p><p>A <strong>Change Set</strong> allows you to <strong>preview changes</strong> before actually applying them to a stack. This is very helpful for production environments.</p><p>4. StackSets</p><p><strong>StackSets</strong> allow you to create, update, or delete stacks <strong>across multiple AWS accounts and regions</strong> with a single operation. Useful for managing infrastructure at scale.</p><p><strong>Step-by-step guide</strong></p><p>Creating an S3 Bucket and Uploading the Template</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*NMPBuMLxHxIlJ-oeqKzt9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*cbQV-1H4SyC1psHJnp7uFA.png" /></figure><p>Create YAML/JSON file and upload in S3 bucket</p><pre>{<br>  &quot;AWSTemplateFormatVersion&quot;: &quot;2010-09-09&quot;,<br>  &quot;Description&quot;: &quot;CloudFormation template to create an EC2 instance and an S3 bucket&quot;,<br><br>  &quot;Resources&quot;: {<br>    &quot;MyS3Bucket&quot;: {<br>      &quot;Type&quot;: &quot;AWS::S3::Bucket&quot;,<br>      &quot;Properties&quot;: {<br>        &quot;BucketName&quot;: &quot;my-cloudformation-demo-bucket-12345&quot;<br>      }<br>    },<br><br>    &quot;MyEC2Instance&quot;: {<br>      &quot;Type&quot;: &quot;AWS::EC2::Instance&quot;,<br>      &quot;Properties&quot;: {<br>        &quot;InstanceType&quot;: &quot;t2.micro&quot;,<br>        &quot;ImageId&quot;: &quot;ami-0c55b159cbfafe1f0&quot;, <br>        &quot;Tags&quot;: [<br>          {<br>            &quot;Key&quot;: &quot;Name&quot;,<br>            &quot;Value&quot;: &quot;CFN-EC2&quot;<br>          }<br>        ]<br>      }<br>    }<br>  },<br><br>  &quot;Outputs&quot;: {<br>    &quot;BucketName&quot;: {<br>      &quot;Description&quot;: &quot;The name of the created S3 bucket&quot;,<br>      &quot;Value&quot;: {<br>        &quot;Ref&quot;: &quot;MyS3Bucket&quot;<br>      }<br>    },<br>    &quot;InstanceId&quot;: {<br>      &quot;Description&quot;: &quot;The ID of the EC2 instance&quot;,<br>      &quot;Value&quot;: {<br>        &quot;Ref&quot;: &quot;MyEC2Instance&quot;<br>      }<br>    }<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ubpzmob14X49HOjAxjn1kw.png" /></figure><p><strong>Creating a CloudFormation Stack</strong></p><p>Opening the <strong>AWS CloudFormation</strong> Console. Click on <strong>Create Stack</strong> and selecting “<strong>With Existing Template</strong>”. Under <strong>Template Source</strong>, selecting <strong>Amazon S3 URL</strong>. Providing the Amazon S3 URL of the uploading a YAML file. Assigning the<strong> stack name</strong>. And Clicking <strong>Next </strong>and left other configurations as default. Then finally Clicking on <strong>Create Stack.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*S3-HSWoWbhg6uzLcsdopQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*P_DUptUXJyucImP47HmRtw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*2LXWC-6P_9g93KIX_X4ukw.png" /></figure><p>Now, the CloudFormation stack is successfully created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*blk44-SVcNcxk-wrjCLWAQ.png" /></figure><p>The <strong>EC2 instance</strong> is launched automatically as per the template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*sp8mRPTblTsln9LDVmzRZg.png" /></figure><p>While delete the stack Our instance automatically terminated</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*XfAneYmuALjPwDiu1s6gow.png" /></figure><p>Ec2 also Terminated</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*rxgwtuTm8lQLVubKJ_H4mQ.png" /></figure><p><strong>Conclusion</strong></p><p>AWS CloudFormation with an S3-stored template automated EC2 and S3 deployment. Deleting the stack terminated the EC2 instance, demonstrating efficient infrastructure management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=383e8b702914" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ How to Trigger an AWS Lambda Function Using API Gateway
(Serverless API in Minutes — Beginner…]]></title>
            <link>https://medium.com/@saugatrijal99/how-to-trigger-an-aws-lambda-function-using-api-gateway-serverless-api-in-minutes-beginner-78478aa39b8a?source=rss-f75595ab59b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/78478aa39b8a</guid>
            <category><![CDATA[aws-lambda-trigger]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Saugat Rijal]]></dc:creator>
            <pubDate>Wed, 16 Apr 2025 09:22:57 GMT</pubDate>
            <atom:updated>2025-04-16T09:22:57.310Z</atom:updated>
            <content:encoded><![CDATA[<h3>🔹 <em>How to Trigger an AWS Lambda Function Using API Gateway</em><br><em>(Serverless API in Minutes — Beginner Friendly)</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ldz4m6zNAthqN0mHUlvoTw.png" /></figure><h3><strong>Intro</strong></h3><p><strong>AWS Lambda</strong> is a serverless service that runs your code in response to events — like HTTP requests, file uploads, or changes in a database. You don’t need to set up or manage any servers. Just write your function, upload it to Lambda, and AWS takes care of the rest — scaling, running, and maintaining the infrastructure behind the scenes. It’s perfect for building lightweight, event-driven applications and automating backend tasks.</p><p><strong>Amazon API Gateway</strong> is a fully managed service that allows you to build, publish, and manage APIs at scale. Think of APIs as the “gateways” that let apps talk to your backend services. With API Gateway, you can easily create RESTful APIs that trigger Lambda functions, enabling you to build powerful serverless applications.</p><p><strong>Create an AWS Lambda Function</strong></p><p>Go to the A<strong>WS Lambda</strong> console. Click <strong>Create function</strong> → Select <strong>Author from scratch</strong>. Enter a <strong>Function name</strong>. Choose <strong>Runtime</strong>: Python 3.9. Click <strong>Create function</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*kZBj7FQuOLyn1BN8rH-FQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*nGLBQ2vssG7M8XncGr4ZDA.png" /></figure><p><strong>Create an Event in AWS Lambda Function</strong></p><p>Go to your function &gt; <strong>test</strong>. Then choose to create <strong>new event</strong>. Provide <strong>event name</strong> and <strong>save </strong>the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*gpLoNXO1VpQ2r_ktMjQhxQ.png" /></figure><p><strong>Deploy and test code</strong></p><p>Go to code section in the function deploy the code there and test the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*u5LyqrZjHIS3ib1YbWHLwQ.png" /></figure><p><strong>If the test succeeds, it should be visible as:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*ZU3YHCgahHBGKiSlakzbLQ.png" /></figure><p>Create an API gateway</p><p>Go to the <strong>API Gateway console</strong>. Click <strong>Create API</strong> → Choose <strong>HTTP API</strong>. Click <strong>Build</strong>. Set the <strong>Integration type</strong> to <strong>Lambda Function</strong>. Select your <strong>Lambda function</strong>. Click <strong>Next</strong>, configure other settings, and Click <strong>create</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*D0zst9AZ-ZfdRfQ23zDnBA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*6sqJ0U8y7y49_7beIxCabw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*-yh_fDSoybAXfFIBIgpFSA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*nZ_eBu7CZuCejq6I6IhHEA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*znrnl8neYPC9X9-OpbKmMQ.png" /></figure><p><strong>Create a stage in API gateway</strong></p><p>Go to your <strong>API gateway</strong> &gt; <strong>stages</strong>. Click on <strong>create</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*JGDYHfHUIpoOD-VOx5EkYw.png" /></figure><p>Then, give stage name and description</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*JGB--XIRGLa_zPeRQ_iJbQ.png" /></figure><p>Then deploy the stage</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*gCkW9YB9pLB_5eEWU32qkA.png" /></figure><p>After that, use invoke URL to test and open in browser.</p><p>Note: Don’t forget to use function name in url /saugatfunc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ldz4m6zNAthqN0mHUlvoTw.png" /></figure><h3>🔚 Conclusion</h3><p>Connecting <strong>AWS Lambda</strong> with <strong>API Gateway</strong> is a powerful way to build scalable, serverless applications. With just a few steps, you can create an endpoint that runs your code in response to HTTP requests — no need to manage servers or worry about scaling. This setup is ideal for building APIs, automating backend processes, or handling real-time data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78478aa39b8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Hosting a Static Website on Amazon S3 — A Beginner’s Guide]]></title>
            <link>https://medium.com/@saugatrijal99/hosting-a-static-website-on-amazon-s3-a-beginners-guide-e0dd72e9d2cf?source=rss-f75595ab59b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0dd72e9d2cf</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-beginner]]></category>
            <category><![CDATA[s3]]></category>
            <dc:creator><![CDATA[Saugat Rijal]]></dc:creator>
            <pubDate>Tue, 15 Apr 2025 14:44:05 GMT</pubDate>
            <atom:updated>2025-04-15T14:44:05.241Z</atom:updated>
            <content:encoded><![CDATA[<h3>🚀 Hosting a Static Website on Amazon S3 — A Beginner’s Guide</h3><p>In the world of web development and cloud computing, <strong>Amazon S3 (Simple Storage Service)</strong> is one of the easiest and most cost-effective ways to host a <strong>static website</strong>. Whether you’re showcasing a portfolio, a resume, a product landing page, or documentation — S3 has your back.</p><p>In this guide, I’ll walk you through <strong>step-by-step</strong> how to host a static website on <strong>Amazon S3</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*3E_DoPgNgG3a2v6FWzeHGA.png" /></figure><p><strong>Create bucket on S3</strong></p><p>You will be redirected to the S3 dashboard. Here, create a bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*5VfmCWB57rHYZPJv3mVHHQ.png" /></figure><p>Then, uploading file on bucket</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*d7r-7RCAPZYA_oRC2T6keg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*6lJ2KwDbHBFjVHRi6iq1nw.png" /></figure><p><strong>Enabling Static Website Hosting</strong></p><p>Navigating to the <strong>Properties </strong>tab and scrolling to <strong>Static website hosting</strong> &amp; choose on <strong>edit</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*6p6eKnnjVs-a7bVwJjAwbw.png" /></figure><p>Configuring the bucket policy for Public Access</p><p>Navigate to the <strong>Permissions </strong>tab. And under <strong>Bucket policy,</strong> adding the following JSON policy and save the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*0_fE9LJ4S1S91MjX6KSKTw.png" /></figure><p>Accessing the Website</p><p>Go back to <strong>Properties </strong>and in <strong>Static website hosting</strong>. Copying the <strong>Bucket website endpoint</strong>. And opening it in a browser to verify that our website is live.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*RgHsZ6b2M1WkIl4f67Unlg.png" /></figure><p><strong>Conclusion</strong></p><p>Hosting a static site on S3 is simple, scalable, and nearly free (you pay only for what you use). It’s a great choice for developers, bloggers, or startups wanting to launch quickly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0dd72e9d2cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating S3 Event Notifications with AWS Lambda and SNS: Complete Guide]]></title>
            <link>https://medium.com/@saugatrijal99/automating-s3-event-notifications-with-aws-lambda-and-sns-complete-guide-4f0139390a1e?source=rss-f75595ab59b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f0139390a1e</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-automation]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Saugat Rijal]]></dc:creator>
            <pubDate>Tue, 08 Apr 2025 14:54:36 GMT</pubDate>
            <atom:updated>2025-04-15T13:26:23.268Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*jK1_-S41xNtLVEURjgNP6A.png" /><figcaption>Figure: Architecture of AWS S3 Event Notification with Lambda &amp; SNS</figcaption></figure><h3>Introduction</h3><p>This documentation explains how to automatically send notifications when something changes in an Amazon S3 bucket, like when a file is uploaded, deleted, or updated. It uses AWS services like Lambda and SNS to make this happen. By setting up event triggers in S3, a Lambda function can run automatically when a change happens. Then, using SNS, it can send alerts through email, SMS, or other services. In this documentation, you’ll also learn how to create a Lambda function that runs whenever a new file is added to your S3 bucket. This function will grab the event details and send an email using Amazon SNS (Simple Notification Service).</p><h4>Steps:</h4><ol><li>Create a S3 bucket</li><li>Create an SNS Topic</li><li>Subscribe an Email to SNS Topic</li><li>Create an IAM Role for Lambda</li><li>Create a Lambda Function</li><li>Add Environmental Variable for SNS</li><li>Write the Lambda code</li><li>Configure S3 to Trigger Lambda on file upload, delete &amp; update</li><li>Testing the setup</li></ol><h3><strong>Step-by-Step Implementation</strong></h3><h3><strong>Step 1: Create an S3 Bucket</strong></h3><ol><li>Go to the<strong> AWS Management Console → Open S3.</strong></li><li>Click <strong>Create Bucket.</strong></li><li>Provide a unique<strong> Bucket Name (e.g. s3-event-bucket).</strong></li><li>Choose the AWS<strong> Region.</strong></li><li>Keep other settings as default and click<strong> Create Bucket.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*y9i4iPR-crEX7qi0yUso1Q.png" /></figure><h3><strong>Step 2: Create an SNS Topic</strong></h3><ol><li>Go to the <strong>AWS Management Console</strong> → Open <strong>SNS</strong>.</li><li>Click <strong>Create topic</strong>.</li><li>Select <strong>Standard</strong> as the type.</li><li>Enter a <strong>Topic name</strong> (e.g., S3EventNotificationTopic).</li><li>Click <strong>Create topic</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*euqGnQ120NBUadasSdRUWw.png" /></figure><p>6. Copy the <strong>Topic ARN</strong> (Amazon Resource Name) — we will use it in Lambda.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*jL4-CESF_my5Zo05gADAMw.png" /></figure><h3><strong>Step 3: Subscribe an Email to SNS Topic</strong></h3><ol><li>In the <strong>SNS console</strong>, go to <strong>Subscriptions</strong> → Click <strong>Create Subscription</strong>.</li><li>Select the <strong>Topic ARN</strong> from Step 2.</li><li>Choose <strong>Email</strong> as the Protocol.</li><li>Enter your <strong>email address</strong>.</li><li>Click <strong>Create Subscription</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*EQIB_8q_Co_UX1kWOVM-9w.png" /></figure><p>Now check your email you will get mail. Click on confirm subscription link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*ZJrOfAF7d_YZg8LwjD7IEA.png" /></figure><p>Now this email is confirmed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*tDjBa7SvID6wgyHGzazYjA.png" /></figure><h3><strong>Step 4: Create an IAM Role for Lambda</strong></h3><p>To allow Lambda to access S3 and SNS, we need an IAM role:</p><ol><li>Go to the <strong>AWS IAM Console</strong> → Click <strong>Roles</strong> → <strong>Create role</strong>.</li><li>Select <strong>Lambda</strong> as the trusted entity.</li><li>Attach the following policies:<br> AmazonS3ReadOnlyAccess (To read from S3)<br> AmazonSNSFullAccess (To publish to SNS)</li><li>Click <strong>Next</strong>, give the role a name (e.g., LambdatoS3SNS), and click <strong>Create role</strong>.</li></ol><p>5. Copy the <strong>Role ARN</strong> — we will use it in Lambda</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*qBWWPWZYUjg1bui6NT-6TA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*SqZ4L6Awr6aD2a79no5W0w.png" /></figure><h3><strong>Step 5: Create a Lambda Function</strong></h3><ol><li>Go to <strong>AWS Lambda Console</strong> → Click <strong>Create function</strong>.</li><li>Choose <strong>Author from Scratch</strong>.</li><li>Enter a <strong>Function name</strong> (e.g., SNStoS3).</li></ol><p>4. Select <strong>Python 3.9</strong> as the runtime.</p><p>5. Choose <strong>Use an existing role</strong> → Select the IAM Role from Step 4.</p><p>6. Click <strong>Create function</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*HJl1aZC8Oyx-u74BgVFw_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*3_C-Rqf2-XthTsxvvwo5bA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*lCKz68ZuaoeME2T5kq56kA.png" /></figure><h3><strong>Step 6: Add Environment Variable for SNS</strong></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 (must this)</li><li>Value: Paste the <strong>SNS Topic ARN</strong> from Step 2.</li></ol><p>5. Click <strong>Save.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*stTIVaV7oUzF9njs_1Vw1w.png" /></figure><blockquote>Make sure to “SNS_TOPIC_ARN” in key</blockquote><h3><strong>Step 7: Write the Lambda Code</strong></h3><p>Replace the default Lambda code with the following in the Code editor</p><p>Click <strong>Deploy</strong> to save the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*zkDak5mQB6IzBI1etQzBhw.png" /></figure><p>Code</p><pre>import json<br>import boto3<br>import os<br># Initialize SNS client<br>sns_client = boto3.client(&#39;sns&#39;)<br># Load SNS topic ARN from environment variables<br>SNS_TOPIC_ARN = os.environ.get(&#39;SNS_TOPIC_ARN&#39;)<br>def lambda_handler(event, context):<br> print(&quot;Received event: &quot; + json.dumps(event, indent=2))<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>message = f&quot;📢 S3 Event Notification 📢\n\n🔹 Event: {event_name}\n🔹 Bucket: {bucket_name}\n🔹 Object: {object_key}&quot;<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>print(f&quot;✅ Notification sent! Message ID: {response[&#39;MessageId&#39;]}&quot;)<br>return {&quot;statusCode&quot;: 200, &quot;body&quot;: json.dumps(&quot;Notification sent successfully!&quot;)}</pre><h3><strong>Step 8: Configure S3 to Trigger Lambda on File Upload</strong></h3><ol><li>Go to the <strong>AWS S3 Console</strong> → Select your bucket.</li><li>Go to <strong>Properties</strong> → Scroll down to <strong>Event notifications</strong>.</li><li>Click <strong>Create event notification</strong>.</li><li><strong>Event Name</strong>: (e.g., file_trigger).</li><li>Under <strong>Event types</strong>, select <strong>PUT</strong> and <strong>Permanently Deleted</strong>.</li><li>Under <strong>Destination</strong>, Choose <strong>Lambda function</strong>.</li><li>Select the <strong>Lambda function</strong> you created (S3EventNotifier).</li></ol><p>8. Click <strong>Save changes</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*JrGG5wUGEsOTV05odGuFIQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*P8s-FMPqfSROHM7Cn44-0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*gTE0gcEGKqp2DB2RrWPGbQ.png" /></figure><h3><strong>Step 9: Test the Setup</strong></h3><ol><li>Upload a file to your <strong>S3 bucket</strong>.</li><li>Wait a few seconds, then check your <strong>email inbox</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*thplhBspNAKr-RBPA5RepA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*HSio2meqa7SMiWgJM1uJ0Q.png" /></figure><p>Open Email</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*Ul1th79N5641tSh617rzWw.png" /></figure><h3><strong>Conclusion</strong></h3><p>In summary, using AWS Lambda and SNS to automate S3 event notifications make efficiency by allowing real-time processing and instant alerts for file updates. This serverless method simplifies workflows, cuts down on manual tasks, and enhances system responsiveness, making it a great choice for automating events in AWS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f0139390a1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>