You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Re-use AWS Security Group created for Load Balancers
Step-02: Create ALB Basic Manually
Step-02-01: Create EC2 Instance with Userdata
Go to AWS Services -> EC2 -> Instances -> Launch Instances
Step 1: Choose an Amazon Machine Image (AMI): Amazon Linux 2 AMI (HVM), SSD Volume Type
Step 2: Choose an Instance Type: t2.micro
Step 3: Configure Instance Details:
Number of Instances: 2
Userdata: select file and reference terraform-manifests/app1-install.sh for userdata
Rest all defaults
Step 4: Add Storage: leave to defaults
Step 5: Add Tags:
Key: Name
Value: ALB-Manual-Test-1
Step 6: Configure Security Group:
Security Group Name: ALB-Manual-TestSG1
Add SSH and HTTP rules for entire internet edge 0.0.0.0/0
Step 7: Review Instance Launch: Click on Launch
Select an existing key pair or create a new key pair: terraform-key
Click on Launch Instance
Verify once the EC2 Instance is created and wait for Instances to be in 2/2 checks passed
Access Instances and verify
# Access App1 from both Instances
http://<public-ip-instance-1>/app1/index.html
http://<public-ip-instance-1>/app1/metadata.html
http://<public-ip-instance-2>/app1/index.html
http://<public-ip-instance-2>/app1/metadata.html
Step-02-02: Create Target Group
Go to AWS Services -> EC2 -> Target Groups -> Create target group
Choose a target type: Instances
Target Group Name: app1-tg
Protocol: HTTP
Port: 80
VPC: default-vpc
Protocol Version: HTTP1
Health Check Protocol: HTTP
Health check path: /app1/index.html
Advanced Health Check Settings - Port: Traffic Port
Healthy threshold: 5
Unhealthy threshold: 2
Timeout: 5 seconds
Interval: 30 seconds
Success codes: 200-399
Tags: App = app1-tg
Click Next
Register targets
Select EC2 Instances: select EC2 Instances
Ports for the selected instances: 80
Click on Include as pending below
Click on Create target group
Step-02-03: Create Application Load Balancer
Go to AWS Services -> EC2 -> Load Balancing -> Load Balancers -> Create Load Balancer
# Terraform AWS Application Load Balancer (ALB) Outputs################################################################################# Load Balancer################################################################################
output "id" {
description = "The ID and ARN of the load balancer we created"
value = module.alb.id
}
output "arn" {
description = "The ID and ARN of the load balancer we created"
value = module.alb.arn
}
output "arn_suffix" {
description = "ARN suffix of our load balancer - can be used with CloudWatch"
value = module.alb.arn_suffix
}
output "dns_name" {
description = "The DNS name of the load balancer"
value = module.alb.dns_name
}
output "zone_id" {
description = "The zone_id of the load balancer to assist with creating DNS records"
value = module.alb.zone_id
}
################################################################################# Listener(s)################################################################################
output "listeners" {
description = "Map of listeners created and their attributes"
value = module.alb.listeners
sensitive = true
}
output "listener_rules" {
description = "Map of listeners rules created and their attributes"
value = module.alb.listener_rules
sensitive = true
}
################################################################################# Target Group(s)################################################################################
output "target_groups" {
description = "Map of target groups created and their attributes"
value = module.alb.target_groups
}
Step-06: Execute Terraform Commands
# Terraform Initialize
terraform init
# Terraform Validate
terraform validate
# Terraform Plan
terraform plan
# Terraform Apply
terraform apply -auto-approve
# Verify
Observation:
1. Verify EC2 Instances
2. Verify Load Balancer SG
3. Verify ALB Listeners and Rules
4. Verify ALB Target Groups, Targets (should be healthy) and Health Check settings
5. Access sample app using Load Balancer DNS Name
# Example: from my environment
http://hr-stag-alb-1575108738.us-east-1.elb.amazonaws.com
http://hr-stag-alb-1575108738.us-east-1.elb.amazonaws.com/app1/index.html
http://hr-stag-alb-1575108738.us-east-1.elb.amazonaws.com/app1/metadata.html