<?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 Nischaal Karkeey on Medium]]></title>
        <description><![CDATA[Stories by Nischaal Karkeey on Medium]]></description>
        <link>https://medium.com/@nischaalkarkeey?source=rss-a416acb68978------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*nj6pTZLEUCpK-4UB</url>
            <title>Stories by Nischaal Karkeey on Medium</title>
            <link>https://medium.com/@nischaalkarkeey?source=rss-a416acb68978------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 14:45:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nischaalkarkeey/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Set Up Jenkins on AWS EC2 (Complete Guide with Commands)]]></title>
            <link>https://medium.com/@nischaalkarkeey/how-i-set-up-jenkins-on-aws-ec2-complete-guide-with-commands-ab095d8d1678?source=rss-a416acb68978------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab095d8d1678</guid>
            <dc:creator><![CDATA[Nischaal Karkeey]]></dc:creator>
            <pubDate>Thu, 10 Apr 2025 12:10:57 GMT</pubDate>
            <atom:updated>2025-04-10T12:10:57.188Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, I’m excited to walk you through a <strong>complete, step-by-step installation of Jenkins</strong> on an <strong>AWS EC2 instance</strong> — a foundational DevOps skill for mastering CI/CD automation.</p><p>Here’s exactly what I did</p><h3>Step 1: Launch an EC2 Instance</h3><ol><li>Log in to your <strong>AWS Console</strong>, navigate to <strong>EC2 Dashboard</strong>, and click <strong>“Launch Instance”</strong>.</li><li>Name the instance: jenkins-server (or anything you prefer).</li><li>Select an <strong>Amazon Linux 2 AMI</strong> (free tier eligible).</li><li>Choose an instance type: t2.micro is enough for testing.</li><li>Create a <strong>new key pair</strong> (or use existing). Download the .pem file (e.g., jenkins-key.pem) — <strong>this is critical for SSH access</strong>.</li><li>Configure a <strong>Security Group</strong>:</li></ol><ul><li>Allow <strong>SSH (port 22)</strong> for remote access.</li><li>Add a <strong>Custom TCP rule for port 8080</strong> (Jenkins default UI port).</li></ul><p>7. Click <strong>Launch Instance</strong>.</p><h3>Step 2: Connect to EC2 via SSH</h3><ol><li>On your local terminal, go to where your .pem file is stored and secure it:</li></ol><pre>chmod 400 ~/Downloads/jenkins-key.pem</pre><ol><li>Get the <strong>Public IPv4 address</strong> of the instance from AWS.</li><li>Connect to your instance:</li></ol><pre>ssh -i ~/Downloads/jenkins-key.pem ec2-user@&lt;YOUR_PUBLIC_IPV4&gt;</pre><h3>Step 3: Install Java (Required for Jenkins)</h3><p>Update your instance:</p><pre>sudo yum update -y</pre><ol><li>Install Java 17 (Amazon Corretto):</li></ol><pre>sudo yum install java-17-amazon-corretto -y</pre><p>2. Verify the installation:</p><pre>java -version</pre><p>✅ Output should confirm Java 17 is installed</p><h3>Step 4: Install Jenkins</h3><ol><li>Add Jenkins repo:</li></ol><pre>sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo</pre><p>2.Import Jenkins GPG key:</p><pre>sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key</pre><p>3. Install Jenkins:</p><pre>sudo yum install jenkins -y</pre><p>4. Enable Jenkins service on boot:</p><pre>sudo systemctl enable jenkins</pre><p>5. Start Jenkins:</p><pre>sudo systemctl start jenkins</pre><p>6. Check if Jenkins is running:</p><pre>sudo systemctl status jenkins</pre><p>✅ You should see “active (running)”.</p><h3>Step 5: Configure Security Group to Allow Web Access</h3><ol><li>Go to your EC2 instance in the AWS Console.</li><li>Under <strong>Security</strong>, click on your <strong>Security Group</strong>.</li><li>Click <strong>Edit Inbound Rules</strong>, then:</li></ol><ul><li>Add <strong>Custom TCP Rule</strong>:</li><li>Port Range: 8080</li><li>Source: 0.0.0.0/0 (or your IP for better security)</li></ul><p>4. Save the rule.</p><h3>Step 6: Access Jenkins Web Interface</h3><ol><li>In your browser, go to:</li></ol><pre>http://&lt;YOUR_PUBLIC_IPV4&gt;:8080</pre><p>2. Get the initial admin password:</p><pre>sudo cat /var/lib/jenkins/secrets/initialAdminPassword</pre><ol><li>Paste it into the web UI to unlock Jenkins.</li><li>Select <strong>Install Suggested Plugins</strong>.</li><li>Create an admin user → Set up name, password, email.</li><li>Click <strong>Save and Finish</strong>.</li></ol><p>🎉 Jenkins is now ready to use!</p><h3>Step 7: Create Your First Jenkins Job</h3><ol><li>From Jenkins Dashboard, click <strong>“New Item”</strong>.</li><li>Enter a name and select <strong>Freestyle project</strong>.</li><li>Configure source code, build steps, triggers as needed.</li><li>Click <strong>Save</strong>, then <strong>Build Now</strong> to run it.</li></ol><h3>Final Result</h3><p>You now have a <strong>fully operational Jenkins server</strong> on AWS EC2, perfect for:</p><ul><li>CI/CD pipelines</li><li>Automating builds</li><li>Deploying code</li><li>Learning infrastructure management</li></ul><p>This hands-on setup was a great way to deepen my understanding of:</p><ul><li>Jenkins installation &amp; config</li><li>Linux server administration</li><li>Secure EC2 usage</li><li>DevOps toolchains on cloud</li></ul><p>Looking forward to scaling this further and integrating with Git, Docker, and more!</p><p>#DevOps #Jenkins #AWS #EC2 #CloudComputing #CI_CD #Automation #InfrastructureAsCode #LearningInPublic #TechJourney #DevOpsEngineer</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab095d8d1678" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transferring a WordPress site hosted on Lightsail to an EC2-based environment.]]></title>
            <link>https://medium.com/@nischaalkarkeey/transferring-a-wordpress-site-hosted-on-lightsail-to-an-ec2-based-environment-b386b9f1bd0c?source=rss-a416acb68978------2</link>
            <guid isPermaLink="false">https://medium.com/p/b386b9f1bd0c</guid>
            <dc:creator><![CDATA[Nischaal Karkeey]]></dc:creator>
            <pubDate>Tue, 08 Apr 2025 09:28:05 GMT</pubDate>
            <atom:updated>2025-04-08T09:28:05.457Z</atom:updated>
            <content:encoded><![CDATA[<h3>Step 1: Host WordPress in AWS Lightsail</h3><ol><li><strong>Create a Lightsail Instance</strong></li></ol><ul><li>Go to the <a href="https://lightsail.aws.amazon.com/">AWS Lightsail Console</a>.</li><li>Click <strong>Create Instance</strong> → Select <strong>Linux/Unix</strong> → Choose <strong>WordPress Blueprint</strong>.</li><li>Choose an instance plan (cheapest is fine for testing).</li><li>Set a name (e.g., wordpress-ls) and create the instance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*zF_3wuoP6-WqD2mt.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*M1WmosVTpbDXVWV_.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*cXTJzBbu4rlcwsv5.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*0xgn4hRMwiXqNNEN.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*bQ5mgXtdhy7FmcaA.png" /></figure><p><strong>2. Access WordPress Admin Panel</strong></p><ul><li>Connect to your instance using SSH (click <strong>“Connect using SSH”</strong> in Lightsail)</li><li>Type: cat bitnami_application_password</li><li>Copy the password displayed</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*qi8EmWPxrp9RAjwy.png" /></figure><ul><li>Open http://&lt;Lightsail-IP&gt;/wp-admin/.</li></ul><p>Now Login to the wordpress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*iWxyd-elBBzvuvOo.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*H8eLbJoXw38Qu2rq.png" /></figure><h3>Step 2: Backup the WordPress Site in S3</h3><ol><li><strong>Create S3 Bucket.</strong></li></ol><ul><li>Go to S3 in AWS Console</li><li>Click “Create bucket”</li><li>Name it (e.g., “backup-wordpress-demo”)</li><li>Keep default settings, click “Create bucket”</li></ul><p><strong>2. Backup the Database</strong>:</p><ul><li>In <strong>Lightsail SSH Terminal</strong>, run:<br>This will generate a pwd.</li></ul><pre>cat /opt/bitnami/wordpress/wp-config.php</pre><pre># Use the Bitnami MariaDB command (note the correct path)<br>/opt/bitnami/mariadb/bin/mariadb-dump -u bn_wordpress -p bitnami_wordpress &gt; wordpress-dump.sql</pre><pre># Enter the password when prompted</pre><p><strong>2. Backup WordPress Files</strong>:</p><pre>sudo zip -r wordpress-site.zip /opt/bitnami/wordpress/wp-content /opt/bitnami/wordpress/wp-config.php</pre><ul><li><strong>Set Up AWS CLI:</strong></li></ul><pre>sudo apt install awscli -y<br>aws configure<br># Enter your AWS Access Key, Secret Key, region (e.g., ap-south-1), and output format (json)</pre><ul><li>Enter your <strong>AWS Access Key &amp; Secret Key</strong>.</li><li>Choose <strong>region</strong> (e.g., us-east-1).</li><li>Upload backup files to S3:</li></ul><pre>aws s3 cp wordpress-dump.sql s3://Your-Bucket-Name/<br>aws s3 cp wordpress-site.zip s3://Your-Bucket-Name/</pre><p>✅ <strong>Now, the WordPress backup is safely stored in S3!</strong></p><h3>Step 3: Migrate WordPress to EC2</h3><h3>1. Launch an EC2 Instance</h3><ol><li>Go to <strong>AWS EC2 Console</strong> → Click <strong>Launch Instance</strong>.</li><li><strong>Choose Amazon Linux or Ubuntu</strong>.</li><li><strong>Select Instance Type</strong> (t2.micro for free-tier).</li><li><strong>Configure Security Group</strong>:</li></ol><ul><li>Allow <strong>HTTP (80)</strong>, <strong>HTTPS (443)</strong>, and <strong>SSH (22)</strong>.</li></ul><p><strong>5. Launch &amp; Download Key Pair</strong> (e.g., ec2-key.pem).</p><h3>2. Connect to EC2 &amp; Install LAMP Stack</h3><p><strong>Connect to EC2 via SSH:</strong></p><pre>ssh -i ec2-key.pem ec2-user@&lt;ec2-public-ip&gt;</pre><p><strong>Install LAMP Stack (Apache, MySQL, PHP)</strong></p><pre># Update system<br>sudo dnf update -y</pre><pre># Install Apache<br>sudo dnf install httpd -y<br>sudo systemctl start httpd<br>sudo systemctl enable httpd</pre><pre># Install MariaDB (MySQL)<br>sudo dnf install mariadb105-server -y<br>sudo systemctl start mariadb<br>sudo systemctl enable mariadb</pre><pre># Secure MySQL installation<br>sudo mysql_secure_installation<br># Answer prompts:<br># - Set root password: Y<br># - Remove anonymous users: Y<br># - Disallow root login remotely: Y<br># - Remove test database: Y<br># - Reload privilege tables: Y</pre><pre># Install PHP and extensions<br>sudo dnf install php php-mysqlnd php-json php-xml php-mbstring php-curl php-zip unzip -y</pre><pre># Restart Apache to apply PHP settings<br>sudo systemctl restart httpd</pre><h3>✅ LAMP stack is now installed! 🚀</h3><h3>3. Install AWS CLI and Download Backups</h3><pre># Install AWS CLI<br>sudo dnf install aws-cli -y</pre><pre># Configure AWS CLI<br>aws configure<br># Enter your credentials and region</pre><pre># Download backups from S3<br>aws s3 cp s3://Your-Bucket-Name/wordpress-dump.sql .<br>aws s3 cp s3://Your-Bucket-Name/wordpress-site.zip .</pre><h3>Install WordPress Core</h3><pre># Navigate to the WordPress installation directory<br>cd /var/www/html</pre><pre># Remove default WordPress files (be cautious with this step)<br>sudo rm -rf *  </pre><pre># Download the latest WordPress<br>sudo wget <a href="https://wordpress.org/latest.tar.gz">https://wordpress.org/latest.tar.gz</a></pre><pre># Extract the WordPress files<br>sudo tar -xzf latest.tar.gz --strip-components=1</pre><pre># Clean up the tar file<br>sudo rm latest.tar.gz</pre><h3>Extract Backup Content</h3><pre># Create a temporary directory for extraction<br>sudo mkdir -p /tmp/wp-extract</pre><pre># Extract the backup of the WordPress site files<br>sudo unzip ~/wordpress-site.zip -d /tmp/wp-extract</pre><pre># Replace the wp-content directory with your backup<br>sudo rm -rf /var/www/html/wp-content<br>sudo cp -r /tmp/wp-extract/opt/bitnami/wordpress/wp-content /var/www/html/</pre><pre># Copy the wp-config.php file (but don’t overwrite it yet)<br>sudo cp /tmp/wp-extract/opt/bitnami/wordpress/wp-config.php /tmp/wp-config-backup.php</pre><p>✅ <strong>WordPress files are now in the web directory!</strong></p><h3>4. Create Database and User</h3><p>You’ll need to create a new database and user for WordPress:</p><pre># Connect to MySQL<br>sudo mysql -u root -p</pre><pre># In the MySQL prompt:<br>CREATE DATABASE wordpress;<br>CREATE USER &#39;user&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;choose-strong-password&#39;;<br>GRANT ALL PRIVILEGES ON wordpress.* TO &#39;user&#39;@&#39;localhost&#39;;<br>FLUSH PRIVILEGES;<br>EXIT;</pre><p>Make sure to replace choose-strong-password with a strong password for the user.</p><p><strong>Import the Database:</strong></p><pre># Check your home directory<br>ls ~/</pre><pre># If the file is in your home directory, use this command to move it<br>mv ~/wordpress-dump.sql /var/www/html/</pre><pre>cd /var/www/html<br>mysql -u user -p wordpress &lt; wordpress-dump.sql</pre><p>✅ <strong>Database is now restored!</strong> 🎉</p><h3>5. Configure WordPress</h3><ol><li><strong>Create </strong><strong>wp-config.php:</strong></li></ol><pre># Create wp-config.php</pre><pre>cd /var/www/html<br>sudo cp wp-config-sample.php wp-config.php<br>sudo nano wp-config.php</pre><p>2. <strong>Update these lines:</strong></p><pre>define(&#39;DB_NAME&#39;, &#39;wordpress&#39;);<br>define(&#39;DB_USER&#39;, &#39;user&#39;);<br>define(&#39;DB_PASSWORD&#39;, &#39;choose-strong-password&#39;);<br>define(&#39;DB_HOST&#39;, &#39;localhost&#39;);</pre><p>In your wp-config.php, Add the following lines just after the <strong>Database Settings</strong>:</p><pre>define(&#39;WP_HOME&#39;, &#39;http://&lt;your-ec2-ip&gt;&#39;);<br>define(&#39;WP_SITEURL&#39;, &#39;http://&lt;your-ec2-ip&gt;&#39;);</pre><p><strong>Save and exit the file</strong> by pressing CTRL + X, then Y, and hit Enter.</p><p>3. <strong>Set Proper Permissions:</strong></p><p>Ensure that the web server has the proper permissions to read and write the files in your WordPress directory:</p><pre>sudo chown -R apache:apache /var/www/html<br>sudo chmod -R 755 /var/www/html</pre><p>4. <strong>Restart Apache Web Server:</strong></p><pre>sudo systemctl restart httpd</pre><p>✅ <strong>WordPress is now linked to the database!</strong> 🚀</p><h3>Fix: Reset Password for user</h3><p>Try resetting the password using MySQL:</p><ol><li><strong>Log into MySQL as root</strong></li></ol><pre>sudo mysql -u root -p</pre><p>2.<strong> Select the WordPress database</strong></p><pre>USE wordpress;</pre><p>3.<strong> Reset the password for </strong>user</p><pre>UPDATE wp_users SET user_pass = MD5(&#39;YourStrongPassword123&#39;) WHERE user_login = &#39;user&#39;;</pre><p><em>(Replace </em><em>YourStrongPassword123 with your preferred password.)</em></p><p>4.<strong> Exit MySQL</strong></p><pre>EXIT;</pre><h3>6. Access WordPress on EC2</h3><p>Open a browser and visit:</p><pre>http://&lt;ec2-public-ip&gt;/wp-admin</pre><h3>ENTER</h3><ul><li><strong>Username:</strong> user</li><li><strong>Password:</strong> YourStrongPassword123</li></ul><p>🎉 <strong>WordPress is now hosted on EC2!</strong> 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*A0z1zLrKstKzvBaH.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*a6Z99ExOK3bqzFbV.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*JFpP11Pk5eMQfk2F.png" /></figure><p>You now have access to your Wordpress and files.</p><p>✅ <strong>Summary:</strong><br> ✔ Deployed WordPress on Lightsail<br> ✔ Created backup and stored it in S3<br> ✔ Successfully migrated WordPress to EC2</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b386b9f1bd0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated Text Analysis Solution Using AWS Lambda, EC2, and S3 for Counting Words and Letters.]]></title>
            <link>https://medium.com/@nischaalkarkeey/automated-text-analysis-solution-using-aws-lambda-ec2-and-s3-for-counting-words-and-letters-855b2443e5b6?source=rss-a416acb68978------2</link>
            <guid isPermaLink="false">https://medium.com/p/855b2443e5b6</guid>
            <dc:creator><![CDATA[Nischaal Karkeey]]></dc:creator>
            <pubDate>Mon, 24 Mar 2025 08:21:07 GMT</pubDate>
            <atom:updated>2025-03-24T13:27:18.500Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*IWn7c6gUp0_0URPs" /></figure><h3>Introduction</h3><p>This project demonstrates an automated text analysis system that leverages AWS services like Lambda, EC2, and S3. When a text file is uploaded to an S3 bucket, a Lambda function triggers an EC2 instance to read the file, count the number of words and letters, and display the results in the terminal. This approach ensures efficient processing of text data while utilizing scalable cloud resources.</p><p>Detailed Step-by-Step Guide</p><ol><li>Creating an S3 Bucket</li></ol><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/700/0*YJF04-eSDCXFYYCe" /></figure><p>Upload a simple text file you want to count works and letters in your S3 bucket.</p><p>2. Creating an EC2 Instance</p><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/700/0*9fDED4AqDaOgXRyx" /></figure><p>3. Creating and Attaching an IAM Role for EC2</p><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/700/0*GxDiPFfFR8-5sX9P" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*xEoE2zn387fMgmy-" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*MZ0JwenWKQ0n3MTN" /></figure><p><strong>Attach this role to your EC2 instance:</strong></p><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/700/0*cUr-kvBxh_KLSWv_" /></figure><p>4. Creating an IAM Role for AWS Lambda</p><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/700/0*MpIzxeuscwfx4M81" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*GyME5WcFSJf5BfaM" /></figure><p>5. Creating a Lambda Function</p><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/700/0*IBmrf5sw1jRGsv-u" /></figure><p>Inside the code editor, replace the default code with the code below and deploy it.</p><blockquote>import boto3</blockquote><blockquote>ec2 = boto3.client(‘ec2’) INSTANCE_ID = ‘your-ec2-instance-id’</blockquote><blockquote>def lambda_handler(event, context):</blockquote><blockquote>ec2.start_instances (InstanceIds=[INSTANCE_ID])</blockquote><blockquote>print (f”EC2 instance {INSTANCE_ID} started successfully.”)</blockquote><p>Deploy and test the code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*c_rwe4Iw-eOPkoda" /></figure><p>Deploying and Testing Code in Lambda Function</p><p>6. Adding a S3 event to Trigger Lambda</p><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 text file 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/700/0*Yzqoznoq9alyOEhu" /></figure><p>7. Connecting EC2 Instance via SSH</p><blockquote><em>ssh -i “your-key.pem” ec2-user@&lt;EC2-PUBLIC-IP&gt;</em></blockquote><p>Install all required dependencies</p><blockquote>sudo yum update -y</blockquote><blockquote>sudo dnf install -y python3.9 python3-pip</blockquote><blockquote>pip3 install pillow boto3</blockquote><blockquote>python3 — version</blockquote><blockquote>pip3 — version</blockquote><p>8. Creating a Python Script on EC2</p><p>nano (filename).py</p><p>And enter the following python code and make some required changes:<br>If we want to show the results in folder in our S3 bucket we can use this code:</p><p>import boto3</p><p>def count_text(key):<br> “””<br> Download a text file from S3, count words and letters, <br> and save the results back to S3.<br> “””<br> s3 = boto3.client(‘s3’)<br> bucket_name = ‘your-bucket-name’ # Change this to your actual S3 bucket name</p><p>try:<br> # Download text file from S3<br> response = s3.get_object(Bucket=bucket_name, Key=key)<br> content = response[‘Body’].read().decode(‘utf-8’)</p><p># Count words and letters<br> word_count = len(content.split())<br> letter_count = sum(char.isalpha() for char in content)</p><p># Prepare result file<br> result_key = f”results/{key.split(‘/’)[-1].replace(‘.txt’, ‘_result.txt’)}”<br> result_content = f”Words: {word_count}\nLetters: {letter_count}”</p><p># Upload result to S3<br> s3.put_object(Bucket=bucket_name, Key=result_key, Body=result_content)<br> print(f”Result saved as ‘{result_key}’ in S3.”)</p><p>except Exception as e:<br> print(f”Error: {e}”)</p><p># Ensure the script runs only when executed directly<br>if __name__ == “__main__”:<br> count_text(‘count.txt’) # Change ‘count.txt’ to your actual file name</p><p><strong>Now, make your Python script executable with:</strong></p><blockquote>chmod +x filename.py</blockquote><p>Now, run the python code with :</p><blockquote>python3 filename.py</blockquote><p>9. Result:</p><p>The lambda will trigger your EC2 instance and it will download the text file you uploaded earlier in S3 and give result as follow:</p><p><strong>For Case 1, result will show as:<br></strong>“Result saved as ‘results/filename.txt’ in S3” in terminal and it will provide a folder as ‘results/.’ in S3 bucket</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*UsUGeAcRPReu0uzw" /></figure><p>image for case 1</p><p>Then, to test the result we can go to our S3 in AWS Console and it should be as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*As-BoCLxj9XTdpCg" /></figure><p>A new textfile with same name will be available inside results folder and when downloaded a text file will open as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ndhWIfepu8qsXz06" /></figure><p><strong>Conclusion:<br></strong>This project effectively automates text analysis using AWS services. By combining S3 for storage, Lambda for automation, and EC2 for processing, the system efficiently counts words and letters in uploaded text files. This solution demonstrates a scalable and cost-effective method for handling text data, showcasing the power of AWS integration in building automated workflows.</p><p>Steps:</p><ol><li>Creating an S3 Bucket</li><li>Creating an EC2 Instance</li><li>Creating and Attaching an IAM Role for EC2</li><li>Creating an IAM Role for AWS Lambda</li><li>Creating a Lambda Function</li><li>Adding a S3 event to Trigger Lambda</li><li>Connecting EC2 Instance via SSH</li><li>Creating a Python Script on EC2<br>i) Case 1: To show word count result in S3 bucket.<br>ii) Case 2: To show word count result in terminal.</li><li>Result</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=855b2443e5b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>