Giter Club home page Giter Club logo

hostname-as-target-for-elastic-load-balancer's Introduction

Elastic Load Balancer: Using hostname as a target

For more information, refer to blog: Hostname-as-Target for Newtork Load Balancers

Elastic Load Balancing automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers, IP addresses, and Lambda functions. It can handle the varying load of your application traffic in a single Availability Zone or across multiple Availability Zones. Elastic Load Balancing offers three types of load balancers that all feature the high availability, automatic scaling, and robust security necessary to make your applications fault tolerant:

  • Application Load Balancer: Best suited for load balancing of HTTP and HTTPS traffic and provides advanced request routing targeted at the delivery of modern application architectures, including microservices and containers. Operates at Layer 7 of Open System Interconnection (OSI) model.

  • Network Load Balancer: Best suited for load balancing of Transmission Control Protocol (TCP), User Datagram Protocol (UDP) and Transport Layer Security (TLS) traffic where extreme performance is required. Operates at Layer 4 of OSI model.

  • Classic Load Balancer: Provides basic load balancing across multiple Amazon EC2 instances and operates at both the request level and connection level. Classic Load Balancer is intended for applications that were built within the EC2-Classic network. Today applications are architected on EC2-VPC network and use either Application Load Balancer or Network Load Balancer.

Elastic Load Balancer (ELB), as describe above, do no support Fully Qualified Domain Name (FQDN) as targets. This repository describes solution that uses AWS Lambda (Lambda) to add FQDN as target for Elastic Load Balancer.

You create an ELB with target group of type ip. Once ELB is created, you will deploy this Lambda. Lambda periodically resolves the target FQDN and registers/deregisters IP addresses as targets from a target group.

For more information, refer to blog: Hostname-as-Target for Newtork Load Balancers

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

hostname-as-target-for-elastic-load-balancer's People

Contributors

amazon-auto avatar pmankad96 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hostname-as-target-for-elastic-load-balancer's Issues

`describe_target_health` never returns

Hello, I followed the guide at https://aws.amazon.com/blogs/networking-and-content-delivery/hostname-as-target-for-network-load-balancers/ but have not been able to get this working successfully inside a VPC. When the function runs, it always reaches timeout. I've made sure to add an open security group for the lambda, as well as adding the lambda to the vpc and placing it in the same subnets as my vpc private endpoint resource.

Any suggestions on what I am doing wrong? Thanks

ERROR: 'str' object has no attribute 'labels'

Have anyone run into this error...

[ERROR] 2022-09-22T13:53:11.531Z 173750ff-4fb7-4f2e-a757-316995010d32 ERROR: 'str' object has no attribute 'labels'
Traceback (most recent call last):
File "/var/task/elb_hostname_as_target.py", line 123, in lambda_handler
dns_lookup_result = utils.dns_lookup(DNS_SERVER, TARGET_FQDN, "A")
File "/var/task/lambda_utils.py", line 225, in dns_lookup
lookupAnswer = myResolver.query(domainname, record_type)
File "/var/task/dns/resolver.py", line 916, in query
qnames_to_try.append(qname.concatenate(self.domain))
File "/var/task/dns/name.py", line 682, in concatenate
labels.extend(list(other.labels))
AttributeError: 'str' object has no attribute 'labels'
[ERROR] 2022-09-22T13:53:11.532Z 173750ff-4fb7-4f2e-a757-316995010d32 ERROR: Invocation Failed

TypeError: not all arguments converted during string formatting

The lambda includes the following code:

https://github.com/aws-samples/hostname-as-target-for-elastic-load-balancer/blob/main/source/elb_hostname_as_target.py#L191

    except Exception as e:
        logger.error("ERROR:", e)

This causing a python error if triggered

[ERROR] TypeError: not all arguments converted during string formattingTraceback (most recent call last):  File "/var/task/elb_hostname_as_target.py", line 191, in lambda_handler    logger.error("ERROR:", e)  File "/var/lang/lib/python3.7/logging/__init__.py", line 1407, in error    self._log(ERROR, msg, args, **kwargs)  File "/var/lang/lib/python3.7/logging/__init__.py", line 1514, in _log    self.handle(record)  File "/var/lang/lib/python3.7/logging/__init__.py", line 1524, in handle    self.callHandlers(record)  File "/var/lang/lib/python3.7/logging/__init__.py", line 1586, in callHandlers    hdlr.handle(record)  File "/var/lang/lib/python3.7/logging/__init__.py", line 894, in handle    self.emit(record)  File "/var/runtime/bootstrap.py", line 243, in emit    msg = self.format(record)  File "/var/lang/lib/python3.7/logging/__init__.py", line 869, in format    return fmt.format(record)  File "/var/lang/lib/python3.7/logging/__init__.py", line 608, in format    record.message = record.getMessage()  File "/var/lang/lib/python3.7/logging/__init__.py", line 369, in getMessage    msg = msg % self.args

I think you want to use this instead

logger.exception("error")

render_list function does not handle external IPs due to boto3 api error

If you are trying to use the lamda with non-vpc IP address the AWS api/boto3 will fail with the following error

[ERROR]	2022-11-19T18:50:05.007Z	75a3e5b4-4302-4493-9824-539647241114	The Availability Zone is required for IP address '172.25.18.11' because it is not in the VPC

To resolve you need to specify the AZ in the render_list function. This should prob be added as an option param in the formation template

def render_list(ip_list):
    """
    Render a list of targets for registration/deregistration
    """
    target_list = []
    for ip in ip_list:
        target = {
            'Id': ip,
            'AvailabilityZone': 'all'
        }
        target_list.append(target)
    return target_list

Update DNSPython Dependencies

Project currently uses dnspython-1.15.0.dist-info which relies on some soon to be deprecated python cryptography libraries. The project sample should be upgraded to latest DNSpython package 2.10.

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.