<?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>DEV Community: Ahmet Ozan GAZİ</title>
    <description>The latest articles on DEV Community by Ahmet Ozan GAZİ (@ozy31).</description>
    <link>https://dev.to/ozy31</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%2F1315268%2F67e138c9-df75-4d0f-917d-8a963e6c4bc7.jpeg</url>
      <title>DEV Community: Ahmet Ozan GAZİ</title>
      <link>https://dev.to/ozy31</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ozy31"/>
    <language>en</language>
    <item>
      <title>AWS Site-to-Site VPN Connection and Distrubution over AWS Transit Gateway.</title>
      <dc:creator>Ahmet Ozan GAZİ</dc:creator>
      <pubDate>Tue, 24 Jun 2025 11:40:03 +0000</pubDate>
      <link>https://dev.to/ozy31/aws-site-to-site-vpn-connection-and-distrubution-over-aws-transit-gateway-5465</link>
      <guid>https://dev.to/ozy31/aws-site-to-site-vpn-connection-and-distrubution-over-aws-transit-gateway-5465</guid>
      <description>&lt;h1&gt;
  
  
  AWS Site-to-Site VPN and Transit Gateway Cross-Account Routing
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In enterprise cloud infrastructures, establishing secure and scalable network connections between different AWS accounts and VPCs (Virtual Private Cloud) is of critical importance. AWS provides powerful services such as &lt;strong&gt;Site-to-Site VPN&lt;/strong&gt; and &lt;strong&gt;Transit Gateway&lt;/strong&gt; to meet this need. In this article, we will explain step by step how to route network traffic between multiple AWS accounts using Site-to-Site VPN and Transit Gateway.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Basic Concepts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Site-to-Site VPN
&lt;/h3&gt;

&lt;p&gt;AWS Site-to-Site VPN creates an encrypted tunnel between your on-premises data center and your AWS VPC. This enables secure data transmission between your on-premises network and cloud environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Transit Gateway
&lt;/h3&gt;

&lt;p&gt;AWS Transit Gateway allows you to connect multiple VPCs and on-premises networks through a central hub. This structure simplifies network management and increases scalability.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Scenario and Architecture Definition
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Account A:&lt;/strong&gt; Main AWS account connected to on-premises data center.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Account B and C:&lt;/strong&gt; VPCs located in different AWS accounts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Objective:&lt;/strong&gt; Provide secure and centralized access from on-premises data center to VPCs in Account B and C.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Step-by-Step Setup
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1. Creating Transit Gateway (Account A)
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Sign in to &lt;strong&gt;AWS Management Console&lt;/strong&gt; with Account A.&lt;/li&gt;
&lt;li&gt;Follow the steps: &lt;strong&gt;VPC Dashboard&lt;/strong&gt; &amp;gt; &lt;strong&gt;Transit Gateways&lt;/strong&gt; &amp;gt; &lt;strong&gt;Create Transit Gateway&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Give the Transit Gateway a meaningful name and configure necessary settings.&lt;/li&gt;
&lt;li&gt;Note the Transit Gateway ID.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  3.2. Creating Transit Gateway Attachments
&lt;/h3&gt;

