<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Prahal N P</title>
    <description>The latest articles on Forem by Prahal N P (@prahal_np_690f1dc355c914).</description>
    <link>https://forem.com/prahal_np_690f1dc355c914</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2966527%2F00614f13-9de6-4fd8-8c8e-ec03096afb7f.jpg</url>
      <title>Forem: Prahal N P</title>
      <link>https://forem.com/prahal_np_690f1dc355c914</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/prahal_np_690f1dc355c914"/>
    <language>en</language>
    <item>
      <title>EC2 Key Pairs</title>
      <dc:creator>Prahal N P</dc:creator>
      <pubDate>Fri, 19 Dec 2025 05:46:29 +0000</pubDate>
      <link>https://forem.com/prahal_np_690f1dc355c914/ec2-key-pairs-46jh</link>
      <guid>https://forem.com/prahal_np_690f1dc355c914/ec2-key-pairs-46jh</guid>
      <description>&lt;p&gt;EC2 key pairs are cryptographic keys used for secure SSH access to Amazon EC2 instances.&lt;/p&gt;

&lt;p&gt;It's a combination of 2 keys.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Public key: Stored by AWS and placed on your EC2 instance.&lt;/li&gt;
&lt;li&gt;Private key: Downloaded to your local machine.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How EC2 Key Pair works:&lt;/strong&gt;&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;While creating an ec2 instance we have 2 option we can provide the existing key pair or we can create part of the ec2 instance.&lt;/li&gt;
&lt;li&gt;Once the ec2 key-pair created, we have an option to download the private key. Once downloaded AWS will delete it and cannot be recovered.&lt;/li&gt;
&lt;li&gt;Public key will be stored within AWS and used by Ec2 instances.&lt;/li&gt;
&lt;li&gt;When we create the instance by providing the key-pair the public key will be stored in the &lt;strong&gt;~/.ssh/authorized_keys&lt;/strong&gt; folder.&lt;/li&gt;
&lt;li&gt;While connecting to instance user use the Private key instead of password.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Key Pairs don't get deleted from Ec2 instance's root volume when the key pair removed from the ec2 console&lt;/li&gt;
&lt;li&gt;Launching an ec2 with the golden/pre-build ami, the old key(used while building AMI) will exist with the new key pair in the root volume. User can Use any of the private keys to SSH the instance.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How Instance Connect works:&lt;/strong&gt;&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;User Initiate the connection by Ec2 Instance connect API.&lt;/li&gt;
&lt;li&gt;Ec2 instance connect will create an temporary ec2 key pair.&lt;/li&gt;
&lt;li&gt;Private key will be handled by ec2 instance connect and public key will be passed to instance through instance metadata which will be valid only for 60 seconds.
4.Ec2 instance connect will ssh the ec2 with the AWS IP address range to the instance with the Private key.&lt;/li&gt;
&lt;li&gt;The session starts and all the connections are logged in cloudtrail.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How to Connect to Linux EC2 Instance with a Lost &lt;br&gt;
SSH Key Pair:&lt;/strong&gt;&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;Create a new Key Pair&lt;/li&gt;
&lt;li&gt;Stop the original EC2 instance&lt;/li&gt;
&lt;li&gt;Detach the EBS root volume&lt;/li&gt;
&lt;li&gt;Attach the EBS volume to a temporary EC2 instance as a secondary volume&lt;/li&gt;
&lt;li&gt;Add the new public key to ~/.ssh/authorized_keys on the volume&lt;/li&gt;
&lt;li&gt;Re-attach the volume to the original instance, then restart the instance&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>aws</category>
      <category>beginners</category>
      <category>security</category>
    </item>
    <item>
      <title>AWS Envelop Encryption</title>
      <dc:creator>Prahal N P</dc:creator>
      <pubDate>Thu, 18 Dec 2025 06:43:22 +0000</pubDate>
      <link>https://forem.com/prahal_np_690f1dc355c914/aws-envelop-encryption-56jj</link>
      <guid>https://forem.com/prahal_np_690f1dc355c914/aws-envelop-encryption-56jj</guid>
      <description>&lt;p&gt;First we will learn what is encryption, Encryption is the process of scrambling readable data (plaintext) into an unreadable code (ciphertext) using an algorithm and a secret key, preventing unauthorized access.&lt;/p&gt;

