Giter Club home page Giter Club logo

aws_lab_3-4's Introduction

AWS_LAB_3-4

Create a VPC with an App. LoadBalancer connected to 2 Public EC2 in a diff AZs with Nginx Configured as a proxy to pass traffic to an internal facing Network LB connected to 2 Private EC2s with a web app on them.

4 EC2s

Screenshot from 2023-01-07 12-12-13

ALB and NLB

Screenshot from 2023-01-07 12-12-42

Screenshot from 2023-01-07 12-12-55

Screenshot from 2023-01-07 12-13-12

Health Status of Target Groups

Screenshot from 2023-01-07 12-13-24 Screenshot from 2023-01-07 12-13-35

Subnets

Screenshot from 2023-01-07 12-15-11 Screenshot from 2023-01-07 12-15-19

Screenshot from 2023-01-07 12-15-25

NAT gateway to connect the private subnets to the internet

Screenshot from 2023-01-07 12-15-36

EC2s acting as reverse proxies

Screenshot from 2023-01-05 15-30-56 Screenshot from 2023-01-05 15-42-47

User data of Private EC2s

Screenshot from 2023-01-07 12-49-33

Output

Screenshot from 2023-01-07 12-11-35

LAB 4

Use the Previous Infrastructure and add Auto Scaling Group to the Private subnets that hosts the app

ASG Policy

Screenshot from 2023-01-07 12-50-59

Screenshot from 2023-01-07 12-51-53

Screenshot from 2023-01-07 12-53-46

Health Status

Screenshot from 2023-01-07 12-59-46

(Bonus) terraform file to create a vpc and subnets

# Create VPC
resource "aws_vpc" "example" {
  cidr_block       = "10.0.0.0/16"
  enable_dns_hostnames = true

  tags = {
    Name = "example-vpc"
  }
}

# Create public subnets
resource "aws_subnet" "public" {
  count             = 2
  vpc_id            = aws_vpc.example.id
  cidr_block        = "10.0.${count.index}.0/24"
  availability_zone = "us-west-2a"
  map_public_ip_on_launch = true

  tags = {
    Name = "example-public-${count.index+1}"
  }
}

# Create private subnets
resource "aws_subnet" "private" {
  count             = 2
  vpc_id            = aws_vpc.example.id
  cidr_block        = "10.0.${count.index+2}.0/24"
  availability_zone = "us-west-2a"
  map_public_ip_on_launch = false

  tags = {
    Name = "example-private-${count.index+1}"
  }
}

# Create security group for public subnets
resource "aws_security_group" "public" {
  name        = "public"
  description = "Allow HTTP and HTTPS traffic"
  vpc_id      = aws_vpc.example.id

  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

# Create security group for private subnets
resource "aws_security_group" "private" {
  name        = "private"
  description = "Allow all traffic"
  vpc_id      = aws_vpc.example.id

  ingress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

# Create Application Load Balancer
resource "aws_alb" "example" {
  name            = "example-alb"
  internal        = false
  security_groups = [aws_security_group.alb.id]
  subnets         = [aws_subnet.public.id]

  tags = {
    Name = "example-alb"
  }
}

# Create target group
resource "aws_alb_target_group" "example" {
  name     = "example-target-group"
  port     = 80
  protocol = "HTTP"
  vpc_id   = aws_vpc.example.id
}
resource "aws_alb_target_group_attachment" "example" {
  target_group_arn = aws_alb_target_group.example.arn
  target_id        = aws_instance.example.id
  port             = 80
}

resource "aws_alb_listener" "example" {
  load_balancer_arn = aws_alb.example.arn
  port              = "80"
  protocol          = "HTTP"

  default_action {
    type             = "forward"
    target_group_arn = aws_alb_target_group.example.arn
  }
}

aws_lab_3-4's People

Contributors

alii2121 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.