<?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: Rajesh Gundeti</title>
    <description>The latest articles on Forem by Rajesh Gundeti (@rajesh_gundeti).</description>
    <link>https://forem.com/rajesh_gundeti</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%2F2672919%2Fb354e1d4-64c6-45fb-8d1c-0dd71360c074.jpg</url>
      <title>Forem: Rajesh Gundeti</title>
      <link>https://forem.com/rajesh_gundeti</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rajesh_gundeti"/>
    <language>en</language>
    <item>
      <title>Secure Data Sharing: AWS Lambda Writing to S3 Across Accounts</title>
      <dc:creator>Rajesh Gundeti</dc:creator>
      <pubDate>Wed, 03 Sep 2025 02:33:08 +0000</pubDate>
      <link>https://forem.com/aws-builders/secure-data-sharing-aws-lambda-writing-to-s3-across-accounts-5h1</link>
      <guid>https://forem.com/aws-builders/secure-data-sharing-aws-lambda-writing-to-s3-across-accounts-5h1</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the multi account AWS environment. It is common to have services hosted in one account and the data ingested to the different account. For instance, there is a lambda function in one AWS account and read or write data to the S3 bucket in a different AWS account. &lt;/p&gt;

&lt;p&gt;This blog explains the detailed steps to configure S3 bucket policy and IAM role for lambda function to achieve cross account S3 access with AWS Lambda.&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%2F9n13bh80bne3odqhzale.jpeg" 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%2F9n13bh80bne3odqhzale.jpeg" alt="Secure Data Sharing: AWS Lambda Writing to S3 Across Accounts" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Account A (1111111111): Hosts the Lambda function.&lt;/li&gt;
&lt;li&gt;Account B (2222222222): Owns the target S3 bucket (account_b_bucket).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal is to allow AWS lambda function in Account A to put an object in the S3 bucket of Account B.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Architecture Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The setup involves three main components&lt;/p&gt;

&lt;p&gt;1) IAM role (account_a_lambda_role) in account A and the custom policy attached to the role to access the S3 bucket in account B. &lt;/p&gt;

&lt;p&gt;Attach this policy to the Lambda execution role (replace the bucket name):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "CrossAccountS3",
      "Action": ["s3:GetObject", "s3:PutObject"],
      "Effect": "Allow",
      "Resource": ["arn:aws:s3:::account_b_bucket/*"]
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will grant permissions on the lambda to request access to the S3 bucket in account B.&lt;/p&gt;

&lt;p&gt;2) Trust policy of Lambda Execute Role allows lambda function to assume the role.&lt;/p&gt;

&lt;p&gt;Attach this policy to the Lambda execution role:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "Service": "lambda.amazonaws.com" },
      "Action": "sts:AssumeRole"
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Bucket Policy in Account B that allows IAM role attached to the lambda function in account A to put the object in the bucket. &lt;/p&gt;

&lt;p&gt;Configure the bucket policy in account B to trust account A's Lambda role. Replace the account number, lambda role and bucket name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "Id": "ExamplePolicy",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "CrossAccountBucket",
      "Action": ["s3:GetObject", "s3:PutObject"],
      "Effect": "Allow",
      "Resource": ["arn:aws:s3:::account_b_bucket/*"],
      "Principal": {
        "AWS": ["arn:aws:iam::1111111111:role/account_a_lambda_role"]
      }
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Execution Flow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Lambda in Account A is invoked.&lt;/p&gt;

&lt;p&gt;It assumes the IAM role account_a_lambda_role.&lt;/p&gt;

&lt;p&gt;The role policy allows S3 actions on the target bucket.&lt;/p&gt;

&lt;p&gt;The bucket policy in Account B authorizes the role ARN.&lt;/p&gt;

&lt;p&gt;The Lambda can now securely access the cross-account bucket.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Lambda code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Replace the "TARGET_BUCKET" in the below code with your target bucket name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import boto3
import os
from datetime import datetime

# Initialize S3 client
s3_client = boto3.client("s3")