&lt;p&gt;In AWS, the KMS service manages encryption, specifically for data at rest. This service encrypts data only if its size is less than 4 KB. For data larger than 4 KB, KMS uses envelope encryption.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How AWS Encryption and Decryption works works:&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;For data size less than 4 kb KMS will take care of the encryption process.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;AWS SDK/CLI calls the encrypt API with the secret data.&lt;/li&gt;
&lt;li&gt;KMS validates the IAM permissions for the user to perform the API.&lt;/li&gt;
&lt;li&gt;If the user has permission, KMS encrypts the data and sends the encrypted data.&lt;/li&gt;
&lt;li&gt;During decryption, AWS SDK/CLI calls the decrypt API with the encrypted data.&lt;/li&gt;
&lt;li&gt;KMS validates the IAM permissions for the user to perform the API.&lt;/li&gt;
&lt;li&gt;If the user has permission, KMS decrypts the data and sends the decrypted data.&lt;/li&gt;
&lt;li&gt;AWS KMS manages the encryption/decryption key if we use keys stored in KMS.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How AWS Envelope Encryption works:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;KMS Encrypt API call has a limit of 4 KB. If you want to encrypt &amp;gt;4 KB, we need to use Envelope Encryption&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encryption:&lt;/strong&gt;&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;This time we want to encrypt a big file ie, more than 4KB file.&lt;/li&gt;
&lt;li&gt;We are going to use the SDK to call the GenerateDataKey API by specifying CMK.&lt;/li&gt;
&lt;li&gt;If the requester has the permission, KMS will provide 2 keys, plaintext DEK and encrypted DEK.&lt;/li&gt;
&lt;li&gt;SDK will encrypt the secret file with the plaintext DEK.&lt;/li&gt;
&lt;li&gt;Finally SDK will create an single Final file which has encrypted secret file and encrypted DEK.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Decryption:&lt;/strong&gt;&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;During decryption AWS SDK will call the Decrypt API with the envelop file.&lt;/li&gt;
&lt;li&gt;If the requester has the permission, KMS will decrypt the encrypted DEK part of the envelop file using KMS CMK, and send the plaintext data key.&lt;/li&gt;
&lt;li&gt;AWS SDK will decrypt the encrypted file. &lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>aws</category>
      <category>security</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>High Availability Multi-Region RDS Instance</title>
      <dc:creator>Prahal N P</dc:creator>
      <pubDate>Sat, 05 Apr 2025 03:08:50 +0000</pubDate>
      <link>https://forem.com/prahal_np_690f1dc355c914/high-availability-multi-region-rds-instance-4omm</link>
      <guid>https://forem.com/prahal_np_690f1dc355c914/high-availability-multi-region-rds-instance-4omm</guid>
      <description>&lt;p&gt;Amazon Relational Database Service (Amazon RDS) is an managed relational database service. Amazon RDS automates undifferentiated database management tasks, such as provisioning, configuring, backing up, and patching.&lt;/p&gt;

&lt;p&gt;Currently AWS support Highly available, durable relational databases deployed across up to three Availability Zones (AZs) ie, Multi-AZ where standby instance is created in other availability zone to enhance availability and resilience, ensuring that if one zone fails, the system can automatically switch to another. AWS support multi-AZ where any availability zone goes down the system will be available through standby instance.&lt;/p&gt;

&lt;p&gt;The solution outlined here supports the RDS instance during regional unavailability. In this setup, resources are provisioned using Cloudformation templates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Primary region architecture:&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;The CloudFormation stack outlined above provisions the following resources: two Lambda functions that create RDS-related resources, an SSM parameter containing the RDS information, and an alarm parameter. where lambda code will be residing in the s3 bucket. Here this template expects the RDS parameter and alarms parameters as input.&lt;/p&gt;

