Bootstrap FreeKB - Amazon Web Services (AWS) - Create Elastic Load Balancer (ELB) Listener using the AWS CLI
Amazon Web Services (AWS) - Create Elastic Load Balancer (ELB) Listener using the AWS CLI


An Elastic Load Balancer (ELB) is typically used to load balance requests across two (or more) different EC2 instances. 

 

This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.

Before creating the Listner, you will need to:

When creating the Listener, you will need to get the ARN (Amazon Resource Name) of your Elastic Load Balancer. The aws elbv2 describe-load-balancers command can be used.

~]$ aws elbv2 describe-load-balancers | grep LoadBalancerArn
            "LoadBalancerArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/my-application-load-balancer/942a937d17436eab",

 

You will also need the ARN of your Target Group. The aws elbv2 describe-target-groups command can be used.

~]$ aws elbv2 describe-target-groups | grep TargetGroupArn
            "TargetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-target-group/cbcc3e9dace0fa63",

 

The elbv2 create-listener command can then be used to create the Elastic Load Balancer Listener.

~]$ aws elbv2 create-listener --load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:12345679012:loadbalancer/app/my-application-load-balancer/942a937d17436eab \
--protocol HTTP \
--port 80 \
--default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-target-group/cbcc3e9dace0fa63
{
    "Listeners": [
        {
            "ListenerArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:listener/app/my-application-load-balancer/942a937d17436eab/c0a8eebc13f243cc",
            "LoadBalancerArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/my-application-load-balancer/942a937d17436eab",
            "Port": 80,
            "Protocol": "HTTP",
            "DefaultActions": [
                {
                    "Type": "forward",
                    "TargetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-target-group/cbcc3e9dace0fa63",
                    "ForwardConfig": {
                        "TargetGroups": [
                            {
                                "TargetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-target-group/cbcc3e9dace0fa63",
                                "Weight": 1
                            }
                        ],
                        "TargetGroupStickinessConfig": {
                            "Enabled": false
                        }
                    }
                }
            ]
        }
    ]
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter e24891 in the box below so that we can be sure you are a human.