def lambda_handler(event, context):
    # Get bucket name from environment variable
    bucket_name = os.environ["TARGET_BUCKET"]

    # Generate file content
    timestamp = datetime.utcnow().strftime("%Y-%m-%d_%H-%M-%S")
    file_content = f"Hello from Lambda!\nTimestamp: {timestamp}\n"

    # File name to upload
    file_name = f"lambda_output_{timestamp}.txt"

    try:
        # Upload file content to S3
        s3_client.put_object(
            Bucket=bucket_name,
            Key=file_name,
            Body=file_content.encode("utf-8")
        )

        return {
            "statusCode": 200,
            "body": f"File {file_name} successfully uploaded to {bucket_name}"
        }
    except Exception as e:
        return {
            "statusCode": 500,
            "body": f"Error uploading file: {str(e)}"
        }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By configuring the correct IAM role policies and S3 bucket policies, we can ensure the secure communication between the lambda in one AWS  account and S3 bucket in a different AWS account.&lt;/p&gt;

&lt;p&gt;This pattern is not limited to the Lambda function. It can be applied to other services like EC2, ECS tasks etc.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>serverless</category>
      <category>security</category>
      <category>lambda</category>
    </item>
    <item>
      <title>Configuring Hybrid Authentication (Certificates + Users) in AWS Client VPN</title>
      <dc:creator>Rajesh Gundeti</dc:creator>
      <pubDate>Fri, 22 Aug 2025 02:24:53 +0000</pubDate>
      <link>https://forem.com/aws-builders/configuring-hybrid-authentication-certificates-users-in-aws-client-vpn-3lc7</link>
      <guid>https://forem.com/aws-builders/configuring-hybrid-authentication-certificates-users-in-aws-client-vpn-3lc7</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this post we are going to look into the point to site VPN configuration using AWS client VPN. The clientVPN enables the endusers connect to securely the AWS hosted network with mutual authentication and user authentication. &lt;/p&gt;

&lt;p&gt;Before diving into the configuration steps. Let us discuss the typical network architecture. As illustrated in the cover image. The network architecture has one hub/transit account which is a demilitarized zone (DMZ) for accessing the spoke accounts. Typically hub/transit is uses the inspect services like firewall for any incoming traffic from internet. In our scenario, we are hosting the AWS client VPN. It uses the AWS certificate manager for mutual authentication and managed active directory for user authentication. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1) Generate server and client certificates for mutual authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the hub/transit account. Run the following commands to configure client VPN.&lt;/p&gt;