&lt;h4&gt;
  
  
  a) Connecting Account A's VPC to Transit Gateway
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Create a new attachment from the &lt;strong&gt;Transit Gateway Attachments&lt;/strong&gt; section in VPC Dashboard.&lt;/li&gt;
&lt;li&gt;Select the relevant VPC in Account A and connect it to the Transit Gateway.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  b) Creating VPC Attachments in Other Accounts (B and C)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;In Account B and C, enable Transit Gateway sharing through &lt;strong&gt;Resource Access Manager (RAM)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Share the Transit Gateway from Account A.&lt;/li&gt;
&lt;li&gt;In Account B and C, connect their own VPCs to the Transit Gateway using the shared Transit Gateway.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.3. Site-to-Site VPN Setup
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Create &lt;strong&gt;Customer Gateway&lt;/strong&gt; and &lt;strong&gt;Virtual Private Gateway&lt;/strong&gt; in Account A.&lt;/li&gt;
&lt;li&gt;Create &lt;strong&gt;Site-to-Site VPN Connection&lt;/strong&gt; and enter your on-premises network information.&lt;/li&gt;
&lt;li&gt;Connect the VPN connection to the Transit Gateway (create Attachment).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  3.4. Route Table and Routing
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Add routes to each VPC's route table to route traffic to other VPCs and on-premises network through the Transit Gateway.&lt;/li&gt;
&lt;li&gt;Define rules in the Transit Gateway Route Table to route incoming traffic to the correct VPC or VPN.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.5. Security Groups and NACLs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Configure security groups and network access control lists (NACL) to allow relevant ports and protocols.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. Testing and Validation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Test the connection by pinging or SSH connecting to resources (e.g., EC2) in Account B and C from the on-premises network.&lt;/li&gt;
&lt;li&gt;Monitor traffic using AWS VPC Flow Logs and CloudWatch.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Best Practices
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Segment Transit Gateway Route Tables to ensure network isolation.&lt;/li&gt;
&lt;li&gt;Securely manage resource sharing with IAM and RAM.&lt;/li&gt;
&lt;li&gt;Use two tunnels for high availability in VPN connections.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;With AWS Site-to-Site VPN and Transit Gateway, you can establish a centralized, secure, and scalable network architecture between different AWS accounts and on-premises networks. This structure greatly simplifies network management in large-scale and multi-account architectures.&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%2F6w5p2caq7nzi84f7fmsy.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%2F6w5p2caq7nzi84f7fmsy.png" alt="Image description" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;






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


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

&lt;/div&gt;

</description>
    </item>
    <item>
      <title>MFA AWS VIA TERMINAL</title>
      <dc:creator>Ahmet Ozan GAZİ</dc:creator>
      <pubDate>Mon, 20 May 2024 10:48:12 +0000</pubDate>
      <link>https://dev.to/ozy31/mfa-aws-via-terminal-406h</link>
      <guid>https://dev.to/ozy31/mfa-aws-via-terminal-406h</guid>
      <description>&lt;p&gt;In today's digital landscape, securing access to cloud services is paramount, particularly as cyber threats become increasingly sophisticated. Amazon Web Services (AWS), a leading cloud service provider, offers robust security features to protect sensitive data and infrastructure. One essential security measure is Multi-Factor Authentication (MFA), which enhances the traditional username and password login process by requiring an additional verification step. This essay will explore the process of configuring and using MFA to access AWS from a local terminal, highlighting the steps involved, the benefits of this security approach, and practical tips for seamless integration. By implementing MFA, users can significantly bolster their security posture, ensuring that access to their AWS environments is both secure and efficient.&lt;br&gt;
 In this article I want draw your attention to some point which we can make it happen with ease. First of all we need to do some configuration like installing necessary packages such as &lt;code&gt;os, subprocess, pyotp, json, base64, binascli, configparser, dotenv&lt;/code&gt;. These packages are prerequisites for making the scripts work . &lt;br&gt;
As a next step we need to define the environment variables which we'll us it in our &lt;code&gt;bash&lt;/code&gt; scripts. To do seo we create a .env file to keep all of our environmental variables to call them in the cli commands.&lt;br&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%2Fisjpvcuzixpikj3vh2th.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%2Fisjpvcuzixpikj3vh2th.png" alt="Image description" width="800" height="170"&gt;&lt;/a&gt;&lt;br&gt;
When configuring Multi-Factor Authentication (MFA) to securely access Amazon Web Services (AWS) from a local terminal, one of the crucial steps involves creating a .env file. This file, short for "environment variables," is essential for securely storing and managing sensitive information, such as AWS access keys, secret keys, and MFA device serial numbers. By using a .env file, users can avoid hard-coding these credentials directly into their scripts or applications, which enhances security and simplifies configuration management. The .env file should be placed in the root directory of the project and structured in a way that each variable is declared on a new line.&lt;br&gt;
 When it comes to creating a script for all of these configuration, naturally we need to acquire a snappy script which includes as follows,&lt;br&gt;
