Set Up Public VPC and EC2 for Internet Access

Tasks

  • Create a public VPC named devops-pub-vpc.

  • Create a subnet named devops-pub-subnet under the VPC.

  • Ensure public IPs are automatically assigned to resources in this subnet.

  • Create an EC2 instance named devops-pub-ec2 under this VPC.

  • Ensure SSH port 22 is open for this instance and accessible over the internet.

    Steps

    1. Create a VPC now.

    2. VPC → Your VPCs → Create VPC

      Enter the following details:

      • Name tag: devops-pub-vpc

      • IPv4 CIDR block: 10.0.0.0/16

      • IPv6 CIDR block: No IPv6 CIDR block.

      • Tenancy: Default

        Click Create VPC*.*

  1. You successfully created vpc-0fe2735e948ae693d / devops-pub-vpc.

  2. Enable Public DNS for the VPC

    • Select the newly created VPC (devops-pub-vpc) in the VPC dashboard.

    • Go to the Actions dropdown and choose Edit DNS hostnames.

    • Enable both DNS resolution and DNS hostnames.

    • Save changes.

      VPC → Your VPCs → vpc-0fe2735e948ae693d → Edit VPC settings

  3. Create the Subnet

    a) In the VPC Dashboard, click Create Subnet.

    b) Enter the following details:

    • VPC: Select devops-pub-vpc.

    • Subnet name: devops-pub-subnet.

    • Availability Zone: Select any (e.g., us-east-1a).

    • IPv4 CIDR block: 10.0.1.0/24.

VPC → Subnets → Create subnet

  1. Enable Auto-assign public IPv4 address.

  2. Create an Internet Gateway

  3. Go to Actions, and choose Attach to VPC.

  4. Select devops-pub-vpc and click Attach internet gateway.

  5. Create and Configure a Route Table

    • In the VPC Dashboard, go to Route Tables.

    • Click Create route table.

    • Enter the following details:

      • Name tag: devops-pub-rt

      • VPC: Select devops-pub-vpc.

    • Click Create route table.

      VPC → Route tables → Create route table

  6. Click Edit routes.

  7. Add the following route:

    • Destination: 0.0.0.0/0

    • Target: Internet Gateway (select devops-igw from the dropdown).

    • Save changes.

  1. Edit subnet associations

    VPC → Route tables → rtb-005a434e2701bf060 → Edit subnet associations

  2. Create a Security Group

    Enter the following details:

    • Security group name: devops-pub-sg

    • Description: Allow SSH access.

    • VPC: Select devops-pub-vpc.

  3. Add an Inbound Rule:

    • Type: SSH

    • Protocol: TCP

    • Port Range: 22

    • Source: 0.0.0.0/0

  1. Launch the EC2 Instance

    • Go to the EC2 Dashboard and click Launch Instances.

    • Enter the following details:

      • Name: devops-pub-ec2.

      • AMI: Any of ami ( I am choosing ubuntu right now)

      • Instance type: t2.micro.

      • Key pair: Select an existing key pair or create a new one.

      • Network settings:

        • VPC: Select devops-pub-vpc.

        • Subnet: Select devops-pub-subnet.

        • Auto-assign public IP: Enabled (should be automatic due to subnet settings).

        • Security group: Select devops-pub-sg.

    • Click Launch Instance.

      Congrats! You have successfully completed the task.