&lt;p&gt;Run the below command to clone the openVPN easy-rsa repo on your laptop/local machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/OpenVPN/easy-rsa.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2F7hwxp28vpz5w3qu41gzo.jpeg" 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%2F7hwxp28vpz5w3qu41gzo.jpeg" alt=" " width="600" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run the below command to switch to the easyrsa3 directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd easy-rsa/easyrsa3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize the new PKI environment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./easyrsa init-pki
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fjkbg9ry5jlhq1b8z9zcw.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%2Fjkbg9ry5jlhq1b8z9zcw.png" alt=" " width="600" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Build a new certificate authority (CA) by running the below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./easyrsa build-ca nopass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fn2o94xuko3pbzuvhclmt.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%2Fn2o94xuko3pbzuvhclmt.png" alt=" " width="600" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To generate the server certificate and key run the below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./easyrsa --san=DNS:server build-server-full server nopass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fg94vtrzq5kvm5xkaunsv.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%2Fg94vtrzq5kvm5xkaunsv.png" alt=" " width="600" height="593"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Generate the client certificate and key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./easyrsa build-client-full client1.domain.tld nopass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fw3o6axrkwquwt38yb8bg.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%2Fw3o6axrkwquwt38yb8bg.png" alt=" " width="600" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the server certificate, key, chain and client certificate and key to a custom folder “awsclientvpn”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir ~/awsclientvpn/
cp pki/ca.crt ~/awsclientvpn/
cp pki/issued/server.crt ~/awsclientvpn/
cp pki/private/server.key ~/awsclientvpn/
cp pki/issued/client1.domain.tld.crt ~/awsclientvpn
cp pki/private/client1.domain.tld.key ~/awsclientvpn/
cd ~/awsclientvpn/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fnr6p8kwxcyxnhapouojy.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%2Fnr6p8kwxcyxnhapouojy.png" alt=" " width="600" height="124"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Zip the custom  directory and upload the zip file to the cloud shell in the account where client VPN will be configured.In this scenario, upload the zip file to the hub/transit AWS account.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;zip -r awsclientvpn.zip awsclientvpn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fpdakpwy1z7ugirwmqy5b.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%2Fpdakpwy1z7ugirwmqy5b.png" alt=" " width="600" height="130"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Upload the zipfile to the cloudshell in the account where client VPN will be configured, unzip.&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%2Fwyz3myf5jcmz0efkjzq9.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%2Fwyz3myf5jcmz0efkjzq9.png" alt=" " width="600" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run the below command from the directory where files are downloaded and then import the server certificates to AWS certificate manager.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws acm import-certificate --certificate fileb://server.crt --private-key fileb://server.key --certificate-chain fileb://ca.crt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the below command to import the client certificates to AWS certificate manager.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws acm import-certificate --certificate fileb://client1.domain.tld.crt --private-key fileb://client1.domain.tld.key --certificate-chain fileb://ca.crt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the AWS console verify that the certificates are imported.&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%2Flizq15u7zgyru5iah6o4.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%2Flizq15u7zgyru5iah6o4.png" alt=" " width="600" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2) Create the directory service for user authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the spoke/shared services account, create a new managed AD for integrating with client VPN for user authentication.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ds create-microsoft-ad \
    --name &amp;lt;your-domain-name&amp;gt; \
    --short-name &amp;lt;your-netbios-name&amp;gt; \
    --password &amp;lt;your-admin-password&amp;gt; \
    --vpc-settings VpcId=&amp;lt;your-spoke-vpc-id&amp;gt;,SubnetIds=&amp;lt;spoke-subnet-id-1&amp;gt;,&amp;lt;spoke-subnet-id-2&amp;gt; \
    --edition STANDARD \
    --description "My AWS Managed Microsoft AD Standard"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fb6j62ou8sivaif5a77ht.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%2Fb6j62ou8sivaif5a77ht.png" alt=" " width="600" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3) Create client VPN endpoint&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Navigate to the VPC section from AWS console and enter the Name, description and CIDR that will be assigned for the client machines by VPN client.&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%2Ff5av3k7cz11r0r2ge099.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%2Ff5av3k7cz11r0r2ge099.png" alt=" " width="600" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the server certificate ARN. Choose authentication both options  "mutual authentication" and "user-based authentication". Select client certificate ARN. In the user based authentication select Active directory authentication. Then select the directory ID from the dropdown menu.&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%2F2vzq4e8tef3x16fmakkk.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%2F2vzq4e8tef3x16fmakkk.png" alt=" " width="600" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enter the DNS Server details. If you are using route 53 as a DNS. Use VPC+2 IP as the DNS address. If VPC CIDR is 10.10.10.0/24, then the DNS IP address is 10.10.10.2.&lt;/p&gt;

&lt;p&gt;Select the transport protocol as UDP. Select the VPC from the dropdown. Create a dedicated security group and open port 443 to allow access for target IP address.&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%2Fxp6rwmv7duenyv7tq518.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%2Fxp6rwmv7duenyv7tq518.png" alt=" " width="600" height="778"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Associate target VPC to the client VPN.&lt;/p&gt;

&lt;p&gt;Select the VPC to which the client VPN need to be associated. Choose public subnet for users to access VPN over the internet. The VPC endpoint ENI will be created in the subnet selected.&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%2Foar5e81une97g0rrs834.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%2Foar5e81une97g0rrs834.png" alt=" " width="600" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add Authorization Rule. In this demo, I am whitelisting for all users. Use the a separate AD group to allow access only to the specific users.&lt;/p&gt;