1- Imports and Environment Setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Imports the necessary modules.&lt;/li&gt;
&lt;li&gt;Loads environment variables from the .env file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2- Configuration Reading:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reads AWS credentials from the specified source profile in the AWS credentials file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3-Validation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verifies that the TOTP secret is valid and base32 encoded.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;4- MFA Token Generation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generates a current MFA token using the TOTP secret.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;5- Session Token Retrieval:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses AWS STS to obtain a session token with the MFA token.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;6- Credentials Update:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Updates the AWS credentials file with the temporary session credentials.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Additionally, ensure the ~/.aws/profile under the $HOME directory is correctly configured for your AWS CLI.&lt;/p&gt;

&lt;p&gt;Here is the one example for script that we may use;&lt;br&gt;
&lt;code&gt;aws-login.py&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
import subprocess
import pyotp
import json
import base64
import binascii
import configparser
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

# Retrieve variables from the environment
mfa_serial_number = os.getenv('MFA_SERIAL_NUMBER')
totp_secret = os.getenv('TOTP_SECRET')
source_profile = os.getenv('SOURCE_PROFILE', 'dev-mfa')
aws_profile = os.getenv('AWS_PROFILE', 'default')

# Read credentials from the source profile
config = configparser.ConfigParser()
credentials_file_path = os.path.expanduser('~/.aws/credentials')
config.read(credentials_file_path)

if source_profile not in config:
    print(f"Profile '{source_profile}' not found in {credentials_file_path}.")
    exit(1)

aws_access_key_id = config[source_profile].get('aws_access_key_id')
aws_secret_access_key = config[source_profile].get('aws_secret_access_key')

if not aws_access_key_id or not aws_secret_access_key:
    print(f"Missing credentials in profile '{source_profile}'.")
    exit(1)

# Ensure TOTP secret is base32 encoded
try:
    base64.b32decode(totp_secret, casefold=True)
except binascii.Error:
    print("The provided TOTP secret is not valid base32 encoded. Please check the secret.")
    exit(1)

# Generate MFA token
totp = pyotp.TOTP(totp_secret)
mfa_token = totp.now()

# Get temporary session token using MFA
try:
    response = subprocess.check_output([
        'aws', 'sts', 'get-session-token',
        '--serial-number', mfa_serial_number,
        '--token-code', mfa_token,
        '--output', 'json',
        '--profile', source_profile
    ])
except subprocess.CalledProcessError as e:
    print(f"Error getting session token: {e}")
    exit(1)

# Parse the response
response_json = json.loads(response)
credentials = response_json['Credentials']

# Update the AWS credentials file with the temporary credentials
if aws_profile not in config.sections():
    config.add_section(aws_profile)

config[aws_profile]['aws_access_key_id'] = credentials['AccessKeyId']
config[aws_profile]['aws_secret_access_key'] = credentials['SecretAccessKey']
config[aws_profile]['aws_session_token'] = credentials['SessionToken']

with open(credentials_file_path, 'w') as configfile:
    config.write(configfile)

print(f"🙌🏻 Welcome to Starlet Technologies AWS Cloud Services. All logins and acitivities are monitoring and recording.")
print("⏰ Your AWS CLi session will expire at:", credentials['Expiration'])

## Verify the identity of the temporary credentials
#try:
#    identity = subprocess.check_output(['aws', 'sts', 'get-caller-identity', '--profile', aws_profile])
#    print("Current Identity:", identity.decode('utf-8'))
#except subprocess.CalledProcessError as e:
#    print(f"Error verifying identity: {e}")
#    exit(1)
#
## Attempt to list S3 buckets
#try:
#    s3_buckets = subprocess.check_output(['aws', 's3', 'ls', '--profile', aws_profile])
#    print("S3 Buckets:", s3_buckets.decode('utf-8'))
#except subprocess.CalledProcessError as e:
#    print(f"Error listing S3 buckets: {e}")
#    exit(1)

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

&lt;/div&gt;



&lt;p&gt;In order to make above script run, we use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python aws-login.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a expected output we can see ;&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%2Fho39y4r7hzbiuizhx1r4.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%2Fho39y4r7hzbiuizhx1r4.png" alt="Image description" width="800" height="62"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the troubleshooting purposes we recommend you to check if you have registered profile under &lt;code&gt;~/.aws/credentials&lt;/code&gt; file.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
