AWS VPC to ECS – Day 1: Apna VPC Banaate Hain! 😎
Utkarsh Rastogi

Utkarsh Rastogi @awslearnerdaily

About: Cloud Specialist | AWS Community Builder | I write about AI, serverless, DevOps & real-world cloud projects using AWS, Bedrock, LangChain & more to help others learn and build smarter solutions.

Location:
India
Joined:
Mar 22, 2025

AWS VPC to ECS – Day 1: Apna VPC Banaate Hain! 😎

Publish Date: Aug 9
8 2

Namaste doston! 🙏

Aaj se hum ek CloudFormation Blog Series shuru kar rahe hain – jisme hum VPC se ECS service tak ka safar step-by-step cover karenge.

Socho jaise hum apna gali (VPC), ghar (Subnet), aur road (Route Table) bana rahe hain – taaki baad me apni gaadi (ECS) waha chal sake. 🚗


🎯 Day 1 ka Goal

  • Apna VPC create karna
  • Usme Public aur Private Subnets banana
  • Basic networking ka base ready karna

🧠 Thoda Theory – VPC Kya Hai?

VPC ka matlab hai Virtual Private Cloud.

Yeh AWS ka ek private area hai jaha aap apne resources (servers, databases, containers) ko rakho, aur networking rules set karo.

Think of it like – "Apni private society jaha kaun aayega, kaun jayega, sab aap decide karoge." 🏡


🗺 Architecture Samajh Lo Pehle

Day 1 ke baad humare paas yeh hoga:

VPC
├── Public Subnet (Internet se connected)
└── Private Subnet (Sirf internal access)

1️⃣ VPC Banana – vpc.yaml

AWSTemplateFormatVersion: "2010-09-09"
Description: "Creating VPC for Learning Purpose"

Parameters:
  CidrBlockValue:
    Type: String
    Description: The IPv4 network range for the VPC, in CIDR notation
    Default: "10.0.0.0/18"
  EnableDnsSupportValue:
    Type: String
    Description: Indicates whether the instances launched in the VPC get DNS hostnames. If enabled, instances in the VPC get DNS hostnames; otherwise, they do not. Disabled by default for nondefault VPCs.
    Default: "true"
  EnableDnsHostnamesValue:
    Type: String
    Description: Indicates whether the DNS resolution is supported for the VPC
    Default: "true"
  NameValue:
    Type: String
    Description: Name Tag Value
    Default: "awslearnervpc"
  TeamNameValue:
    Type: String
    Description: TeamName Tag Value
    Default: "awslearner"
  EnvironmentValue:
    Type: String
    Description: Environment Tag Value
    Default: "dev"
  SSMName:
    Type: String
    Description:  VPC ID
    Default: "/learner/vpcid"


Resources:
  LearnerVPC:
    Type: 'AWS::EC2::VPC'
    Properties:
      CidrBlock: !Ref CidrBlockValue
      EnableDnsSupport: !Ref EnableDnsSupportValue
      EnableDnsHostnames: !Ref EnableDnsHostnamesValue
      Tags:
        - Key: Name
          Value: !Ref NameValue
        - Key: TeamName
          Value: !Ref TeamNameValue
        - Key: Environment
          Value: !Ref EnvironmentValue


  SSMParameter:
    Type: "AWS::SSM::Parameter"
    DependsOn: LearnerVPC
    Properties:
      Name: !Ref SSMName
      Type: "String"
      Value: !Ref LearnerVPC 
      Description: "VPC"
      Tags:
        Name: !Ref SSMName
        TeamName: !Ref TeamNameValue
        Environment: !Ref EnvironmentValue

Outputs:
  VPCId:
    Description: The ID of the VPC
    Value: !Ref LearnerVPC
Enter fullscreen mode Exit fullscreen mode

🚀 Deployment

aws cloudformation deploy \
  --template-file vpc.yaml \
  --stack-name AWSLearner-VPC-Stack \
  --capabilities CAPABILITY_NAMED_IAM
Enter fullscreen mode Exit fullscreen mode

2️⃣ Public Subnet Banana – public_subnet.yaml

AWSTemplateFormatVersion: "2010-09-09"
Description: "Creating Public Subnet for Learning Purpose"

Parameters:
  VPC:
    Type: AWS::SSM::Parameter::Value<String>
    Description: VPC ID
    Default: "/learner/vpcid"
  TeamNameValue:
    Type: String
    Description: TeamName Tag Value
    Default: "awslearner"
  EnvironmentValue:
    Type: String
    Description: Environment Tag Value
    Default: "dev"
  PublicSubnet1CIDR:
    Type: String
    Description: PublicSubnet1A IP Range
    Default: "10.0.0.0/24"
  PublicSubnet2CIDR:
    Type: String
    Description: PublicSubnet1B IP Range
    Default: "10.0.1.0/24"
  SSMName:
    Type: String
    Description:  VPC ID
    Default: "/learner/public/subnetids"