&lt;p&gt;Authorization rule is the instructions that will allow users to access VPN from a specific network. In the below screenshot 0.0.0.0/0 was entered to allow all users from internet. Preferably, select a specific access group.&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%2Fdrsy5wtkyvhi6scaplts.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%2Fdrsy5wtkyvhi6scaplts.png" alt=" " width="600" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the client VPN configuration was completed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4) Configure client on local machine&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Download the client configuration file to the local machine/laptop.&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%2Fu0mkh3cd8ydbkgj8hfg9.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%2Fu0mkh3cd8ydbkgj8hfg9.png" alt=" " width="600" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On your laptop, download and install open VPN. &lt;a href="https://openvpn.net/client/" rel="noopener noreferrer"&gt;click here&lt;/a&gt; to download the client.&lt;/p&gt;

&lt;p&gt;open client and upload the profile (*.ovpn file). Make sure to place the client cert, key in the same folder where *.ovpn profile file is located.&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%2Fb7e7s82zo3bu6iof3qgz.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%2Fb7e7s82zo3bu6iof3qgz.png" alt=" " width="300" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the profile was successfully imported, the endpoint details will appear on the openVPN client.&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%2Felhxlq1juzc6tb9uxq7u.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%2Felhxlq1juzc6tb9uxq7u.png" alt=" " width="300" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connect to the client. When prompted enter the password.&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%2Fgf1b7o5ybik9zkhips0n.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%2Fgf1b7o5ybik9zkhips0n.png" alt=" " width="300" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When connected to the VPN, the status on the client will change to connected.&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%2Fvu3ctixqd5tdw1yp0pst.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%2Fvu3ctixqd5tdw1yp0pst.png" alt=" " width="250" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connect EC2 servers in the spoke accounts using their private IP address.&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%2Fr2ui2qtti14468bntic0.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%2Fr2ui2qtti14468bntic0.png" alt=" " width="600" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/client-auth-mutual-enable.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/client-auth-mutual-enable.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>authentication</category>
      <category>vpn</category>
      <category>acm</category>
    </item>
    <item>
      <title>Re-Encrypt Your AWS EBS Volumes with a Shared KMS Key (CMK)</title>
      <dc:creator>Rajesh Gundeti</dc:creator>
      <pubDate>Fri, 28 Mar 2025 01:34:52 +0000</pubDate>
      <link>https://forem.com/rajesh_gundeti/seamlessly-re-encrypt-your-aws-ebs-volumes-with-a-shared-kms-key-cmk-2lhf</link>
      <guid>https://forem.com/rajesh_gundeti/seamlessly-re-encrypt-your-aws-ebs-volumes-with-a-shared-kms-key-cmk-2lhf</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Amazon Elastic Block Store (EBS) allows encryption using AWS-managed or customer-managed keys. However, modifying the encryption key of an existing EBS volume is not straightforward. This blog post walks through a Python script utilizing Boto3 to re-encrypt an EBS volume with a shared AWS Customer Managed key (CMK), ensuring data security compliance. In this scenario the CMK is shared from a different account. We will go through the steps to change the encryption key of the volume from AWS default key to shared CMK.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Required Libraries&lt;/strong&gt;&lt;br&gt;
The script makes use of the boto3 library, which is the official AWS SDK for Python. It allows programmatic access to AWS services, including EC2, which manages EBS volumes.&lt;/p&gt;

