Mastering AWS CLI for Load Balancer Management
A few keystrokes are all it takes to stand up or tear down the traffic spine of your cloud. With the AWS Command Line Interface, you control every aspect of an Elastic Load Balancer: creation, deletion, health checks, listener rules, security groups, target groups, scaling. No clicking through tabs. No guessing at hidden defaults. Just precise commands that either power your service or take it offline.
First, know what you’re building. The aws elb
and aws elbv2
commands are your entry points. Classic Load Balancers (ELB) and Application or Network Load Balancers (ALB/NLB) use different command sets. Pick the right one before you script.
To create an Application Load Balancer:
aws elbv2 create-load-balancer \
--name my-alb \
--subnets subnet-abc123 subnet-def456 \
--security-groups sg-123456
This instantly provisions the load balancer across your specified subnets with the attached security group.
Next, you’ll create a target group:
aws elbv2 create-target-group \
--name my-targets \
--protocol HTTP \
--port 80 \
--vpc-id vpc-abc123
Then register your targets:
aws elbv2 register-targets \
--target-group-arn arn:aws:elasticloadbalancing:region:account:targetgroup/my-targets/123abc \
--targets Id=i-12345 Id=i-67890
Attach the target group to a listener:
aws elbv2 create-listener \
--load-balancer-arn arn:aws:elasticloadbalancing:region:account:loadbalancer/app/my-alb/abc123 \
--protocol HTTP \
--port 80 \
--default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:region:account:targetgroup/my-targets/123abc
Health checks are not optional. Set them with modify-target-group
to fine-tune thresholds, intervals, and paths. Test failover scenarios. Script repeatable deployments. Use tags for cost tracking and quick teardown in staging environments.
Security is baked in through security groups and certificate management. For HTTPS, combine create-listener
with an ACM certificate ARN. Tighten listener rules to exact paths and hosts.
When you’re done, your AWS CLI playbook should turn load balancer operations into muscle memory. No surprises. No delays.
If you want to see the power of infrastructure made simple, without losing the speed and control the CLI gives you, try hoop.dev. Spin it up, ship a live system in minutes, and watch your load balancer serve real traffic, fast.