Step-by-Step Guide: Setting up AWS ALB using AWS CLI

Table of Contents

AWS ALB Setup

AWS ALB Setup

Prerequisite

If you don’t have one, create a default vpc

Get the aws cli if you don’t already have it

https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html

Configure your aws cli

https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html

Test to make sure you have version 2 of the aws cli installed

Get the AMI id of the free tier-eligible AMI

List your VPCs

Create an environment variable for your VPC

Use a key pair from your existing key pairs

MyALBKeyPair.pem

Create Resources

Create your security group

Set environment variable for your security group

Get your local IP Address

Set an environment variable for your IP address

Add ssh and HTTP rules to your inbound rules

Create your subnets

Create environment variables for your subnets

Create your EC2 instances using the AMI id of ami-03c7d01cf4dedc891 (the free tier eligible AMI), two in each subnet; one for the video server and the other for the web server.

userdata-video-server-1.txt

userdata-video-server-2.txt

userdata-web-server-1.txt

userdata-web-server-2.txt

!/bin/bash

sudo su
yum install httpd -y
echo “

Hello from EC2 web instance #2

This server acts as an Apache nginx server” > /var/www/html/index.html
echo “

Serving web interactions from EC2 web instance #2

Create environment variables for your EC2 instances

Tag your instances with names

Create your Video Load Balancer

Create environment variables for your ALB ARN and DNS name

Create your Target Groups

Create environment variables for your target group ARNs

Register your EC2 instances with your Target Groups

Create a listener for your ALB and give it a default Target Group of the web target group

Create an environment variable for your listener ARN

Verify the health of your targets in each Target Group

Add path-based routing

conditions-pattern.json

Get your listener arns

Create environment variables for your rule ARNs

Test your setup

http://myalb-1394077796.us-east-1.elb.amazonaws.com/vid/

Delete Resources

Delete your listener rules

Delete your listener

Delete your Target Groups

Delete your ALB

Terminate your EC2 instances

Delete your subnets

Delete your security group

References

https://serverfault.com/questions/509136/how-do-i-set-a-vpc-in-aws-to-default-vpc-true

Rate this post

Leave a Reply