&lt;p&gt;To install Boto3, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install boto3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The script uses the following components from boto3:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;boto3.client('ec2'): Creates an EC2 client to interact with AWS EC2 services.&lt;/li&gt;
&lt;li&gt;create_snapshot(): Creates a backup snapshot of an EBS volume.&lt;/li&gt;
&lt;li&gt;get_waiter('snapshot_completed'): Waits until the snapshot is fully created.&lt;/li&gt;
&lt;li&gt;copy_snapshot(): Copies the snapshot with a new encryption key.&lt;/li&gt;
&lt;li&gt;get_waiter('snapshot_completed'): Ensures the copied snapshot is ready.&lt;/li&gt;
&lt;li&gt;create_volume(): Creates a new EBS volume from the copied snapshot.&lt;/li&gt;
&lt;li&gt;get_waiter('volume_available'): Ensures the new volume is available.&lt;/li&gt;
&lt;li&gt;detach_volume(): Detaches the old volume from the EC2 instance.&lt;/li&gt;
&lt;li&gt;attach_volume(): Attaches the new volume to the EC2 instance.&lt;/li&gt;
&lt;li&gt;describe_volumes(): Retrieves details of the newly attached volume.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Understanding the Script&lt;/strong&gt;&lt;br&gt;
The provided Python script automates the process of changing an EBS volume’s encryption key in five key steps:&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Create a Snapshot of the Existing Volume
&lt;/h2&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%2F9d2m8h9pzt4847j74rrs.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%2F9d2m8h9pzt4847j74rrs.png" alt="Create a Snapshot of the Existing Volume" width="800" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The script begins by creating a snapshot of the existing EBS volume, serving as a backup before re-encryption.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;snapshot = ec2.create_snapshot(VolumeId=volume_id, Description="Snapshot before changing encryption key")
snapshot_id = snapshot['SnapshotId']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To ensure data consistency, it waits for the snapshot to complete before proceeding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;waiter = ec2.get_waiter('snapshot_completed')
waiter.wait(SnapshotIds=[snapshot_id])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Copy the Snapshot with the Shared CMK
&lt;/h2&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%2Fhjei8lg3v3qz38lyvh5j.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%2Fhjei8lg3v3qz38lyvh5j.png" alt="Copy the Snapshot with the shared CMK" width="800" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The script then copies the snapshot, applying the new KMS key for encryption.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;copied_snapshot = ec2.copy_snapshot(
    SourceRegion=region,
    SourceSnapshotId=snapshot_id,
    DestinationRegion=region,
    KmsKeyId=kms_key_arn,
    Encrypted=True,
    Description="Snapshot with customer-managed KMS key"
)
copied_snapshot_id = copied_snapshot['SnapshotId']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A wait process ensures the copied snapshot is ready for use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Create a New Volume from the Copied Snapshot
&lt;/h2&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%2Ffp7q3v9om977zkiv22rq.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%2Ffp7q3v9om977zkiv22rq.png" alt="Create a New Volume from the Copied Snapshot" width="800" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The copied snapshot is then used to create a new volume that is encrypted with the new KMS key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;new_volume = ec2.create_volume(
    SnapshotId=copied_snapshot_id,
    AvailabilityZone=availability_zone,
    Encrypted=True,
    KmsKeyId=kms_key_arn
)
new_volume_id = new_volume['VolumeId']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A waiter ensures the new volume is available before proceeding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Replace the Old Volume with the New Volume
&lt;/h2&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%2Fbgb1oc0o3v25f2i4zmie.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%2Fbgb1oc0o3v25f2i4zmie.png" alt="Replace the Old Volume with the New Volume of the EC2" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The script detaches the old volume from the EC2 instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ec2.detach_volume(VolumeId=volume_id)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After confirming the old volume is detached, the new volume is attached in its place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ec2.attach_volume(VolumeId=new_volume_id, InstanceId=instance_id, Device=device_name)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Verify the New Volume
&lt;/h2&gt;

&lt;p&gt;Finally, the script retrieves and prints the details of the newly attached volume to verify the encryption change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;volume_info = ec2.describe_volumes(VolumeIds=[new_volume_id])
print(f"New volume details: {volume_info}")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Script&lt;/strong&gt;&lt;br&gt;
Below is the full python code to change the encryption key of the EBS volume.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import boto3