Resources:
  PublicSubnet1:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: !Select [ 0, !GetAZs '' ]
      CidrBlock: !Ref PublicSubnet1CIDR
      MapPublicIpOnLaunch: true
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentValue}PublicSubnet(AZ1)
        - Key: TeamName
          Value: !Ref TeamNameValue
        - Key: Environment
          Value: !Ref EnvironmentValue

  PublicSubnet2:
    Type: AWS::EC2::Subnet
    DependsOn: PublicSubnet1
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: !Select [ 1, !GetAZs '' ]
      CidrBlock: !Ref PublicSubnet2CIDR
      MapPublicIpOnLaunch: true
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentValue}PublicSubnet(AZ2)
        - Key: TeamName
          Value: !Ref TeamNameValue
        - Key: Environment
          Value: !Ref EnvironmentValue

  SSMParameter:
    Type: "AWS::SSM::Parameter"
    DependsOn: PublicSubnet2
    Properties:
      Name: !Ref SSMName
      Type: "StringList"
      Value: !Join [ ",", [ !Ref PublicSubnet1, !Ref PublicSubnet2 ]]
      Description: "VPC"
      Tags:
        Name: !Ref SSMName
        TeamName: !Ref TeamNameValue
        Environment: !Ref EnvironmentValue

Outputs:
  PublicSubnets:
    Description: A list of the public subnets
    Value: !Join [ ",", [ !Ref PublicSubnet1, !Ref PublicSubnet2 ]]
Enter fullscreen mode Exit fullscreen mode

🚀 Deployment

aws cloudformation deploy \
  --template-file public_subnet.yaml \
  --stack-name AWSLearner-PublicSubnet-Stack \
  --capabilities CAPABILITY_NAMED_IAM
Enter fullscreen mode Exit fullscreen mode

3️⃣ Private Subnet Banana – private_subnet.yaml

AWSTemplateFormatVersion: "2010-09-09"
Description: "Creating Private Subnet for Learning Purpose"
Parameters:
  VPC:
    Type: AWS::SSM::Parameter::Value<String>
    Description: VPC ID
    Default: "/learner/vpcid"
  TeamNameValue:
    Type: String
    Description: TeamName Tag Value
    Default: "awslearner"
  EnvironmentValue:
    Type: String
    Description: Environment Tag Value
    Default: "dev"
  PrivateSubnet1CIDR:
    Type: String
    Description: PublicSubnet1A IP Range
    Default: "10.0.20.0/20"
  PrivateSubnet2CIDR:
    Type: String
    Description: PublicSubnet1B IP Range
    Default: "10.0.32.0/20"
  SSMName:
    Type: String
    Description:  VPC ID
    Default: "/learner/private/subnetids"


Resources:
  PrivateSubnet1:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: !Select [ 0, !GetAZs '' ]
      CidrBlock: !Ref PrivateSubnet1CIDR
      MapPublicIpOnLaunch: false
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentValue}PrivateSubnet(AZ1)
        - Key: TeamName
          Value: !Ref TeamNameValue
        - Key: Environment
          Value: !Ref EnvironmentValue

  PrivateSubnet2:
    Type: AWS::EC2::Subnet
    DependsOn: PrivateSubnet1
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: !Select [ 1, !GetAZs '' ]
      CidrBlock: !Ref PrivateSubnet2CIDR
      MapPublicIpOnLaunch: false
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentValue}PrivateSubnet(AZ2)
        - Key: TeamName
          Value: !Ref TeamNameValue
        - Key: Environment
          Value: !Ref EnvironmentValue

  SSMParameter:
    Type: "AWS::SSM::Parameter"
    DependsOn: PrivateSubnet2
    Properties:
      Name: !Ref SSMName
      Type: "StringList"
      Value: !Join [ ",", [ !Ref PrivateSubnet1, !Ref PrivateSubnet2 ]]
      Description: "VPC"
      Tags:
        Name: !Ref SSMName
        TeamName: !Ref TeamNameValue
        Environment: !Ref EnvironmentValue

Outputs:
  PrivateSubnets:
    Description: A list of the private subnets
    Value: !Join [ ",", [ !Ref PrivateSubnet1, !Ref PrivateSubnet2 ]]
Enter fullscreen mode Exit fullscreen mode

🚀 Deployment

aws cloudformation deploy \
  --template-file private_subnet.yaml \
  --stack-name AWSLearner-PrivateSubnet-Stack \
  --capabilities CAPABILITY_NAMED_IAM
Enter fullscreen mode Exit fullscreen mode

📝 Recap so far

By now, we have:

1️⃣ VPC – Our gated community 🏡 (everything will live here).
2️⃣ Public Subnet – The gali ka open plot 🏞 (open to the world).
3️⃣ Private Subnet – The secret mango farm 🥭 (safe from the world).

✅ Network foundation is ready! 🎯
We are just warming up — the real ECS magic is coming soon. 🛠


📢 Stay tuned for the next part

💡 Follow this series if you want to learn VPC → ECS setup step-by-step using separate YAML files for each AWS resource.

📬 Make sure to bookmark this blog and share it with your cloud buddies — let’s build this together!


👨‍💻 About Me

Hi! I'm Utkarsh, a Cloud Specialist & AWS Community Builder who loves turning complex AWS topics into fun chai-time stories

👉 Explore more


Comments 2 total

  • Ankur K
    Ankur KAug 9, 2025

    Well written by AI

    • Utkarsh Rastogi
      Utkarsh RastogiAug 9, 2025

      Bro content is made by me only but for some lines ai is used to brush up for icons

Add comment