question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ELBv2: Can't create listener

See original GitHub issue

Part of my code:

@mock_ec2
@mock_elbv2
class TestElasticLoadBalancingV2(unittest.TestCase):

    def setUp(self):
        self.tags = [
            {
                'Key': 'test_key',
                'Value': 'test_value'
            }
        ]
        self.region = 'us-east-1'
        self.credentials = {
            "aws_access_key_id": "",
            "aws_secret_access_key": ""
        }

        self.client = boto3.client(
            'elbv2',
            self.region,
            **self.credentials
        )


    def create_resources(self):
        self.elb_name = 'test_elb'
        subnets_ids = self.subnets_ids()
        lb_arn = self.create_load_balancer(self.elb_name, subnets_ids)
        tg_arn = self.create_target_group()
        self.create_listener(lb_arn, tg_arn)

    def create_load_balancer(self, elb_name, subnets):
        response = self.client.create_load_balancer(
            Name=elb_name,
            Tags=self.tags,
            Subnets=subnets
        )
        return response['LoadBalancers'][0]['LoadBalancerArn']

    def create_target_group(self):
        response = self.client.create_target_group(
            Name='test-target-group',
            Protocol='HTTPS',
            Tags=self.tags,
            Port = 6081,
            TargetType='instance'
        )
        return response['TargetGroups'][0]['TargetGroupArn']

    def create_listener(self, lb_arn, tg_arn):
        self.client.create_listener(
            LoadBalancerArn=lb_arn,
            DefaultActions=[
                {
                    'Type': 'fixed-response',
                    'FixedResponseConfig': {
                        'StatusCode': '200',
                        'ContentType': 'application/json'
                    }
                }
            ],
            Tags=self.tags
        )

    def subnets_ids(self):
        ec2_client = boto3.client(
            'ec2',
            self.region,
            **self.credentials
        )
        response = ec2_client.describe_subnets()
        subnets_ids = [subnet['SubnetId'] for subnet in response['Subnets']]
        return subnets_ids


    def test_elbv2(self):
        self.create_resources()

Traceback:

 File "/home/geek/try_moto/tests.py", line 646, in create_listener
    self.client.create_listener(
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/client.py", line 386, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/client.py", line 691, in _make_api_call
    http, parsed_response = self._make_request(
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/client.py", line 711, in _make_request
    return self._endpoint.make_request(operation_model, request_dict)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/endpoint.py", line 102, in make_request
    return self._send_request(request_dict, operation_model)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/endpoint.py", line 134, in _send_request
    success_response, exception = self._get_response(
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/endpoint.py", line 166, in _get_response
    success_response, exception = self._do_get_response(
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/endpoint.py", line 217, in _do_get_response
    parsed_response = parser.parse(
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 245, in parse
    parsed = self._do_parse(response, shape)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 523, in _do_parse
    return self._parse_body_as_xml(response, shape, inject_metadata=True)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 535, in _parse_body_as_xml
    parsed = self._parse_shape(shape, start)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 312, in _parse_shape
    return handler(shape, node)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 388, in _handle_structure
    parsed[member_name] = self._parse_shape(
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 312, in _parse_shape
    return handler(shape, node)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 370, in _handle_list
    return super(BaseXMLResponseParser, self)._handle_list(shape, node)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 320, in _handle_list
    parsed.append(self._parse_shape(member_shape, item))
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 312, in _parse_shape
    return handler(shape, node)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 388, in _handle_structure
    parsed[member_name] = self._parse_shape(
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 312, in _parse_shape
    return handler(shape, node)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 174, in _get_text_content
    return func(self, shape, text)
  File "/home/geek/.local/share/virtualenvs/aws_automation-MKiSmjjO/lib/python3.8/site-packages/botocore/parsers.py", line 486, in _handle_integer
    return int(text)
ValueError: invalid literal for int() with base 10: 'None'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rajendersainicommented, Oct 5, 2021

@bblommers yes that fixes the test. I will put up a Pull Request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

create-listener — AWS CLI 1.27.32 Command Reference
Creates a listener for the specified Application Load Balancer, Network Load Balancer, or Gateway Load Balancer. For more information, see the following:.
Read more >
create-listener — AWS CLI 2.0.34 Command Reference
The following create-listener example creates an HTTP listener for the specified Application Load Balancer that forwards requests to the specified target group.
Read more >
Cannot create ELBV2 listener default rule with ForwardConfig
I'm trying to create an application load balancer with a single listener. That lister should have a default rule with weighted target groups....
Read more >
ELBv2 ALB Listener Security - Trend Micro
Ensure ELBv2 ALBs are using a secure protocol. ... To add an HTTPS listener to your Application Load Balancer, perform the following operations: ......
Read more >
ELBv2 ALB is using a secure listener - Datadog Docs
aws elbv2 create-listener --load-balancer-arn arn:aws:elasticloadbalancing:region:123456789012:loadbalancer/app/my-load-balancer/12ab3c456d7e8912 --protocol ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found