def convert_ebs_encryption(volume_id, kms_key_arn, region, availability_zone, instance_id, device_name):
    ec2 = boto3.client('ec2', region_name=region)

    # Step 1: Create a snapshot of the existing volume
    snapshot = ec2.create_snapshot(VolumeId=volume_id, Description="Snapshot before changing encryption key")
    snapshot_id = snapshot['SnapshotId']
    print(f"Snapshot created: {snapshot_id}")

    # Wait for the snapshot to complete
    waiter = ec2.get_waiter('snapshot_completed')
    waiter.wait(SnapshotIds=[snapshot_id])

    # Step 2: Copy the snapshot with the new KMS key
    copied_snapshot = ec2.copy_snapshot(
        SourceRegion=region,
        SourceSnapshotId=snapshot_id,
        DestinationRegion=region,
        KmsKeyId=kms_key_arn,
        Encrypted=True,
        Description="Snapshot with customer-managed KMS key"
    )
    copied_snapshot_id = copied_snapshot['SnapshotId']
    print(f"Copied snapshot created: {copied_snapshot_id}")

    # Wait for the copied snapshot to complete
    waiter.wait(
        SnapshotIds=[copied_snapshot_id],
        WaiterConfig={
            'Delay': 60,  # Wait 60 seconds between each attempt
            'MaxAttempts': 60  # Maximum of 60 attempts
        }
    )

    # Step 3: Create a new volume from the copied snapshot
    new_volume = ec2.create_volume(
        SnapshotId=copied_snapshot_id,
        AvailabilityZone=availability_zone,
        Encrypted=True,
        KmsKeyId=kms_key_arn
    )
    new_volume_id = new_volume['VolumeId']
    print(f"New volume created: {new_volume_id}")

    # Wait for the new volume to become available
    waiter = ec2.get_waiter('volume_available')
    waiter.wait(VolumeIds=[new_volume_id])
    print(f"New Volume is available")

    ## Step 4: Detach the old volume and attach the new volume
    #ec2.detach_volume(VolumeId=volume_id)
    #ec2.attach_volume(VolumeId=new_volume_id, InstanceId=instance_id, Device=device_name)
    #print(f"New volume {new_volume_id} attached to instance {instance_id} as {device_name}")

    # Step 4: Detach the old volume
    ec2.detach_volume(VolumeId=volume_id)

    # Wait for the old volume to be fully detached
    detach_waiter = ec2.get_waiter('volume_available')
    detach_waiter.wait(VolumeIds=[volume_id])
    print(f"Old volume {volume_id} detached successfully")

    # Attach the new volume
    ec2.attach_volume(VolumeId=new_volume_id, InstanceId=instance_id, Device=device_name)
    print(f"New volume {new_volume_id} attached to instance {instance_id} as {device_name}")

    # Step 5: Verify the new volume
    volume_info = ec2.describe_volumes(VolumeIds=[new_volume_id])
    print(f"New volume details: {volume_info}")

# Example usage
#convert_ebs_encryption('&amp;lt;EBS_VOLUME_ID&amp;gt;', '&amp;lt;CUSTOMER_KMS_KEY_ID&amp;gt;', '&amp;lt;REGION&amp;gt;', '&amp;lt;AVAILABILITY_ZONE&amp;gt;', '&amp;lt;INSTANCE_ID&amp;gt;', '&amp;lt;DEVICE_NAME&amp;gt;')

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
This automated approach enables AWS users to change the encryption key of an EBS volume without downtime for all non root volumes. It ensures compliance with security policies while maintaining data integrity. By leveraging Boto3 and AWS KMS, organizations can efficiently manage encrypted EBS volumes at scale.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>aws</category>
      <category>python</category>
      <category>ebs</category>
    </item>
    <item>
      <title>#security</title>
      <dc:creator>Rajesh Gundeti</dc:creator>
      <pubDate>Thu, 13 Mar 2025 21:55:38 +0000</pubDate>
      <link>https://forem.com/rajesh_gundeti/security-30a</link>
      <guid>https://forem.com/rajesh_gundeti/security-30a</guid>
      <description></description>
      <category>security</category>
    </item>
  </channel>
</rss>