&lt;p&gt;The Create_resource_primary_region Lambda function will be established as a component of the CloudFormation template. It is triggered directly from the stack itself. During the stack creation process, this Lambda function activates and generates RDS instance, alarms based on the provided input. Additionally, this Lambda function updates the parameters to the SSM parameter, which is integral to the stack.&lt;/p&gt;

&lt;p&gt;The Create_stack_secondary_region lambda function is designed to retrieve the CloudFormation template from S3. Based on the specified secondary region parameter, it will create a stack in that region. which completes the deployment process in the primary region, which is halfway in our overall solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secondary region architecture:&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;This stack provisions the following resources: 2 event-bridge rule, an ssm parameter, an lambda function and an sns-topic.&lt;/p&gt;

&lt;p&gt;During the stack creation, the Create_resource_failover_fallback_action Lambda function is triggered. This function creates a read replica in the secondary region from the primary region's RDS instance. Additionally, it updates the RDS instance parameters and alarm parameters in the SSM parameter store. This process successfully completes the deployment.&lt;/p&gt;

&lt;p&gt;During the primary region outage, the RDS_failover_event event bridge rule will trigger the Create_resource_failover_fallback_action lambda which will do following actions. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Notifies outage to users through sns topic.&lt;/li&gt;
&lt;li&gt;failover_status_check event rule will be disabled intially but enables now which will invoke the lambda every 5mins.&lt;/li&gt;
&lt;li&gt;Promotes the RDS Read replica(This will take sometime in this time the rds will be outage)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The failover_status_check rule triggers a lambda function that verifies the promotion status. If the instance is successfully promoted, the lambda creates an alarm. Once all components are set up, signaling the completion of the failover process. The failover_status_check rule is then disabled, and users are notified through the designated topic.&lt;/p&gt;

&lt;p&gt;In the event that the region recovers during the promotion phase, the RDS_failover_event rule will notify the lambda, which will delete the promoting instance and create a new read replica in the secondary region using the primary region instance. Users will also receive notifications through the topic in this scenario.&lt;/p&gt;

&lt;p&gt;Once the primary region comes back then RDS_failover_event rule will notifies the lambda which will do the same steps for fallback ie, &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Notifies outage to users through sns topic.&lt;/li&gt;
&lt;li&gt;failover_status_check event rule will be disabled initially but enables now which will invoke the lambda every 5mins.&lt;/li&gt;
&lt;li&gt;Create the read replica in the primary region from secondary region instance, the primary region instance and the alarm are deleted, the execution exits.&lt;/li&gt;
&lt;li&gt;The failover_status_check rule will trigger the lambda every 5 mins so it will be checking creating status once created.. &lt;/li&gt;
&lt;li&gt;Promotes the RDS Read replica in primary region.(This will take sometime in this time the rds will be outage)
Failover_status_check rule will invoke the lambda which will check for the promotion status if promoted then lambda creates alarm and create read replica in secondary region. once everything created, the secondary region instance and alarm will be deleted and fallback is completed, disables the failover_status_check rule and notifies users through the topic.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: Here we can fallback during maintenance windows too.Incase user has budget concern we can use the rds automated backups instead of the read-replicas which will reduce the budget but there is limitation of supported replication region!!&lt;/p&gt;

&lt;p&gt;Following is the RDS_failover_event event rule pattern:&lt;br&gt;
{&lt;br&gt;
"source": ["aws.health"],&lt;br&gt;
"detail-type": ["AWS Health Event"],&lt;br&gt;
"detail": {&lt;br&gt;
"service": ["RDS"],&lt;br&gt;
"eventTypeCategory": ["issue"],&lt;br&gt;
"eventTypeCode": ["AWS_RDS_API_ISSUE", "AWS_RDS_CONNECTIVITY_ISSUE", "AWS_RDS_OPERATIONAL_ISSUE"],&lt;br&gt;
"statusCode": ["open","closed"]&lt;br&gt;
},&lt;br&gt;
"resources": [!Ref pDBIdentifier],&lt;br&gt;
"region": [!Ref pPrimaryRegion]&lt;br&gt;
}&lt;/p&gt;

</description>
      <category>aws</category>
      <category>rds</category>
    </item>
  </channel>
</rss>
